diff --git a/src/reset.cpp b/src/reset.cpp index addeb36f..0572dabd 100644 --- a/src/reset.cpp +++ b/src/reset.cpp @@ -89,8 +89,18 @@ void enter_deepsleep(const uint64_t wakeup_sec = 60, RTC_runmode = RUNMODE_SLEEP; - // stop further enqueuing of senddata + // switch off radio +#if (WIFICOUNTER) + switch_wifi_sniffer(0); +#endif +#if (BLECOUNTER) + stop_BLEscan(); + btStop(); +#endif + + // stop further enqueuing of senddata and MAC processing sendTimer.detach(); + vTaskDelete(macProcessTask); // halt interrupts accessing i2c bus mask_user_IRQ(); @@ -140,16 +150,7 @@ void enter_deepsleep(const uint64_t wakeup_sec = 60, if (i == 0) goto Error; -// switch off radio -#if (WIFICOUNTER) - switch_wifi_sniffer(0); -#endif -#if (BLECOUNTER) - stop_BLEscan(); - btStop(); -#endif - - // save LMIC state to RTC RAM + // save LMIC state to RTC RAM #if (HAS_LORA) SaveLMICToRTC(wakeup_sec); #endif // (HAS_LORA) diff --git a/src/wifiscan.cpp b/src/wifiscan.cpp index edcafe13..ada8255a 100644 --- a/src/wifiscan.cpp +++ b/src/wifiscan.cpp @@ -70,11 +70,9 @@ void wifi_sniffer_init(void) { ESP_ERROR_CHECK(esp_wifi_set_storage(WIFI_STORAGE_RAM)); ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_NULL)); ESP_ERROR_CHECK(esp_wifi_set_ps(WIFI_PS_NONE)); // no modem power saving - ESP_ERROR_CHECK( esp_wifi_set_promiscuous_filter(&wifi_filter)); // set frame filter ESP_ERROR_CHECK(esp_wifi_set_promiscuous_rx_cb(&wifi_sniffer_packet_handler)); - ESP_ERROR_CHECK(esp_wifi_set_promiscuous(true)); // now switch on monitor mode // setup wifi channel hopping timer WifiChanTimer = @@ -82,24 +80,24 @@ void wifi_sniffer_init(void) { (cfg.wifichancycle > 0) ? pdMS_TO_TICKS(cfg.wifichancycle) : pdMS_TO_TICKS(50), pdTRUE, (void *)0, switchWifiChannel); - // start timer - if (cfg.wifichancycle > 0) - xTimerStart(WifiChanTimer, (TickType_t)0); } void switch_wifi_sniffer(uint8_t state) { if (state) { - // switch wifi sniffer on + // start sniffer ESP_ERROR_CHECK(esp_wifi_start()); - esp_wifi_set_promiscuous(true); - esp_wifi_set_channel(WIFI_CHANNEL_MIN, WIFI_SECOND_CHAN_NONE); + ESP_ERROR_CHECK(esp_wifi_set_promiscuous(true)); + ESP_ERROR_CHECK( + esp_wifi_set_channel(WIFI_CHANNEL_MIN, WIFI_SECOND_CHAN_NONE)); + // start channel hopping timer if (cfg.wifichancycle > 0) xTimerStart(WifiChanTimer, (TickType_t)0); } else { - // switch wifi sniffer off + // start channel hopping timer if (xTimerIsTimerActive(WifiChanTimer) != pdFALSE) xTimerStop(WifiChanTimer, (TickType_t)0); - esp_wifi_set_promiscuous(false); + // stop sniffer + ESP_ERROR_CHECK(esp_wifi_set_promiscuous(false)); ESP_ERROR_CHECK(esp_wifi_stop()); } } \ No newline at end of file