call LMIC_shutdown before ESP.restart

This commit is contained in:
Klaus K Wilting 2018-10-17 07:10:37 +02:00
parent ebfc16219b
commit 6d1d358a56
3 changed files with 11 additions and 6 deletions

View File

@ -16,5 +16,6 @@ typedef struct {
} cmd_t; } cmd_t;
void rcommand(uint8_t cmd[], uint8_t cmdlength); void rcommand(uint8_t cmd[], uint8_t cmdlength);
void do_reset();
#endif #endif

View File

@ -15,7 +15,7 @@ void doHousekeeping() {
// check if update mode trigger switch was set // check if update mode trigger switch was set
if (cfg.runmode == 1) if (cfg.runmode == 1)
ESP.restart(); do_reset();
// task storage debugging // // task storage debugging //
ESP_LOGD(TAG, "Wifiloop %d bytes left", ESP_LOGD(TAG, "Wifiloop %d bytes left",
@ -60,7 +60,7 @@ void doHousekeeping() {
get_salt(); // get new salt for salting hashes get_salt(); // get new salt for salting hashes
if (esp_get_minimum_free_heap_size() <= MEM_LOW) // check again if (esp_get_minimum_free_heap_size() <= MEM_LOW) // check again
esp_restart(); // memory leak, reset device do_reset(); // memory leak, reset device
} }
} // doHousekeeping() } // doHousekeeping()

View File

@ -5,15 +5,19 @@
// Local logging tag // Local logging tag
static const char TAG[] = "main"; 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 // set of functions that can be triggered by remote commands
void set_reset(uint8_t val[]) { void set_reset(uint8_t val[]) {
switch (val[0]) { switch (val[0]) {
case 0: // restart device case 0: // restart device
ESP_LOGI(TAG, "Remote command: restart device");
sprintf(display_line6, "Reset pending"); sprintf(display_line6, "Reset pending");
vTaskDelay(10000 / portTICK_PERIOD_MS); // wait for LMIC to confirm LoRa do_reset();
// downlink to server
esp_restart();
break; break;
case 1: // reset MAC counter case 1: // reset MAC counter
ESP_LOGI(TAG, "Remote command: reset MAC counter"); ESP_LOGI(TAG, "Remote command: reset MAC counter");