Browse Source

kitchen_pilot_wire_control.ino: add a loop watchdog

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

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

@ -3,8 +3,12 @@
Switches on or off a heater.
*/
#include <Ticker.h>
#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();
}

Loading…
Cancel
Save