def main(): print("main program for moisture reading") sensors = Sensors.query.all() # print("By Row:") # for row in sensorinfo: # print("Row:", row) for sensor_data in sensors: print("Next Sensor: {} {} {}".format(sensor_data.sensor_id, sensor_data.crop, sensor_data.bcm_pin)) nxt_sensor = moisturemeter.MoistureMeter(sensor_data.sensor_id, sensor_data.bcm_pin) print("get kPa for : ", sensor_data.sensor_id) sensor_reading_data = nxt_sensor.get_kpa_value() print("Return data: ", sensor_reading_data) new_reading = SensorReadings(sensor_data.sensor_id, sensor_reading_data) db.session.add(new_reading) db.session.commit() print("=========== END OF RUN ===========") # Clean up GPIO GPIO.cleanup()
def do_sensor_readings(): sensors = Sensors.query.all() for sensor_data in sensors: senlog.info("Next Sensor: {} {} {}".format(sensor_data.sensor_id, sensor_data.crops.crop_name, sensor_data.bcm_pin)) nxt_sensor = moisturemeter.MoistureMeter(sensor_data.sensor_id, sensor_data.bcm_pin) # senlog.debug("get kPa for : ", sensor_data.sensor_id) sensor_reading_data = nxt_sensor.get_kpa_value() senlog.info("Return data: ", sensor_reading_data) if (not sensor_reading_data["data_valid"]): senlog.error("Sensor reading returned DATA VALID as FALSE") new_reading = SensorReadings(sensor_data.sensor_id, sensor_reading_data) x = datetime.datetime.now() senlog.debug("Date:") senlog.debug(x) senlog.debug("New Reading") senlog.debug(new_reading.__dict__) db.session.add(new_reading) db.session.commit()
def get_sensor_reading(sensor_id): Sensor = Sensors.query.get(sensor_id) s_data = Sensor.__dict__ # senlog.debug(s_data) # senlog.debug("Next Sensor: {} {} {}".format(Sensor.sensor_id, Sensor.crops.crop_name, Sensor.bcm_pin)) sensor = moisturemeter.MoistureMeter(Sensor.sensor_id, Sensor.bcm_pin) # senlog.debug("Sensor: ") # senlog.debug(sensor) sensor_reading_data = sensor.get_kpa_value() return sensor_reading_data
def do_moisture_sensor_readings(): moisture_sensors = Sensors.query.all() # print("By Row:") # for row in sensorinfo: # print("Row:", row) for moisture_sensor_data in moisture_sensors: print("Next Sensor: {} {} {}".format(moisture_sensor_data.sensor_id, moisture_sensor_data.crop, moisture_sensor_data.bcm_pin)) nxt_sensor = moisturemeter.MoistureMeter(moisture_sensor_data.sensor_id, moisture_sensor_data.bcm_pin) print("get kPa for : ", moisture_sensor_data.sensor_id) sensor_reading_data = nxt_sensor.get_kpa_value() print("Return data: ", sensor_reading_data) new_reading = SensorReadings(moisture_sensor_data.sensor_id, sensor_reading_data) db.session.add(new_reading) db.session.commit()