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()
{
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);
}

View File

@ -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)