8000 esp32/network_wlan: Don't raise exception when scan returns no results. · DucRP/micropython@ccaf197 · GitHub
[go: up one dir, main page]

Skip to content

Commit ccaf197

Browse files
committed
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>
1 parent dd77dbd commit ccaf197

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

ports/esp32/network_wlan.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,12 @@ STATIC mp_obj_t network_wlan_scan(mp_obj_t self_in) {
345345
if (status == 0) {
346346
uint16_t count = 0;
347347
esp_exceptions(esp_wifi_scan_get_ap_num(&count));
348+
if (count == 0) {
349+
// esp_wifi_scan_get_ap_records must be called to free internal buffers from the scan.
350+
// But it returns an error if wifi_ap_records==NULL. So allocate at least 1 AP entry.
351+
// esp_wifi_scan_get_ap_records will then return the actual number of APs in count.
352+
count = 1;
353+
}
348354
wifi_ap_record_t *wifi_ap_records = calloc(count, sizeof(wifi_ap_record_t));
349355
esp_exceptions(esp_wifi_scan_get_ap_records(&count, wifi_ap_records));
350356
for (uint16_t i = 0; i < count; i++) {

0 commit comments

Comments
 (0)
0