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/main.cpp b/src/main.cpp index b52ce977..b5f69647 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -29,11 +29,11 @@ Task Core Prio Purpose ------------------------------------------------------------------------------- ledloop 0 3 blinks LEDs spiloop 0 2 reads/writes data on spi interface -mqttloop 0 2 reads/writes data on ETH interface IDLE 0 0 ESP32 arduino scheduler -> runs wifi sniffer lmictask 1 2 MCCI LMiC LORAWAN stack clockloop 1 4 generates realtime telegrams for external clock +mqttloop 1 2 reads/writes data on ETH interface timesync_proc 1 3 processes realtime time sync requests irqhandler 1 2 cyclic tasks (i.e. displayrefresh) triggered by timers gpsloop 1 1 reads data from GPS via serial or i2c diff --git a/src/mqttclient.cpp b/src/mqttclient.cpp index 867f06db..f66456ec 100644 --- a/src/mqttclient.cpp +++ b/src/mqttclient.cpp @@ -37,7 +37,7 @@ esp_err_t mqtt_init(void) { SEND_QUEUE_SIZE * PAYLOAD_BUFFER_SIZE); ESP_LOGI(TAG, "Starting MQTTloop..."); - xTaskCreate(mqtt_client_task, "mqttloop", 4096, (void *)NULL, 1, &mqttTask); + xTaskCreatePinnedToCore(mqtt_client_task, "mqttloop", 4096, (void *)NULL, 1, &mqttTask, 1); return ESP_OK; } 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);