Skip to content

Instantly share code, notes, and snippets.

@dirkjanfaber
Last active January 3, 2019 08:19
Show Gist options
  • Save dirkjanfaber/1a80a73c491b6f8da9b7ec2047f4d7ea to your computer and use it in GitHub Desktop.
Save dirkjanfaber/1a80a73c491b6f8da9b7ec2047f4d7ea to your computer and use it in GitHub Desktop.
A watchdog timer for ESP8266 (or just the Arduino). Based on the code of https://www.youtube.com/watch?v=D_7ciW_TCac
#include <Ticker.h>
Ticker secondTick;
#define debug 1
volatile int watchdogCount = 0;
void ISRwatchdog() {
watchdogCount++;
if ( watchdogCount == 5 ) {
// Only print to serial when debugging
(debug) && Serial.println("The dog bites!");
ESP.reset();
}
}
void setup() {
Serial.begin(115200);
Serial.println("Starting");
secondTick.attach(1, ISRwatchdog);
}
void loop() {
Serial.print("Watchdog counter = ");
Serial.println(watchdogCount);
// Feeding the dog
watchdogCount = 0;
delay(1000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment