From 0393fa3a456af51e08f7b97baef2cb93bc86d6d1 Mon Sep 17 00:00:00 2001 From: cyberman54 Date: Sat, 26 Dec 2020 20:45:10 +0100 Subject: [PATCH] repair OTA & deepsleep combination --- src/cyclic.cpp | 13 +++---------- src/rcommand.cpp | 6 +++++- src/reset.cpp | 9 +++++++-- 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/src/cyclic.cpp b/src/cyclic.cpp index a927a21e..88d618e5 100644 --- a/src/cyclic.cpp +++ b/src/cyclic.cpp @@ -20,16 +20,9 @@ void setCyclicIRQ() { // do all housekeeping void doHousekeeping() { - // check if update mode trigger switch was set - if (RTC_runmode == RUNMODE_UPDATE) { - // check battery status if we can before doing ota - if (batt_sufficient()) { - do_reset(true); // warmstart to runmode update - } else { - ESP_LOGE(TAG, "Battery level %d%% is too low for OTA", batt_level); - RTC_runmode = RUNMODE_NORMAL; // keep running in normal mode - } - } + // check if update mode trigger switch was set by rcommand + if (RTC_runmode == RUNMODE_UPDATE) + do_reset(true); // heap and task storage debugging ESP_LOGD(TAG, "Heap: Free:%d, Min:%d, Size:%d, Alloc:%d, StackHWM:%d", diff --git a/src/rcommand.cpp b/src/rcommand.cpp index d69bb0cc..9aad91ff 100644 --- a/src/rcommand.cpp +++ b/src/rcommand.cpp @@ -35,7 +35,11 @@ void set_reset(uint8_t val[]) { case 9: // reset and ask for software update via Wifi OTA ESP_LOGI(TAG, "Remote command: software update via Wifi"); #if (USE_OTA) - RTC_runmode = RUNMODE_UPDATE; + // check power status before scheduling ota update + if (batt_sufficient()) + RTC_runmode = RUNMODE_UPDATE; + else + ESP_LOGE(TAG, "Battery level %d%% is too low for OTA", batt_level); #endif // USE_OTA break; diff --git a/src/reset.cpp b/src/reset.cpp index 89720993..998367b1 100644 --- a/src/reset.cpp +++ b/src/reset.cpp @@ -49,7 +49,6 @@ void do_after_reset(void) { break; case DEEPSLEEP_RESET: // 0x05 Deep Sleep reset digital core - RTC_runmode = RUNMODE_WAKEUP; // calculate time spent in deep sleep gettimeofday(&sleep_stop_time, NULL); sleep_time_ms = @@ -57,6 +56,9 @@ void do_after_reset(void) { (sleep_stop_time.tv_usec - RTC_sleep_start_time.tv_usec) / 1000; ESP_LOGI(TAG, "Time spent in deep sleep: %d ms", sleep_time_ms); RTC_millis += sleep_time_ms; // increment system monotonic time + // set wakeup state, not if we have pending OTA update + if (RTC_runmode == RUNMODE_SLEEP) + RTC_runmode = RUNMODE_WAKEUP; break; case SW_RESET: // 0x03 Software reset digital core @@ -103,7 +105,7 @@ void enter_deepsleep(const uint64_t wakeup_sec = 60, // stop further enqueuing of senddata and MAC processing sendTimer.detach(); - // switch off radio + // switch off radio and other power consuming hardware #if (WIFICOUNTER) switch_wifi_sniffer(0); #endif @@ -111,6 +113,9 @@ void enter_deepsleep(const uint64_t wakeup_sec = 60, stop_BLEscan(); btStop(); #endif +#if (HAS_SDS011) + sds011_sleep(void); +#endif // stop MAC processing vTaskDelete(macProcessTask);