41 lines
834 B
Python
41 lines
834 B
Python
|
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}
|