Skip to content

Commit

Permalink
esp32/network_wlan: Don't raise exception when scan returns no results.
Browse files Browse the repository at this point in the history
Prior to this commit, running scan() without any APs available would give:

    >>> wl.scan()
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    RuntimeError: Wifi Unknown Error 0x0102

Signed-off-by: Damien George <damien@micropython.org>
  • Loading branch information
dpgeorge committed Jun 28, 2022
1 parent dd77dbd commit ccaf197
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions ports/esp32/network_wlan.c
Expand Up @@ -345,6 +345,12 @@ STATIC mp_obj_t network_wlan_scan(mp_obj_t self_in) {
if (status == 0) {
uint16_t count = 0;
esp_exceptions(esp_wifi_scan_get_ap_num(&count));
if (count == 0) {
// esp_wifi_scan_get_ap_records must be called to free internal buffers from the scan.
// But it returns an error if wifi_ap_records==NULL. So allocate at least 1 AP entry.
// esp_wifi_scan_get_ap_records will then return the actual number of APs in count.
count = 1;
}
wifi_ap_record_t *wifi_ap_records = calloc(count, sizeof(wifi_ap_record_t));
esp_exceptions(esp_wifi_scan_get_ap_records(&count, wifi_ap_records));
for (uint16_t i = 0; i < count; i++) {
Expand Down

0 comments on commit ccaf197

Please sign in to comment.