bugfix in wifi on/off logic

This commit is contained in:
cyberman54 2020-12-21 19:35:21 +01:00
parent bb77277836
commit 62132030b7
2 changed files with 20 additions and 21 deletions

View File

@ -89,8 +89,18 @@ void enter_deepsleep(const uint64_t wakeup_sec = 60,
RTC_runmode = RUNMODE_SLEEP; 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(); sendTimer.detach();
vTaskDelete(macProcessTask);
// halt interrupts accessing i2c bus // halt interrupts accessing i2c bus
mask_user_IRQ(); mask_user_IRQ();
@ -140,15 +150,6 @@ void enter_deepsleep(const uint64_t wakeup_sec = 60,
if (i == 0) if (i == 0)
goto Error; 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) #if (HAS_LORA)
SaveLMICToRTC(wakeup_sec); SaveLMICToRTC(wakeup_sec);

View File

@ -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_storage(WIFI_STORAGE_RAM));
ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_NULL)); 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_ps(WIFI_PS_NONE)); // no modem power saving
ESP_ERROR_CHECK( ESP_ERROR_CHECK(
esp_wifi_set_promiscuous_filter(&wifi_filter)); // set frame filter 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_rx_cb(&wifi_sniffer_packet_handler));
ESP_ERROR_CHECK(esp_wifi_set_promiscuous(true)); // now switch on monitor mode
// setup wifi channel hopping timer // setup wifi channel hopping timer
WifiChanTimer = WifiChanTimer =
@ -82,24 +80,24 @@ void wifi_sniffer_init(void) {
(cfg.wifichancycle > 0) ? pdMS_TO_TICKS(cfg.wifichancycle) (cfg.wifichancycle > 0) ? pdMS_TO_TICKS(cfg.wifichancycle)
: pdMS_TO_TICKS(50), : pdMS_TO_TICKS(50),
pdTRUE, (void *)0, switchWifiChannel); pdTRUE, (void *)0, switchWifiChannel);
// start timer
if (cfg.wifichancycle > 0)
xTimerStart(WifiChanTimer, (TickType_t)0);
} }
void switch_wifi_sniffer(uint8_t state) { void switch_wifi_sniffer(uint8_t state) {
if (state) { if (state) {
// switch wifi sniffer on // start sniffer
ESP_ERROR_CHECK(esp_wifi_start()); ESP_ERROR_CHECK(esp_wifi_start());
esp_wifi_set_promiscuous(true); ESP_ERROR_CHECK(esp_wifi_set_promiscuous(true));
esp_wifi_set_channel(WIFI_CHANNEL_MIN, WIFI_SECOND_CHAN_NONE); ESP_ERROR_CHECK(
esp_wifi_set_channel(WIFI_CHANNEL_MIN, WIFI_SECOND_CHAN_NONE));
// start channel hopping timer
if (cfg.wifichancycle > 0) if (cfg.wifichancycle > 0)
xTimerStart(WifiChanTimer, (TickType_t)0); xTimerStart(WifiChanTimer, (TickType_t)0);
} else { } else {
// switch wifi sniffer off // start channel hopping timer
if (xTimerIsTimerActive(WifiChanTimer) != pdFALSE) if (xTimerIsTimerActive(WifiChanTimer) != pdFALSE)
xTimerStop(WifiChanTimer, (TickType_t)0); 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()); ESP_ERROR_CHECK(esp_wifi_stop());
} }
} }