Initial envsens definitions
This commit is contained in:
förälder
c0e0e627c9
incheckning
09a849903c
40
__init__.py
Normal file
40
__init__.py
Normal file
@ -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}
|
Laddar…
x
Referens i nytt ärende
Block a user