def post(self): # user = current_identity # print(user.access) # if user.access == "admin": data = Sensor.parser.parse_args() if SensorModel.find_by_name(data["name"]): return { "message": "A sensor with name '{}' already exists.".format(data["name"]) } sensor = SensorModel(data["name"], data["cloud"], data["connection"], data["format"], data["timeInterval"], data["frequency"], data["minRange"], data["maxRange"]) try: sensor.save_to_db() except: return { "message": "An error occurred while adding the sensor, please try again with correct parameters." } return { "message": "Sensor Successfully Created !", "sensor": sensor.json(), "statusCode": 201 }, 201
def post(self, name): sensor = SensorModel.find_by_name(name) if sensor: sensor = sensor.json() connection = sensor['connection'] connectionDict = json.loads(connection) # print(connectionDict) try: if sensor['cloud'] == "thingworx": simulationThingworx(connectionDict, sensor['frequency'], sensor['timeInterval'], sensor['minRange'], sensor['maxRange']) elif sensor['cloud'] == "aws": simulationAWS(connectionDict, name, sensor['frequency'], sensor['timeInterval'], sensor['minRange'], sensor['maxRange']) elif sensor['cloud'] == "azure": simulationAZURE(connectionDict) else: return { "message": "We don't support simulation for this cloud." } return {"message": "Simulation Completed"} except Exception as error: print(error) return { "message": "Something went wrong, Please check the cloud server and try again." } else: return {"message": "Sensor Not Found"}, 404
def delete(self, name): # user = current_identity # print(user.access) # if user.access == "admin": sensor = SensorModel.find_by_name(name) if sensor: sensor.delete_from_db() return {"message": "Sensor deleted"}
def put(self, name): data = UpdateSensorFrequencyInterval.parser.parse_args() sensor = SensorModel.find_by_name(name) if sensor is None: return {"message": "Sensor not Found !"} else: sensor.frequency = data["frequency"] sensor.timeInterval = data["timeInterval"] sensor.save_to_db() return sensor.json()
def put(self, name): data = UpdateSensorRange.parser.parse_args() sensor = SensorModel.find_by_name(name) if sensor is None: return {"message": "Sensor not Found !"} else: sensor.minRange = data["minRange"] sensor.maxRange = data["maxRange"] sensor.save_to_db() return sensor.json()
def delete(self, name): user = current_identity print(user.access) if user.access == "admin": sensor = SensorModel.find_by_name(name) if sensor: sensor.delete_from_db() return {"message": "Sensor deleted"} else: return {"message": "You do not have ADMIN Rights"}, 405
def post(self, name): if SensorModel.find_by_name(name): return { 'message': "A sensor with name '{}' already exists.".format(name) }, 400 sensor = SensorModel(magnitude) # try: sensor.save_to_db() # except: # return {'message': 'An error occurred while creating the sensor.'}, 500 return sensor.json(), 201
def put(self, name): data = UpdateSensorTimeInterval.parser.parse_args() sensor = SensorModel.find_by_name(name) try: if sensor is None: return {"message": "Sensor not Found !"} else: sensor.timeInterval = data["timeInterval"] sensor.save_to_db() return { "message": "Time Interval has been updated.", "sensor": sensor.json() } except Exception as error: return {"message": error}
def put(self, name): data = UpdateSensorFrequency.parser.parse_args() sensor = SensorModel.find_by_name(name) try: if sensor is None: return {"message": "Sensor not Found !"} else: sensor.frequency = data["frequency"] sensor.save_to_db() return { "message": "Frequency has been updated.", "sensor": sensor.json() } except Exception as error: return {"message": error}
def put(self, name): user = current_identity print(user.access) if user.access == "admin": data = SensorByName.parser.parse_args() sensor = SensorModel.find_by_name(name) if sensor is None: sensor = SensorModel(name, data["value"]) else: sensor.value = data["value"] sensor.save_to_db() return sensor.json() else: return {"message": "You do not have ADMIN Rights."}, 405
def post(self): user = current_identity print(user.access) if user.access == "admin": data = Sensor.parser.parse_args() if SensorModel.find_by_name(data["name"]): return { "message": "A sensor with name '{}' already exists.".format( data["name"]) } sensor = SensorModel(data["name"], data["value"]) try: sensor.save_to_db() except: return {"message": "An error occurred inserting the item."} return sensor.json(), 201 else: return {"message": "You do not have ADMIN Rights"}, 405
def post(self): # user = current_identity # print(user.access) # if user.access == "admin": data = Sensor.parser.parse_args() if SensorModel.find_by_name(data["name"]): return { "message": "A sensor with name '{}' already exists.".format(data["name"]) } sensor = SensorModel(data["name"], data["cloud"], data["connection"], data["format"], data["timeInterval"], data["frequency"], data["minRange"], data["maxRange"]) try: sensor.save_to_db() except: return {"message": "An error occurred inserting the item."} return sensor.json(), 201
def post(self, name): sensor = SensorModel.find_by_name(name) if sensor: sensor = sensor.json() print(sensor['connection']) connectionDict = json.loads(sensor['connection']) # print(connectionDict) if sensor['cloud'] == "thingworx": simulationThingworx(connectionDict, sensor['frequency'], sensor['timeInterval'], sensor['minRange'], sensor['maxRange']) elif sensor['cloud'] == "aws": simulationAWS(connectionDict) elif sensor['cloud'] == "azure": simulationAZURE(connectionDict) else: return { "message": "We don't support simulation for this cloud." } return {"message": "Simulation Completed"} else: return {"message": "Not Found"}
def get(self, name): sensor = SensorModel.find_by_name(name) if sensor: return sensor.json() return {"message": "Item not found"}, 404
def get(self, name): sensor = SensorModel.find_by_name(name) if sensor: return sensor.json(), 200 return {"message": "Sensor not found", "statusCode": 404}, 404
def get(self, name): sensor = SensorModel.find_by_name(name) if sensor: return sensor.json() return {'message': 'Sensor not found'}, 404
def delete(self, name): sensor = SensorModel.find_by_name(name) if sensor: sensor.delete_from_db() return {'message': 'Sensor deleted'}