repair OTA & deepsleep combination

This commit is contained in:
cyberman54 2020-12-26 20:45:10 +01:00
parent 866d0bd730
commit 0393fa3a45
3 changed files with 15 additions and 13 deletions

View File

@ -20,16 +20,9 @@ void setCyclicIRQ() {
// do all housekeeping // do all housekeeping
void doHousekeeping() { void doHousekeeping() {
// check if update mode trigger switch was set // check if update mode trigger switch was set by rcommand
if (RTC_runmode == RUNMODE_UPDATE) { if (RTC_runmode == RUNMODE_UPDATE)
// check battery status if we can before doing ota do_reset(true);
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
}
}
// heap and task storage debugging // heap and task storage debugging
ESP_LOGD(TAG, "Heap: Free:%d, Min:%d, Size:%d, Alloc:%d, StackHWM:%d", ESP_LOGD(TAG, "Heap: Free:%d, Min:%d, Size:%d, Alloc:%d, StackHWM:%d",

View File

@ -35,7 +35,11 @@ void set_reset(uint8_t val[]) {
case 9: // reset and ask for software update via Wifi OTA case 9: // reset and ask for software update via Wifi OTA
ESP_LOGI(TAG, "Remote command: software update via Wifi"); ESP_LOGI(TAG, "Remote command: software update via Wifi");
#if (USE_OTA) #if (USE_OTA)
// check power status before scheduling ota update
if (batt_sufficient())
RTC_runmode = RUNMODE_UPDATE; RTC_runmode = RUNMODE_UPDATE;
else
ESP_LOGE(TAG, "Battery level %d%% is too low for OTA", batt_level);
#endif // USE_OTA #endif // USE_OTA
break; break;

View File

@ -49,7 +49,6 @@ void do_after_reset(void) {
break; break;
case DEEPSLEEP_RESET: // 0x05 Deep Sleep reset digital core case DEEPSLEEP_RESET: // 0x05 Deep Sleep reset digital core
RTC_runmode = RUNMODE_WAKEUP;
// calculate time spent in deep sleep // calculate time spent in deep sleep
gettimeofday(&sleep_stop_time, NULL); gettimeofday(&sleep_stop_time, NULL);
sleep_time_ms = sleep_time_ms =
@ -57,6 +56,9 @@ void do_after_reset(void) {
(sleep_stop_time.tv_usec - RTC_sleep_start_time.tv_usec) / 1000; (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); ESP_LOGI(TAG, "Time spent in deep sleep: %d ms", sleep_time_ms);
RTC_millis += sleep_time_ms; // increment system monotonic time 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; break;
case SW_RESET: // 0x03 Software reset digital core 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 // stop further enqueuing of senddata and MAC processing
sendTimer.detach(); sendTimer.detach();
// switch off radio // switch off radio and other power consuming hardware
#if (WIFICOUNTER) #if (WIFICOUNTER)
switch_wifi_sniffer(0); switch_wifi_sniffer(0);
#endif #endif
@ -111,6 +113,9 @@ void enter_deepsleep(const uint64_t wakeup_sec = 60,
stop_BLEscan(); stop_BLEscan();
btStop(); btStop();
#endif #endif
#if (HAS_SDS011)
sds011_sleep(void);
#endif
// stop MAC processing // stop MAC processing
vTaskDelete(macProcessTask); vTaskDelete(macProcessTask);