From 6d1d358a56de9829b6d204945dc040a7e386d537 Mon Sep 17 00:00:00 2001 From: Klaus K Wilting Date: Wed, 17 Oct 2018 07:10:37 +0200 Subject: [PATCH] call LMIC_shutdown before ESP.restart --- include/rcommand.h | 1 + src/cyclic.cpp | 4 ++-- src/rcommand.cpp | 12 ++++++++---- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/include/rcommand.h b/include/rcommand.h index c656c9fd..bde9a151 100644 --- a/include/rcommand.h +++ b/include/rcommand.h @@ -16,5 +16,6 @@ typedef struct { } cmd_t; void rcommand(uint8_t cmd[], uint8_t cmdlength); +void do_reset(); #endif \ No newline at end of file diff --git a/src/cyclic.cpp b/src/cyclic.cpp index 06d45b62..f75daacf 100644 --- a/src/cyclic.cpp +++ b/src/cyclic.cpp @@ -15,7 +15,7 @@ void doHousekeeping() { // check if update mode trigger switch was set if (cfg.runmode == 1) - ESP.restart(); + do_reset(); // task storage debugging // ESP_LOGD(TAG, "Wifiloop %d bytes left", @@ -60,7 +60,7 @@ void doHousekeeping() { get_salt(); // get new salt for salting hashes if (esp_get_minimum_free_heap_size() <= MEM_LOW) // check again - esp_restart(); // memory leak, reset device + do_reset(); // memory leak, reset device } } // doHousekeeping() diff --git a/src/rcommand.cpp b/src/rcommand.cpp index 42e855a9..ab82deaa 100644 --- a/src/rcommand.cpp +++ b/src/rcommand.cpp @@ -5,15 +5,19 @@ // Local logging tag static const char TAG[] = "main"; +// helper function +void do_reset() { + ESP_LOGI(TAG, "Remote command: restart device"); + LMIC_shutdown(); + esp_restart(); +} + // set of functions that can be triggered by remote commands void set_reset(uint8_t val[]) { switch (val[0]) { case 0: // restart device - ESP_LOGI(TAG, "Remote command: restart device"); sprintf(display_line6, "Reset pending"); - vTaskDelay(10000 / portTICK_PERIOD_MS); // wait for LMIC to confirm LoRa - // downlink to server - esp_restart(); + do_reset(); break; case 1: // reset MAC counter ESP_LOGI(TAG, "Remote command: reset MAC counter");