From 09a849903c33bd441b08b11eb97fe16f2c57e592 Mon Sep 17 00:00:00 2001 From: Dirk Alders Date: Fri, 4 Sep 2020 12:25:02 +0200 Subject: [PATCH] Initial envsens definitions --- __init__.py | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 __init__.py diff --git a/__init__.py b/__init__.py new file mode 100644 index 0000000..9d8bddc --- /dev/null +++ b/__init__.py @@ -0,0 +1,40 @@ +from config import dht_gpio +try: + import Adafruit_DHT as dht +except ImportError: + dht = None + +try: + import Adafruit_BMP.BMP085 as bmp +except ImportError: + bmp = None + +#TODO: background process for value sensing (every x seconds) + +KEY_TEMPERATURE = 't' +KEY_HUMIDITY = 'h' +KEY_PRESSURE = 'p' + + +class EnvSens(object): + def __init__(self): + if bmp is not None: + self.bmp = bmp.BMP085() + + def get_env_data(self): + # + # DHT22 + # + if dht is None: + h = -17.3 + t = -125.7 + else: + h, t = dht.read_retry(dht.DHT22, dht_gpio) + # + # BMP180 + # + if bmp is None: + p = -1024.17 + else: + p = self.bmp.read_pressure()/100. + return {KEY_TEMPERATURE: t, KEY_HUMIDITY: h, KEY_PRESSURE: p}