Fix regression of reboot handler / reboot waiting script (#1725)

* Reboot after OTA: Avoid exeception

* Overview - optimize reload behaviour after reboot

* Update

* Update
This commit is contained in:
Slider0007
2022-12-30 21:58:46 +01:00
committed by GitHub
parent 58cbd680e8
commit 33f357d8da
4 changed files with 51 additions and 35 deletions

View File

@@ -93,7 +93,7 @@ void task_do_Update_ZIP(void *pvParameter)
} }
LogFile.WriteToFile(ESP_LOG_INFO, TAG, "Trigger reboot due to firmware update."); LogFile.WriteToFile(ESP_LOG_INFO, TAG, "Trigger reboot due to firmware update.");
doReboot(); doRebootOTA();
} }
else else
{ {
@@ -596,7 +596,7 @@ void hard_restart()
} }
void task_reboot(void *TaskCreated) void task_reboot(void *KillAutoFlow)
{ {
// write a reboot, to identify a reboot by purpouse // write a reboot, to identify a reboot by purpouse
FILE* pfile = fopen("/sdcard/reboot.txt", "w"); FILE* pfile = fopen("/sdcard/reboot.txt", "w");
@@ -604,7 +604,9 @@ void task_reboot(void *TaskCreated)
fwrite(_s_zw.c_str(), strlen(_s_zw.c_str()), 1, pfile); fwrite(_s_zw.c_str(), strlen(_s_zw.c_str()), 1, pfile);
fclose(pfile); fclose(pfile);
if ((bool)TaskCreated) { vTaskDelay(3000 / portTICK_PERIOD_MS);
if ((bool)KillAutoFlow) {
KillTFliteTasks(); // Kill autoflow task if executed in extra task, if not don't kill parent task KillTFliteTasks(); // Kill autoflow task if executed in extra task, if not don't kill parent task
} }
@@ -616,13 +618,14 @@ void task_reboot(void *TaskCreated)
esp_camera_deinit(); esp_camera_deinit();
WIFIDestroy(); WIFIDestroy();
vTaskDelay(4000 / portTICK_PERIOD_MS); vTaskDelay(3000 / portTICK_PERIOD_MS);
esp_restart(); // Reset type: CPU Reset (Reset both CPUs) esp_restart(); // Reset type: CPU reset (Reset both CPUs)
vTaskDelay(5000 / portTICK_PERIOD_MS); vTaskDelay(5000 / portTICK_PERIOD_MS);
hard_restart(); // Reset type: System reset (Triggered by watchdog), if esp_restart stalls (WDT needs to be activated) hard_restart(); // Reset type: System reset (Triggered by watchdog), if esp_restart stalls (WDT needs to be activated)
vTaskDelete(NULL); //Delete this task if it exits from the loop above ESP_LOGE(TAG, "Reboot failed!");
vTaskDelete(NULL); //Delete this task if it comes to this point
} }
@@ -630,31 +633,47 @@ void doReboot()
{ {
LogFile.WriteToFile(ESP_LOG_INFO, TAG, "Reboot triggered by Software (5s)."); LogFile.WriteToFile(ESP_LOG_INFO, TAG, "Reboot triggered by Software (5s).");
LogFile.WriteToFile(ESP_LOG_WARN, TAG, "Reboot in 5sec"); LogFile.WriteToFile(ESP_LOG_WARN, TAG, "Reboot in 5sec");
BaseType_t xReturned = xTaskCreate(&task_reboot, "task_reboot", configMINIMAL_STACK_SIZE * 3, (void*) true, 10, NULL); BaseType_t xReturned = xTaskCreate(&task_reboot, "task_reboot", configMINIMAL_STACK_SIZE * 3, (void*) true, 10, NULL);
if( xReturned != pdPASS ) if( xReturned != pdPASS )
{ {
ESP_LOGE(TAG, "task_reboot not created -> force reboot without killing flow"); ESP_LOGE(TAG, "task_reboot not created -> force reboot without killing flow");
task_reboot((void*) false); task_reboot((void*) false);
} }
vTaskDelay(10000 / portTICK_PERIOD_MS); // Prevent serving web client fetch response until system is shuting down
}
void doRebootOTA()
{
LogFile.WriteToFile(ESP_LOG_WARN, TAG, "Reboot in 5sec");
esp_camera_deinit();
vTaskDelay(5000 / portTICK_PERIOD_MS);
esp_restart(); // Reset type: CPU reset (Reset both CPUs)
vTaskDelay(5000 / portTICK_PERIOD_MS);
hard_restart(); // Reset type: System reset (Triggered by watchdog), if esp_restart stalls (WDT needs to be activated)
} }
esp_err_t handler_reboot(httpd_req_t *req) esp_err_t handler_reboot(httpd_req_t *req)
{ {
#ifdef DEBUG_DETAIL_ON #ifdef DEBUG_DETAIL_ON
LogFile.WriteHeapInfo("handler_reboot - Start"); LogFile.WriteHeapInfo("handler_reboot - Start");
#endif #endif
LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "handler_reboot"); LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "handler_reboot");
ESP_LOGI(TAG, "!!! System will restart within 5 sec!!!"); ESP_LOGI(TAG, "!!! System will restart within 5 sec!!!");
const char* resp_str = "<body style='font-family: arial'> <h3 id=t></h3></body><script>var h='Rebooting!<br>The page will automatically reload in around 25..60s<br>(in case of a firmware update it can take up to 180s).<br>'; document.getElementById('t').innerHTML=h; setInterval(function (){h +='.'; document.getElementById('t').innerHTML=h; fetch('/index.html',{mode: 'no-cors'}).then(r=>{parent.location.href=('/index.html');})}, 5000);</script>"; const char* resp_str = "<body style='font-family: arial'> <h3 id=t></h3></body><script>var h='Rebooting!<br>The page will automatically reload in around 25..60s<br>(in case of a firmware update it can take up to 180s).<br>'; document.getElementById('t').innerHTML=h; setInterval(function (){h +='.'; document.getElementById('t').innerHTML=h; fetch('/reboot_page.html',{mode: 'no-cors'}).then(r=>{parent.location.href=('/index.html');})}, 1000);</script>";
httpd_resp_send(req, resp_str, strlen(resp_str)); httpd_resp_send(req, resp_str, strlen(resp_str));
doReboot(); doReboot();
#ifdef DEBUG_DETAIL_ON #ifdef DEBUG_DETAIL_ON
LogFile.WriteHeapInfo("handler_reboot - Done"); LogFile.WriteHeapInfo("handler_reboot - Done");
#endif #endif
return ESP_OK; return ESP_OK;
} }

View File

@@ -13,6 +13,7 @@
void register_server_ota_sdcard_uri(httpd_handle_t server); void register_server_ota_sdcard_uri(httpd_handle_t server);
void CheckOTAUpdate(); void CheckOTAUpdate();
void doReboot(); void doReboot();
void doRebootOTA();
void hard_restart(); void hard_restart();
void CheckUpdate(); void CheckUpdate();

View File

@@ -180,7 +180,7 @@ esp_err_t reboot_handlerAP(httpd_req_t *req)
LogFile.WriteHeapInfo("handler_ota_update - Start"); LogFile.WriteHeapInfo("handler_ota_update - Start");
#endif #endif
LogFile.WriteToFile(ESP_LOG_INFO, TAG, "Trigger reboot due to firmware update."); LogFile.WriteToFile(ESP_LOG_INFO, TAG, "Trigger reboot due to firmware update.");
doReboot(); doRebootOTA();
return ESP_OK; return ESP_OK;
}; };

View File

@@ -81,45 +81,43 @@ function addZero(i) {
} }
$(document).ready(function() {
LoadData();
LoadROIImage();
});
function LoadData(){ function LoadData(){
loadStatus();
loadCPUTemp();
loadRSSI();
loadUptime();
loadRoundCounter();
loadValue("value", "value"); loadValue("value", "value");
loadValue("raw", "raw"); loadValue("raw", "raw");
loadValue("prevalue", "prevalue"); loadValue("prevalue", "prevalue");
loadValue("error", "error", "font-size:8px"); loadValue("error", "error", "font-size:8px");
loadStatus();
loadCPUTemp();
loadRSSI();
loadUptime();
loadRoundCounter();
} }
function LoadROIImage(){ function LoadROIImage(){
var d = new Date(); var d = new Date();
var timestamp = d.getTime();
var h = addZero(d.getHours()); var h = addZero(d.getHours());
var m = addZero(d.getMinutes()); var m = addZero(d.getMinutes());
var s = addZero(d.getSeconds()); var s = addZero(d.getSeconds());
$('#img').html('<img src="/img_tmp/alg_roi.jpg" style="max-height:555px; display:block; margin-left:auto; margin-right:auto;"></img>'); $('#img').html('<img src="/img_tmp/alg_roi.jpg?timestamp='+ timestamp +'" max-height:555px; display:block; margin-left:auto; margin-right:auto;"></img>');
$('#timestamp').html("Last Page Refresh:" + (h + ":" + m + ":" + s)); $('#timestamp').html("Last Page Refresh:" + (h + ":" + m + ":" + s));
} }
function Refresh() { function Refresh() {
setTimeout (function() { setTimeout (function() {
LoadData(); LoadData();
LoadROIImage();
var d = new Date();
var timestamp = d.getTime();
var h = addZero(d.getHours());
var m = addZero(d.getMinutes());
var s = addZero(d.getSeconds());
// reassign the url to be like alg_roi.jpg?timestamp=456784512 based on timestamp to ensure image is getting reloaded
$('#img').html('<img src="/img_tmp/alg_roi.jpg?timestamp='+ timestamp +'" max-height:555px; display:block; margin-left:auto; margin-right:auto;"></img>');
$('#timestamp').html("Last Page Refresh:" + (h + ":" + m + ":" + s));
Refresh(); Refresh();
}, 300000); }, 300000);
} }
function loadStatus() { function loadStatus() {
@@ -235,8 +233,6 @@ function addZero(i) {
function init(){ function init(){
basepath = getbasepath(); basepath = getbasepath();
LoadData();
LoadROIImage();
Refresh(); Refresh();
} }