def get(self, sensor_id): if SensorModel.find_by_id(sensor_id): return jsonify({"data": SensorModel.find_by_id(sensor_id)}) else: return { "message": "data by sensor by id : {} is not found".format(sensor_id) }
def post(self): data = Sensor.parser.parse_args() sensorData = SensorModel(**data) try: sensorData.save_to_db() except: return { "message": "And error occured while saving sensor data." }, 500 return sensorData.json(), 201
def post(self): data = SensorRegister.parser.parse_args() sensor_data = SensorModel(data["sensor_id"], data["moisture"], data["temperature"]) try: sensor_data.save_to_mongo() except: return {"message": "Database f****d up"}, 400 return sensor_data.jsonify()
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 = 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 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 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): # 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 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): 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 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): 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, 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 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): 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
from models.sensor import SensorModel from database import Database Database.initialize() sensor1 = SensorModel(101, 100, 100) sensor1.save_to_mongo() for i in Database.find("sensor_trial", {"id": 101}): print(i)
def get(self): return jsonify({"Sensor Values": SensorModel.get_all()})
def get(self, name): sensor = SensorModel.find_by_name(name) if sensor: return sensor.json() return {"message": "Item not found"}, 404
def delete(self, name): sensor = SensorModel.find_by_name(name) if sensor: sensor.delete_from_db() return {'message': 'Sensor deleted'}
def get(self, name): sensor = SensorModel.find_by_name(name) if sensor: return sensor.json() return {'message': 'Sensor 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