diff --git a/soft/kitchen/kitchen_pilot_wire_control/kitchen_pilot_wire_control.ino b/soft/kitchen/kitchen_pilot_wire_control/kitchen_pilot_wire_control.ino index bfe4ef5..aa69254 100644 --- a/soft/kitchen/kitchen_pilot_wire_control/kitchen_pilot_wire_control.ino +++ b/soft/kitchen/kitchen_pilot_wire_control/kitchen_pilot_wire_control.ino @@ -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)