From 38f26f3e6502eb4cfbb0db248581d6f5000bd4d0 Mon Sep 17 00:00:00 2001 From: "Kelvin Ly (from lePotato)" Date: Wed, 21 Aug 2024 12:59:12 -0400 Subject: [PATCH] Add support for the fan --- .../humidifier_controller.ino | 20 ++++++++++--------- shroom_controller.py | 18 ++++++++++++++--- 2 files changed, 26 insertions(+), 12 deletions(-) diff --git a/humidifier_controller/humidifier_controller.ino b/humidifier_controller/humidifier_controller.ino index aa20768..2b733f8 100644 --- a/humidifier_controller/humidifier_controller.ino +++ b/humidifier_controller/humidifier_controller.ino @@ -33,10 +33,13 @@ void fanOff() { } +const int PIN_RELAY4 = 4; +const int PIN_RELAY3 = 5; + void setup() { - pinMode(4, OUTPUT); - pinMode(5, OUTPUT); + pinMode(PIN_RELAY4, OUTPUT); + pinMode(PIN_RELAY3, OUTPUT); pinMode(7, OUTPUT); digitalWrite(7, LOW); @@ -53,8 +56,6 @@ void setup() //sht20.checkSHT20(); // Check SHT20 Sensor } -const int PIN_RELAY4 = 4; -const int PIN_RELAY3 = 5; void loop() { @@ -74,13 +75,14 @@ void loop() Serial.print(temp); Serial.print(","); Serial.print(digitalRead(PIN_RELAY4)); - //Serial.print(","); - //Serial.println(volts2); + Serial.print(","); + Serial.print(digitalRead(PIN_RELAY3)); Serial.println(""); - } else if (c == 'z' || c == 'Z') { - if (c == 'z') digitalWrite(PIN_RELAY4, LOW); - if (c == 'Z') digitalWrite(PIN_RELAY4, HIGH); } + if (c == 'z') digitalWrite(PIN_RELAY4, LOW); + if (c == 'Z') digitalWrite(PIN_RELAY4, HIGH); + if (c == 'y') digitalWrite(PIN_RELAY3, LOW); + if (c == 'Y') digitalWrite(PIN_RELAY3, HIGH); } delay(1); } diff --git a/shroom_controller.py b/shroom_controller.py index 6c870ab..75c63f8 100644 --- a/shroom_controller.py +++ b/shroom_controller.py @@ -135,6 +135,8 @@ last_pipe_reboot = 0 last_running = False pipe_timeout = 10 +fan_on = False + try: while True: now = time.time() @@ -162,6 +164,15 @@ try: continue last_sample = now + # turn on the fan 1 minutes every 5 minutes + cur_min = int(now / 60) + fan_should_be_on = (cur_min % 5 == 0) + if fan_on != fan_should_be_on: + if fan_should_be_on: + s.write(b"Y") + else: + s.write(b"y") + #print("write s") s.write(b"s") s.flush() @@ -175,7 +186,8 @@ try: humidity = float(parts[0]) temp = float(parts[1]) volts = float(parts[2]) - #volts2 = float(parts[3]) + volts2 = float(parts[3]) + fan_on = int(volts2) #print(parts) try: @@ -183,14 +195,14 @@ try: controller.update(s, humidity) if frame_num == 0: - print(humidity, temp, volts) + #print(humidity, temp, volts) update = { "data": { "time": int(now*1000), "temp": temp, "hum": humidity, "hv": volts, - "hv2": 1 if humidifier.on else 0, + "hv2": volts2, } } send_update(update)