diff --git a/app_httpd.cpp b/app_httpd.cpp index 9f10f5d..5a9a1b5 100644 --- a/app_httpd.cpp +++ b/app_httpd.cpp @@ -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; diff --git a/esp32-cam-webserver.ino b/esp32-cam-webserver.ino index 023f7a1..5a992fb 100644 --- a/esp32-cam-webserver.ino +++ b/esp32-cam-webserver.ino @@ -1,4 +1,6 @@ #include "esp_camera.h" +#include +#include #include #include #include "src/parsebytes.h" @@ -185,7 +187,16 @@ void flashLED(int flashtime) { #else return; // No notifcation LED, do nothing, no delay #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) { @@ -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();