diff --git a/actuators.py b/actuators.py index 57b3071..c3379ac 100644 --- a/actuators.py +++ b/actuators.py @@ -100,7 +100,7 @@ actuators = { 'humidifier': PIN(pin=17, initial=GPIO.HIGH, onstate=GPIO.LOW, offstate=GPIO.HIGH, wattage=25), 'heater2': PIN(pin=17, initial=GPIO.HIGH, onstate=GPIO.LOW, offstate=GPIO.HIGH, - wattage=2000), - 'freezer': PIN(pin=14, initial=GPIO.HIGH, onstate=GPIO.LOW, offstate=GPIO.HIGH, + wattage=400), + 'freezer': PIN(pin=14, initial=GPIO.LOW, onstate=GPIO.HIGH, offstate=GPIO.LOW, wattage=165), } diff --git a/app.py b/app.py index c1e7995..e37b723 100644 --- a/app.py +++ b/app.py @@ -149,17 +149,22 @@ def read_sensors(): scantime = 0.5 periodic_state_every_s = 5 periodic_state_every_loop = int(periodic_state_every_s/scantime) + last_scan = 0 while True: - sensors.read() - socketio.emit('sensors', (sensors.get(),)) - if periodic_counter % periodic_state_every_loop == 0: - ## peridoic refresh other data, too, like: - # - current phase (time in this phase) - # - actuators (consumption) - # Issuing a full state update is easiest - updateState() - periodic_counter += 1 - sleep(scantime) + # 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() + socketio.emit('sensors', (sensors.get(),)) + if periodic_counter % periodic_state_every_loop == 0: + ## peridoic refresh other data, too, like: + # - current phase (time in this phase) + # - actuators (consumption) + # Issuing a full state update is easiest + updateState() + periodic_counter += 1 + last_scan = perf_counter() import threading if __name__ == '__main__': diff --git a/phasectrl.py b/phasectrl.py index 2e218a1..a0cf219 100644 --- a/phasectrl.py +++ b/phasectrl.py @@ -180,7 +180,7 @@ class State(): response = ctrl.apply(self.envdata['sensors'][ctrl.input_label][0]) actuators[controller].enable(response) 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.next() is None: return True diff --git a/sensors.py b/sensors.py index 14e5b29..ea56080 100644 --- a/sensors.py +++ b/sensors.py @@ -220,7 +220,7 @@ class Sensors(): 'H_ext2': AHT40('Humidity'), 'heater': GPIOState(22), 'humidifier/heater2': GPIOState(17), - 'freezer': GPIOState(14), + 'freezer': GPIOState(14, transform=lambda x: x), 'fan': GPIOState(27), }