add AHT40 sensor
This commit is contained in:
parent
2c5dd60aa4
commit
9072b24e55
37
sensors.py
37
sensors.py
|
@ -22,6 +22,13 @@ except:
|
||||||
print("Adafruit SHT4X not available!")
|
print("Adafruit SHT4X not available!")
|
||||||
enable_sht = False
|
enable_sht = False
|
||||||
|
|
||||||
|
try:
|
||||||
|
import AHT20
|
||||||
|
enable_aht = True
|
||||||
|
except:
|
||||||
|
print("Adafruit SHT4X not available!")
|
||||||
|
enable_aht = False
|
||||||
|
|
||||||
# TODO client: add a way to disable live plotting? server: stop
|
# TODO client: add a way to disable live plotting? server: stop
|
||||||
# sending data periodically to everybody!
|
# sending data periodically to everybody!
|
||||||
|
|
||||||
|
@ -114,6 +121,9 @@ if enable_sht:
|
||||||
SHT40_DEFAULT = adafruit_sht4x.Mode.NOHEAT_HIGHPRECISION
|
SHT40_DEFAULT = adafruit_sht4x.Mode.NOHEAT_HIGHPRECISION
|
||||||
sht.mode = SHT40_DEFAULT
|
sht.mode = SHT40_DEFAULT
|
||||||
|
|
||||||
|
if enable_aht:
|
||||||
|
aht = AHT20.AHT20()
|
||||||
|
|
||||||
class SHT40(Sensor):
|
class SHT40(Sensor):
|
||||||
def __init__(self, what, every=600):
|
def __init__(self, what, every=600):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
@ -160,6 +170,31 @@ class SHT40(Sensor):
|
||||||
return self.store(
|
return self.store(
|
||||||
time, temperature if self.measure == 'Temperature' else relative_humidity)
|
time, temperature if self.measure == 'Temperature' else relative_humidity)
|
||||||
|
|
||||||
|
class AHT40(Sensor):
|
||||||
|
def __init__(self, what):
|
||||||
|
super().__init__()
|
||||||
|
if what not in ("Temperature", "Humidity"):
|
||||||
|
print("ERROR: invalid sensor value: ", what)
|
||||||
|
return
|
||||||
|
self.measure = what
|
||||||
|
if not enable_aht:
|
||||||
|
return
|
||||||
|
|
||||||
|
def is_temperature(self):
|
||||||
|
return self.measure == "Temperature"
|
||||||
|
|
||||||
|
def is_humidity(self):
|
||||||
|
return self.measure == "Humidity"
|
||||||
|
|
||||||
|
def read(self):
|
||||||
|
time = perf_counter()
|
||||||
|
if not enable_aht:
|
||||||
|
return (time, None)
|
||||||
|
return self.store(
|
||||||
|
time, aht20.get_temperature_crc8() if (
|
||||||
|
self.measure == 'Temperature'
|
||||||
|
) else aht20.get_humidity_crc8())
|
||||||
|
|
||||||
class Sensors():
|
class Sensors():
|
||||||
def __init__(self, history=2621440):
|
def __init__(self, history=2621440):
|
||||||
self.starttime = (datetime.now(), perf_counter())
|
self.starttime = (datetime.now(), perf_counter())
|
||||||
|
@ -181,6 +216,8 @@ class Sensors():
|
||||||
'T_food': Temperature1W('28-06214252b671'),
|
'T_food': Temperature1W('28-06214252b671'),
|
||||||
'T_ext': SHT40('Temperature'),
|
'T_ext': SHT40('Temperature'),
|
||||||
'H_ext': SHT40('Humidity'),
|
'H_ext': SHT40('Humidity'),
|
||||||
|
'T_ext2': AHT40('Temperature'),
|
||||||
|
'H_ext2': AHT40('Humidity'),
|
||||||
'heater': GPIOState(22),
|
'heater': GPIOState(22),
|
||||||
'humidifier/heater2': GPIOState(17),
|
'humidifier/heater2': GPIOState(17),
|
||||||
'freezer': GPIOState(14),
|
'freezer': GPIOState(14),
|
||||||
|
|
Loading…
Reference in New Issue