diff options
| author | Damien George <damien@micropython.org> | 2022-06-28 13:15:10 +1000 |
|---|---|---|
| committer | Damien George <damien@micropython.org> | 2022-06-28 13:18:07 +1000 |
| commit | ccaf1978072a1d8e63b5e2ee350f15d875dfc1fd (patch) | |
| tree | db32a620337c2d7678d349138731c480814393c0 | |
| parent | dd77dbd4f72734da2b11ff52c553d636d1eee614 (diff) | |
esp32/network_wlan: Don't raise exception when scan returns no results.
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>
| -rw-r--r-- | ports/esp32/network_wlan.c | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/ports/esp32/network_wlan.c b/ports/esp32/network_wlan.c index 91099419e..48b398c8f 100644 --- a/ports/esp32/network_wlan.c +++ b/ports/esp32/network_wlan.c @@ -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++) { |
