New fermenter support
This commit is contained in:
parent
5991765c60
commit
6758716ae0
|
@ -53,4 +53,6 @@ class MockPIN(Actuator):
|
|||
|
||||
actuators = {
|
||||
'heater': (GPIOPin if rpi else MockPIN)(pin=22, initial=GPIO.HIGH, onstate=GPIO.LOW, offstate=GPIO.HIGH),
|
||||
'fan': (GPIOPin if rpi else MockPIN)(pin=27, initial=GPIO.HIGH, onstate=GPIO.LOW, offstate=GPIO.HIGH),
|
||||
'humidifier': (GPIOPin if rpi else MockPIN)(pin=17, initial=GPIO.HIGH, onstate=GPIO.LOW, offstate=GPIO.HIGH),
|
||||
}
|
||||
|
|
33
sensors.py
33
sensors.py
|
@ -7,6 +7,10 @@ from os.path import exists
|
|||
import RPi.GPIO as GPIO
|
||||
GPIO.setmode(GPIO.BCM)
|
||||
|
||||
# SHT40
|
||||
import board
|
||||
import adafruit_sht4x
|
||||
|
||||
# TODO client: add a way to disable live plotting? server: stop
|
||||
# sending data periodically to everybody!
|
||||
|
||||
|
@ -63,6 +67,28 @@ class Temperature1W(Sensor):
|
|||
return (time, None)
|
||||
return (time, int(re.search("t=([0-9]+)", content[1]).group(1)) / 1000.0)
|
||||
|
||||
class SHT40(Sensor):
|
||||
def __init__(self, what):
|
||||
self.measure = what
|
||||
self.i2c = board.I2C() # uses board.SCL and board.SDA
|
||||
self.sht = adafruit_sht4x.SHT4x(i2c)
|
||||
print('Serial: ', hex(self.sht.serial_number))
|
||||
# FIXME:
|
||||
self.sht.mode = adafruit_sht4x.Mode.NOHEAT_HIGHPRECISION
|
||||
# Can also set the mode to enable heater
|
||||
# sht.mode = adafruit_sht4x.Mode.LOWHEAT_100MS
|
||||
# modes = [adafruit_sht4x.Mode.HIGHHEAT_1S,
|
||||
# adafruit_sht4x.Mode.LOWHEAT_100MS,
|
||||
# adafruit_sht4x.Mode.NOHEAT_HIGHPRECISION]
|
||||
|
||||
def read(self):
|
||||
time = perf_counter()
|
||||
temperature, relative_humidity = sht.measurements
|
||||
# print("Temperature: %0.1f C" % temperature)
|
||||
# print("Humidity: %0.1f %%" % (relative_humidity))
|
||||
# print("")
|
||||
return (time, temerature if self.measure == 'Temperature' else relative_humidityg)
|
||||
|
||||
class Sensors():
|
||||
def __init__(self, history=2621440):
|
||||
self.starttime = (datetime.now(), perf_counter())
|
||||
|
@ -78,9 +104,12 @@ class Sensors():
|
|||
def scan(self):
|
||||
# FIXME: should scan, apply stored data and return this
|
||||
self.available_sensors = {
|
||||
'T_ext': Temperature1W('28-06214252b671'),
|
||||
'T_food': Temperature1W('28-062142531e5a'),
|
||||
'T_food': Temperature1W('28-06214252b671'),
|
||||
'T_ext': SHT40('Temperature'),
|
||||
'H_ext': SHT40('Humidity'),
|
||||
'heater': GPIOState(22),
|
||||
'humidifier': GPIOState(17),
|
||||
'fan': GPIOState(27),
|
||||
}
|
||||
|
||||
def list(self):
|
||||
|
|
Loading…
Reference in New Issue