Simple Watchdog Timer.
A simple watchdog timer to reset the ESP8266 if it gets stuck in a loop.
Capacitor = 4,700F and R3 = 33K. Using Panasonic 1381R voltage monitor. (pin 3 to ground, pin 1 output, pin 2 voltage to be monitored)
With the values above reset time can be varied from 50 to 250 seconds, if the watchdog is not kicked.
Arduino IDE sketch for testing the watchdog.
//ESP8266 watchdog test
//D5 to watchdog circuit kick the watchdog terminal
//ESP8266 reset to watchdog reset terminal
//Set WDCOUNT to 600 for testing time to reset
//and vary KICKDELAY to modify time to reset
//display counts up in seconds
//When the required time to reset is determined
//set WDCOUNT earlier than this time
#define WDKICK D5
#define WDCOUNT 180
#define KICKDELAY 2000
int counter =0;
// the setup function runs once when you press reset or power the board
void setup() {
pinMode(WDKICK, OUTPUT);// initialize digital pin as an output.
digitalWrite(WDKICK, LOW);//discharge capacitor
delay(KICKDELAY);
pinMode(WDKICK, INPUT);//set to high impedance
pinMode(BUILTIN_LED, OUTPUT);
Serial.begin(115200);
Serial.println();
Serial.println();
Serial.println(‘*BOOTED’);
Serial.println();
}
// the loop function runs over and over again forever
void loop() {
counter++;
Serial.println(counter);
digitalWrite(BUILTIN_LED, HIGH); // turn the LED on (HIGH is the voltage level)
delay(500); // wait for a second
//Serial.println(‘off’);
digitalWrite(BUILTIN_LED, LOW); // turn the LED off by making the voltage LOW
delay(500); // wait for a second
if(counter >= WDCOUNT)//time to kick the dog
{
counter = 0;
pinMode(WDKICK, OUTPUT);
digitalWrite(WDKICK, LOW);//kick the dog
delay(KICKDELAY);
pinMode(WDKICK, INPUT);//set to high impedance
Serial.println(‘Kicked the dog’);
}
}