update according to hardware changes

master
Nicolò Balzarotti 2023-03-30 15:45:02 +02:00
parent a8a1f5e983
commit b3ee15ebe2
4 changed files with 19 additions and 14 deletions

View File

@ -100,7 +100,7 @@ actuators = {
'humidifier': PIN(pin=17, initial=GPIO.HIGH, onstate=GPIO.LOW, offstate=GPIO.HIGH, 'humidifier': PIN(pin=17, initial=GPIO.HIGH, onstate=GPIO.LOW, offstate=GPIO.HIGH,
wattage=25), wattage=25),
'heater2': PIN(pin=17, initial=GPIO.HIGH, onstate=GPIO.LOW, offstate=GPIO.HIGH, 'heater2': PIN(pin=17, initial=GPIO.HIGH, onstate=GPIO.LOW, offstate=GPIO.HIGH,
wattage=2000), wattage=400),
'freezer': PIN(pin=14, initial=GPIO.HIGH, onstate=GPIO.LOW, offstate=GPIO.HIGH, 'freezer': PIN(pin=14, initial=GPIO.LOW, onstate=GPIO.HIGH, offstate=GPIO.LOW,
wattage=165), wattage=165),
} }

7
app.py
View File

@ -149,7 +149,12 @@ def read_sensors():
scantime = 0.5 scantime = 0.5
periodic_state_every_s = 5 periodic_state_every_s = 5
periodic_state_every_loop = int(periodic_state_every_s/scantime) periodic_state_every_loop = int(periodic_state_every_s/scantime)
last_scan = 0
while True: while True:
# This should be more precise than sleep(0.5) and gives the OS the
# control to do other things
sleep(0.01)
if perf_counter() - last_scan > scantime:
sensors.read() sensors.read()
socketio.emit('sensors', (sensors.get(),)) socketio.emit('sensors', (sensors.get(),))
if periodic_counter % periodic_state_every_loop == 0: if periodic_counter % periodic_state_every_loop == 0:
@ -159,7 +164,7 @@ def read_sensors():
# Issuing a full state update is easiest # Issuing a full state update is easiest
updateState() updateState()
periodic_counter += 1 periodic_counter += 1
sleep(scantime) last_scan = perf_counter()
import threading import threading
if __name__ == '__main__': if __name__ == '__main__':

View File

@ -180,7 +180,7 @@ class State():
response = ctrl.apply(self.envdata['sensors'][ctrl.input_label][0]) response = ctrl.apply(self.envdata['sensors'][ctrl.input_label][0])
actuators[controller].enable(response) actuators[controller].enable(response)
except Exception as e: except Exception as e:
print(f"UNKNOWN BUG HERE in run_step {e}") print(f"UNKNOWN BUG HERE in run_step {e} on controller {ctrl}")
if self.check(): if self.check():
if self.next() is None: if self.next() is None:
return True return True

View File

@ -220,7 +220,7 @@ class Sensors():
'H_ext2': AHT40('Humidity'), 'H_ext2': AHT40('Humidity'),
'heater': GPIOState(22), 'heater': GPIOState(22),
'humidifier/heater2': GPIOState(17), 'humidifier/heater2': GPIOState(17),
'freezer': GPIOState(14), 'freezer': GPIOState(14, transform=lambda x: x),
'fan': GPIOState(27), 'fan': GPIOState(27),
} }