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