From 822e9ca8f3d2f63c7477bb7fb859b5d9ad948a3b Mon Sep 17 00:00:00 2001 From: Mark Date: Sat, 4 Jun 2016 16:43:32 +0100 Subject: [PATCH] esp8266/modnetwork: Use struct bss_info::ssid_len for ESSID length. Instead of calling strlen(), which won't work if there're 32 chars in returned ESSID. struct bss_info::ssid_len is not documented in SDK API Guide, but is present in SDK headers since 1.4.0. Just in case, previous code is left commented. --- esp8266/modnetwork.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/esp8266/modnetwork.c b/esp8266/modnetwork.c index c0763ce0eb..7cfa3ff77a 100644 --- a/esp8266/modnetwork.c +++ b/esp8266/modnetwork.c @@ -142,7 +142,13 @@ STATIC void esp_scan_cb(scaninfo *si, STATUS status) { struct bss_info *bs; STAILQ_FOREACH(bs, si->pbss, next) { mp_obj_tuple_t *t = mp_obj_new_tuple(6, NULL); + #if 1 + // struct bss_info::ssid_len is not documented in SDK API Guide, + // but is present in SDK headers since 1.4.0 + t->items[0] = mp_obj_new_bytes(bs->ssid, bs->ssid_len); + #else t->items[0] = mp_obj_new_bytes(bs->ssid, strlen((char*)bs->ssid)); + #endif t->items[1] = mp_obj_new_bytes(bs->bssid, sizeof(bs->bssid)); t->items[2] = MP_OBJ_NEW_SMALL_INT(bs->channel); t->items[3] = MP_OBJ_NEW_SMALL_INT(bs->rssi);