Use the Watchdog timer to force a proper hard restart

This commit is contained in:
Owen 2020-10-29 08:51:24 +01:00
parent 99e957b3f9
commit 22c834e796
2 changed files with 17 additions and 5 deletions

View File

@ -29,6 +29,7 @@
// Functions from the main .ino
extern void flashLED(int flashtime);
extern void setLamp(int newVal);
extern void hard_restart();
// External variables declared in the main .ino
extern char myName[];
@ -629,7 +630,7 @@ static esp_err_t cmd_handler(httpd_req_t *req){
Serial.print('.');
}
Serial.printf(" Thats all folks!\n\n");
ESP.restart();
hard_restart();
}
else {
res = -1;

View File

@ -1,4 +1,6 @@
#include "esp_camera.h"
#include <esp_int_wdt.h>
#include <esp_task_wdt.h>
#include <WiFi.h>
#include <DNSServer.h>
#include "src/parsebytes.h"
@ -187,6 +189,15 @@ void flashLED(int flashtime) {
#endif
}
// ESP.restart() is very 'soft', it can leave the camera hardware
// improperly initialised; resulting in boot loops.
// This replacement uses a watchdog to force a hard restart after 1 second.
void hard_restart() {
esp_task_wdt_init(1,true);
esp_task_wdt_add(NULL);
while(true);
}
// Lamp Control
void setLamp(int newVal) {
if (newVal != -1) {
@ -448,9 +459,9 @@ void setup() {
} else {
delay(100); // need a delay here or the next serial o/p gets missed
Serial.println("Halted: Camera sensor failed to initialise");
Serial.println("Will reboot to try again in 10s\n");
delay(10000);
ESP.restart();
Serial.println("Will reboot to try again in 5s\n");
delay(4000);
hard_restart();
}
sensor_t * s = esp_camera_sensor_get();