Browse Source

kitchen_pilot_wire_control.ino: switch off heater if no order for an hour

master
Richard Genoud 5 years ago
parent
commit
30352d5ae1
1 changed files with 20 additions and 0 deletions
  1. +20
    -0
      soft/kitchen/kitchen_pilot_wire_control/kitchen_pilot_wire_control.ino

+ 20
- 0
soft/kitchen/kitchen_pilot_wire_control/kitchen_pilot_wire_control.ino View File

@ -27,6 +27,16 @@ const int heating_pin = 14;
digitalWrite(pin, HIGH); \
} while(0)
os_timer_t keep_alive_timer;
void reset_timer(os_timer_t *timer)
{
os_timer_disarm(timer);
os_timer_setfn(timer, shutdown_heater, NULL);
os_timer_arm(timer, 3600000, false);
}
void message_callback(const String &message)
{
Serial.println(message);
@ -36,6 +46,14 @@ void message_callback(const String &message)
if (message == "on") {
heater_on(heating_pin);
}
reset_timer(&keep_alive_timer);
}
void shutdown_heater(void *dummy)
{
// if we didn't receive a message for an hour,
// shutdown the heater
heater_off(heating_pin);
}
void setup()
@ -49,6 +67,8 @@ void setup()
client.enableDebuggingMessages(); // Enable debugging messages sent to serial output
client.enableHTTPWebUpdater(); // Enable the web updater. User and password default to values of MQTTUsername and MQTTPassword. These can be overrited with enableHTTPWebUpdater("user", "password").
//client.enableLastWillMessage("TestClient/lastwill", "I am going offline"); // You can activate the retain flag by setting the third parameter to true
os_timer_setfn(&keep_alive_timer, shutdown_heater, NULL);
os_timer_arm(&keep_alive_timer, 3600000, false);
}
// This function is called once everything is connected (Wifi and MQTT)


Loading…
Cancel
Save