Add support for the fan

This commit is contained in:
Kelvin Ly (from lePotato) 2024-08-21 12:59:12 -04:00
parent a65dcb1ee4
commit 38f26f3e65
2 changed files with 26 additions and 12 deletions

View File

@ -33,10 +33,13 @@ void fanOff() {
} }
const int PIN_RELAY4 = 4;
const int PIN_RELAY3 = 5;
void setup() void setup()
{ {
pinMode(4, OUTPUT); pinMode(PIN_RELAY4, OUTPUT);
pinMode(5, OUTPUT); pinMode(PIN_RELAY3, OUTPUT);
pinMode(7, OUTPUT); pinMode(7, OUTPUT);
digitalWrite(7, LOW); digitalWrite(7, LOW);
@ -53,8 +56,6 @@ void setup()
//sht20.checkSHT20(); // Check SHT20 Sensor //sht20.checkSHT20(); // Check SHT20 Sensor
} }
const int PIN_RELAY4 = 4;
const int PIN_RELAY3 = 5;
void loop() void loop()
{ {
@ -74,13 +75,14 @@ void loop()
Serial.print(temp); Serial.print(temp);
Serial.print(","); Serial.print(",");
Serial.print(digitalRead(PIN_RELAY4)); Serial.print(digitalRead(PIN_RELAY4));
//Serial.print(","); Serial.print(",");
//Serial.println(volts2); Serial.print(digitalRead(PIN_RELAY3));
Serial.println(""); 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); delay(1);
} }

View File

@ -135,6 +135,8 @@ last_pipe_reboot = 0
last_running = False last_running = False
pipe_timeout = 10 pipe_timeout = 10
fan_on = False
try: try:
while True: while True:
now = time.time() now = time.time()
@ -162,6 +164,15 @@ try:
continue continue
last_sample = now 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") #print("write s")
s.write(b"s") s.write(b"s")
s.flush() s.flush()
@ -175,7 +186,8 @@ try:
humidity = float(parts[0]) humidity = float(parts[0])
temp = float(parts[1]) temp = float(parts[1])
volts = float(parts[2]) volts = float(parts[2])
#volts2 = float(parts[3]) volts2 = float(parts[3])
fan_on = int(volts2)
#print(parts) #print(parts)
try: try:
@ -183,14 +195,14 @@ try:
controller.update(s, humidity) controller.update(s, humidity)
if frame_num == 0: if frame_num == 0:
print(humidity, temp, volts) #print(humidity, temp, volts)
update = { update = {
"data": { "data": {
"time": int(now*1000), "time": int(now*1000),
"temp": temp, "temp": temp,
"hum": humidity, "hum": humidity,
"hv": volts, "hv": volts,
"hv2": 1 if humidifier.on else 0, "hv2": volts2,
} }
} }
send_update(update) send_update(update)