From 8616129f2e382310802950db066178648a9429a3 Mon Sep 17 00:00:00 2001 From: Damien George Date: Tue, 3 Aug 2021 22:46:24 +1000 Subject: [PATCH] esp8266,esp32: Include hidden networks in WLAN.scan results. Addresses issues #2697 and #5329. Signed-off-by: Damien George --- docs/library/network.WLAN.rst | 2 ++ ports/esp32/modnetwork.c | 2 +- ports/esp8266/modnetwork.c | 4 +++- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/docs/library/network.WLAN.rst b/docs/library/network.WLAN.rst index 88bd3a3707..35e4b798ae 100644 --- a/docs/library/network.WLAN.rst +++ b/docs/library/network.WLAN.rst @@ -46,6 +46,8 @@ Methods .. method:: WLAN.scan() Scan for the available wireless networks. + Hidden networks -- where the SSID is not broadcast -- will also be scanned + if the WLAN interface allows it. Scanning is only possible on STA interface. Returns list of tuples with the information about WiFi access points: diff --git a/ports/esp32/modnetwork.c b/ports/esp32/modnetwork.c index 3977256166..2b64105e79 100644 --- a/ports/esp32/modnetwork.c +++ b/ports/esp32/modnetwork.c @@ -466,7 +466,7 @@ STATIC mp_obj_t esp_scan(mp_obj_t self_in) { mp_obj_t list = mp_obj_new_list(0, NULL); wifi_scan_config_t config = { 0 }; - // XXX how do we scan hidden APs (and if we can scan them, are they really hidden?) + config.show_hidden = true; MP_THREAD_GIL_EXIT(); esp_err_t status = esp_wifi_scan_start(&config, 1); MP_THREAD_GIL_ENTER(); diff --git a/ports/esp8266/modnetwork.c b/ports/esp8266/modnetwork.c index 949aeba106..f0cd83aeec 100644 --- a/ports/esp8266/modnetwork.c +++ b/ports/esp8266/modnetwork.c @@ -233,7 +233,9 @@ STATIC mp_obj_t esp_scan(mp_obj_t self_in) { } mp_obj_t list = mp_obj_new_list(0, NULL); esp_scan_list = &list; - wifi_station_scan(NULL, (scan_done_cb_t)esp_scan_cb); + struct scan_config config = {0}; + config.show_hidden = 1; + wifi_station_scan(&config, (scan_done_cb_t)esp_scan_cb); while (esp_scan_list != NULL) { // our esp_scan_cb is called via ets_loop_iter so it's safe to set the // esp_scan_list variable to NULL without disabling interrupts