From bf6018d3def2477376388d3aad87ef5f94e3b6e1 Mon Sep 17 00:00:00 2001 From: Richard Genoud Date: Tue, 10 Dec 2019 15:27:11 +0100 Subject: [PATCH] kitchen_pilot_wire_control.ino: add a loop watchdog --- .../kitchen_pilot_wire_control.ino | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) 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 129ef8b..fb46193 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 @@ -3,8 +3,12 @@ Switches on or off a heater. */ +#include + #include "EspMQTTClient.h" +#define LWD_TIMEOUT_MS 15000 + EspMQTTClient client( "rico", "xxxxxx", @@ -30,6 +34,10 @@ const int led_pin = 2; digitalWrite(pin, HIGH); \ } while(0) +// loop watchdog variables +unsigned long lwdTime = 0; +unsigned long lwdTimeout = LWD_TIMEOUT_MS; +Ticker lwdTicker; os_timer_t keep_alive_timer; @@ -40,6 +48,19 @@ void reset_timer(os_timer_t *timer) os_timer_arm(timer, 3600000, false); } +void ICACHE_RAM_ATTR lwdtcb(void) +{ + if (((millis() - lwdTime) > LWD_TIMEOUT_MS) || ((lwdTimeout - lwdTime) != LWD_TIMEOUT_MS)) + { + ESP.restart(); + } +} + +void lwdtFeed(void) { + lwdTime = millis(); + lwdTimeout = lwdTime + LWD_TIMEOUT_MS; +} + void message_callback(const String &message) { Serial.println(message); @@ -101,4 +122,5 @@ void loop() led_on(led_state); } counter++; + lwdtFeed(); }