From d0ffe853460887958b7c5ec7e40c8b535797f131 Mon Sep 17 00:00:00 2001 From: Javan R Date: Wed, 1 May 2019 11:17:44 +0200 Subject: [PATCH] moved bme280 into sensors/, fixed missing import --- measurement.py | 1 + read_bme280.py | 21 ++++++++------------- bme280.py => sensors/bme280.py | 0 3 files changed, 9 insertions(+), 13 deletions(-) rename bme280.py => sensors/bme280.py (100%) diff --git a/measurement.py b/measurement.py index 72daa6a..2894ebd 100644 --- a/measurement.py +++ b/measurement.py @@ -12,6 +12,7 @@ import RPi.GPIO as GPIO from read_bme680 import measure_bme680, initBME680FromMain +from read_bme280 import measure_bme280 from read_ds18b20 import measure_temperature from read_hx711 import measure_weight, compensate_temperature from read_dht import measure_dht diff --git a/read_bme280.py b/read_bme280.py index f9f2ade..b8e11b4 100644 --- a/read_bme280.py +++ b/read_bme280.py @@ -3,9 +3,7 @@ # See file LICENSE or go to http://creativecommons.org/licenses/by-nc-sa/3.0/ for full license details. import time -from bme280 import readBME280All #http://bit.ly/bme280py - -# global vars +from sensors.bme280 import readBME280All #http://bit.ly/bme280py def measure_bme280(ts_sensor): fields = {} @@ -14,16 +12,13 @@ def measure_bme280(ts_sensor): # ThingSpeak fields # Create returned dict if ts-field is defined - if 'ts_field_temperature' in ts_sensor: - fields[ts_sensor["ts_field_temperature"]] = temperature - if 'ts_field_humidity' in ts_sensor: - fields[ts_sensor["ts_field_humidity"]] = humidity - if 'ts_field_air_pressure' in ts_sensor: - fields[ts_sensor["ts_field_air_pressure"]] = pressure + if 'ts_field_temperature' in ts_sensor and isinstance(temperature, (int, float)): + fields[ts_sensor["ts_field_temperature"]] = round(temperature, 2) + if 'ts_field_humidity' in ts_sensor and isinstance(humidity, (int, float)): + fields[ts_sensor["ts_field_humidity"]] = round(humidity, 2) + if 'ts_field_air_pressure' in ts_sensor and isinstance(pressure, (int, float)): + fields[ts_sensor["ts_field_air_pressure"]] = round(pressure, 2) except OSError: - print('No BME280 Sensor connected') + print('No BME280 Sensor connected.') return fields -if __name__ == '__main__': - while True: - time.sleep(0.5) diff --git a/bme280.py b/sensors/bme280.py similarity index 100% rename from bme280.py rename to sensors/bme280.py