From b0864c45b9aa54c14e4c54c260b8a103e631e77c Mon Sep 17 00:00:00 2001 From: cyberman54 Date: Sun, 21 Mar 2021 18:41:02 +0100 Subject: [PATCH] reset logic fixed, restart counter addes --- src/boot.cpp | 5 ++--- src/main.cpp | 13 ++++++------- src/reset.cpp | 15 ++++++--------- 3 files changed, 14 insertions(+), 19 deletions(-) diff --git a/src/boot.cpp b/src/boot.cpp index 0dd05943..889476d1 100644 --- a/src/boot.cpp +++ b/src/boot.cpp @@ -95,8 +95,8 @@ void start_boot_menu(void) { // (because esp_restart() from ISR would trigger the ESP32 task watchdog) xTaskCreate( [](void *p) { - vTaskSuspend(NULL); - ESP.restart(); + vTaskSuspend(NULL); // wait for task resume call by watchdog + esp_restart(); }, "Restart", configMINIMAL_STACK_SIZE, NULL, (3 | portPRIVILEGE_BIT), &RestartHandle); @@ -148,7 +148,6 @@ void start_boot_menu(void) { []() { server.sendHeader("Connection", "close"); server.send(200, "text/plain", (Update.hasError()) ? "FAIL" : "OK"); - WiFi.disconnect(true); esp_restart(); }, diff --git a/src/main.cpp b/src/main.cpp index 01b1b949..8f48c926 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -291,16 +291,15 @@ void setup() { #endif #if (BOOTMENU) - // start local webserver after device powers up or on rcommand request - if ((RTC_runmode == RUNMODE_POWERCYCLE) || - (RTC_runmode == RUNMODE_MAINTENANCE)) - start_boot_menu(); -#else - // start local webserver on rcommand request only - if (RTC_runmode == RUNMODE_MAINTENANCE) + // start local webserver after each coldstart + if (RTC_runmode == RUNMODE_POWERCYCLE) start_boot_menu(); #endif + // start local webserver on rcommand request + if (RTC_runmode == RUNMODE_MAINTENANCE) + start_boot_menu(); + // start mac processing task ESP_LOGI(TAG, "Starting MAC processor..."); macQueueInit(); diff --git a/src/reset.cpp b/src/reset.cpp index be940fe4..5e6165f7 100644 --- a/src/reset.cpp +++ b/src/reset.cpp @@ -10,6 +10,7 @@ static const char TAG[] = __FILE__; // RTC_NOINIT_ATTR -> keep value after a software restart or system crash RTC_NOINIT_ATTR runmode_t RTC_runmode; +RTC_NOINIT_ATTR uint32_t RTC_restarts; // RTC_DATA_ATTR -> keep values after a wakeup from sleep RTC_DATA_ATTR struct timeval RTC_sleep_start_time; @@ -17,9 +18,6 @@ RTC_DATA_ATTR unsigned long long RTC_millis = 0; timeval sleep_stop_time; -const char *runmode[6] = {"powercycle", "normal", "wakeup", - "update", "sleep", "maintenance"}; - void do_reset(bool warmstart) { if (warmstart) { ESP_LOGI(TAG, "restarting device (warmstart)"); @@ -46,13 +44,11 @@ void do_after_reset(void) { case RTCWDT_BROWN_OUT_RESET: // 0x0f Reset when the vdd voltage is not // stable RTC_runmode = RUNMODE_POWERCYCLE; + RTC_restarts = 0; break; case SW_CPU_RESET: // 0x0c Software reset CPU - // keep previous runmode, if RTC_runmode has valid value - // sets runmode, if RTC_runmode is invalid (i.e. not initialized) - if ((RTC_runmode != RUNMODE_UPDATE) && (RTC_runmode != RUNMODE_NORMAL)) - RTC_runmode = RUNMODE_POWERCYCLE; + // keep previous set runmode (update / normal / maintenance) break; case DEEPSLEEP_RESET: // 0x05 Deep Sleep reset digital core @@ -84,8 +80,9 @@ void do_after_reset(void) { break; } - ESP_LOGI(TAG, "Starting Software v%s, runmode %s", PROGVERSION, - runmode[RTC_runmode]); + RTC_restarts++; + ESP_LOGI(TAG, "Starting Software v%s (runmode=%d / restarts=%d)", PROGVERSION, + RTC_runmode, RTC_restarts); } void enter_deepsleep(const uint64_t wakeup_sec, gpio_num_t wakeup_gpio) {