← index #11433PR #7521
Related · high · value 1.273
QUERY · ISSUE

ESP32 WLAN.scan() returns incorrect hidden flag

openby zcattaczopened 2023-05-06updated 2023-05-06
bug

Hi, new comer to micropython on ESP boards here. Just start to use this and realized the hidden flag in WLAN.scan() result is incorrect.

  • The documentation mentioned this flag as (ssid, bssid, channel, RSSI, authmode, hidden) , 0 - visible, 1 - hidden; but it's a bool not int.
  • In my test, all APs in results are always with hidden = False, though apparently the SSID returned is b'' and in wavmon these are reported as <Hidden SSID> (I mean confirmed as hidden not AP with empty SSID)

uos.uname() = (sysname='esp32', nodename='esp32', release='1.19.1', version='v1.19.1 on 2022-06-18', machine='ESP32 module with ESP32')

CANDIDATE · PULL REQUEST

Introduce non-blocking scan for access points for ESP32

closedby marcidyopened 2021-07-10updated 2021-07-11

Scan for APs in the background and retrieve ap records with a new function call.

scan run without any arguments, or as scan(True) is backwards compatible and returns a list of AP records.

scan(False) runs a non-blocking scan, taking advantage of the blocking argument to esp_wifi_scan_start.

When the scan is complete, the records are available by calling wlan.get_scan_results().

When running a non-blocking scan, the results are stored in the wifi driver's dynamic memory. A call to esp_wifi_scan_get_ap_records is requires to free that memory.

While testing, i noticed that other calls to the driver (e.g. connect, activate, etc). interrupt the scan and emit a SYSTEM_EVENT_SCAN_DONE event. These appear to clear out the memory also, meaning no records are retrieved. I didn't add any extra behavior to free the driver's memory as the IDF seems to handle it as long as the driver's state is changed. e.g., the records don't hang around in memory if a connect is run after a scan, but before a call to esp_wifi_scan_get_ap_records.

wlan.get_scan_results has 2 behaviors:

  • If no SCAN_DONE event is emitted, it returns None. Either a scan is in progress or no scan was attempted.
  • If a SCAN_DONE event occurred, it will return a (possibly empty) list of records once

I added a check against the record size as there are cases when a SCAN_DONE event is emitted but there are zero records returned, specifically when a scan was interrupted.

I didn't add anything to esp_state for scanning / scan_done since it wasn't strictly necessary, as the driver manages it's memory correctly imo. If the user want's to check if there are scan results, just call wlan.get_scan_results().

to test:

>>> import network
>>> wlan = network.WLAN(network.STA_IF)
>>> wlan.scan()
# list of APs as before
>>> wlan.scan(False)
>>> wlan.get_scan_results()
>>>
# scan finished
>>> wlan.get_scan_results()
# list of APs

To trigger edge cases:

>>> wlan.scan(False)
>>> wlan.connect('ssid', 'pass')
>>> wlan.get_scan_results()

Keyboard

j / / n
next pair
k / / p
previous pair
1 / / h
show query pane
2 / / l
show candidate pane
c
copy suggested comment
r
toggle reasoning
g i
go to index
?
show this help
esc
close overlays

press ? or esc to close

copied