ESP32 Reboot system when watchdog timeout
1 min readJan 4, 2018
Use for reboot when system obstructed.
Suggestion from https://github.com/me-no-dev
The story in https://github.com/espressif/arduino-esp32/issues/841
Following is working code.
#include "esp_system.h"const int loopTimeCtl = 0;
hw_timer_t *timer = NULL;void IRAM_ATTR resetModule(){
ets_printf("reboot\n");
esp_restart_noos();
}void setup() {
Serial.begin(115200);
pinMode(loopTimeCtl, INPUT_PULLUP);
delay(1000);
Serial.println("running setup");timer = timerBegin(0, 80, true); //timer 0, div 80
timerAttachInterrupt(timer, &resetModule, true);
timerAlarmWrite(timer, 3000000, false); //set time in us
timerAlarmEnable(timer); //enable interrupt
}void loop() {
timerWrite(timer, 0); //reset timer (feed watchdog)
long tme = millis();
Serial.println("running mainloop");
while(!digitalRead(loopTimeCtl)){
Serial.println("button pressed");
delay(500);
}
delay(1000);
Serial.print("loop time is = ");
tme = millis() - tme;
Serial.println(tme);
}
Place code timerWrite(timer, 0); to feeding watchdog otherwise timeout fired and reboot.