Simple Watchdog Timer. A simple watchdog timer to reset the ESP8266 if it gets

@Petr_Stehlik
Thank you for the information. I need to kick the watchdog once every poll of 9 ESP servers. This takes about 60 seconds so need a watchdog that times out after 80 seconds or more.

@Brian_Lambert you’re right, I just tried to help you recognize what watchdog rebooted your ESP thus suggested something that is not very practical. So feel free to set the software watchdog to 80 seconds but make sure to return control back to ESP internals regularly (by calling the delay) so the hardware watchdog does not step in.

@Petr_Stehlik
Will do, thank you.

Reverted to using Ticker library as a watchdog in placed of the hardwired one. Seems to work ok so far.

Hi @Brian_Lambert, @Petr_Stehlik. I tried to put watchdog timer into the simple blynk program for testing but seem like it run forever and stop right in setup(), the code in main loop () never run. Please help me out. Many thanks!

void setup() {
// initialize digital pin LED_BUILTIN as an output.
pinMode(LED_BUILTIN, OUTPUT);
while (1){ ESP.wdtFeed();} //enable WD
}

// the loop function runs over and over again forever
void loop() {
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}

First you need to enable the watchdog by ESP.wdtEnable(1000); in your setup function.
Ant then you should not place the while(1){ESP.wdtFeed();} in the setup function, because that while is repeated forever, so you will never get to the loop function!

As long as ESP.wdtFeed() or your Delay(1000) is called within the duration that is defined in ESP.wdtEnabl() the watchdog is happy and will not reset the ESP. To test that, place a while(1){} before the first delay in your loop and the watchdog will reset the ESP after the defined duration.

Thanks @cprezzi. I think software WD is built in function and we dont have specifically set the timer for it. But I did put it to the code.

void setup() {
ESP.wdtEnable(1000);
// initialize digital pin LED_BUILTIN as an output.
pinMode(LED_BUILTIN, OUTPUT);
}

// the loop function runs over and over again forever
void loop() {
Serial.begin(115200);
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
delay(1000);
// wait for a second
while (true){ESP.wdtFeed();}
}

The above code still did not work (LED not blinking) until I put a “break;” right after ESP.wdtFeed to end the true loop.

I am not sure when issue come, the dog would bite or not

That can’t work!
Your loop function just switch the LED on, waits 1s, switch the LED off, wait 1s and then loops endless in the while loop. The watchdog will not trigger because you make the watchdog permanently happy in the while loop.

Just delete the “ESP.wdtFeed();” call in the while loop, and you will see if the watchdog triggers.

Hi. I thought the purpose of ESP.wdtFeed() is to feed the dog (reset timer) so that it will not triggers the reset as long as the Chip/Program is still functioning. If I delete the ESP.wdtFeed() then it will reset after software timeout (which is not what I want).

When I put the break after feeding the dog, the program was able to jump out of the loop and continue to run normal (led binking). But I am not sure when the chip or program run into unexpected error, the watchdog will work or not.

I tough you just want to test if the watchdog jumpes in.

Placing a break in the while does not make sense. Instead you could delete the while and just call feed.

But what do you expect to block in your loop function that could make use of a watchdog?
A watchdog is used if you have subroutines that might not come back or loops that might never stop.

In India, You have too many power blackouts and low voltage situations. My home is equipped with some esp8266 based relays, they are my developed pcb’s and i have rectified some problems like delaying en pin to ensure proper startup voltage (Like TTGO Boards adding a capacitor and 10k resistor to en pin of esp8266 to start esp8266 delayed when powering by ams1117 3.3v). It rectified some freezing problem with my wifi based relay boards, but after some days, still esp8266 board (which connects to electricity, not having inverter output), keeps freezing, and i have to reset them by powering them down.

I need a watchdog to reset the esp8266 when it found non toggling the gpio of esp8266.

The circuit you have shown is partially usable (if esp8266 hangs turning on the gpio then it will not reset the esp8266)

I suggest using proper watchdog ic’s or atleast attiny13 with proper coding as a watchdog for esp8266)

ajaybnl@ google email.com

1 Like