diff options
| author | Scott Shawcroft <scott@adafruit.com> | 2020-12-28 11:49:41 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-12-28 11:49:41 -0800 |
| commit | c3396e4b4938d28a4dcbe32b59df35826cb181aa (patch) | |
| tree | 2cf38ce5a4dc7c8bc1be2936e034392fe4000ef7 /ports | |
| parent | 171efd55e0447b19c9ae734116068cd24db5e78f (diff) | |
| parent | 64bb055700d425617adff7748890354d925248fd (diff) | |
Merge pull request #3868 from BennyE/wifi-enhancement-countrycode
esp32-s2: wifi enhancement to include countrycode
Diffstat (limited to 'ports')
| -rw-r--r-- | ports/esp32s2/common-hal/wifi/Network.c | 6 | ||||
| -rw-r--r-- | ports/esp32s2/common-hal/wifi/Radio.c | 11 |
2 files changed, 17 insertions, 0 deletions
diff --git a/ports/esp32s2/common-hal/wifi/Network.c b/ports/esp32s2/common-hal/wifi/Network.c index e90b3d552..2674df065 100644 --- a/ports/esp32s2/common-hal/wifi/Network.c +++ b/ports/esp32s2/common-hal/wifi/Network.c @@ -48,3 +48,9 @@ mp_obj_t common_hal_wifi_network_get_rssi(wifi_network_obj_t *self) { mp_obj_t common_hal_wifi_network_get_channel(wifi_network_obj_t *self) { return mp_obj_new_int(self->record.primary); } + +mp_obj_t common_hal_wifi_network_get_country(wifi_network_obj_t *self) { + const char* cstr = (const char*) self->record.country.cc; + // 2 instead of strlen(cstr) as this gives us only the country-code + return mp_obj_new_str(cstr, 2); +} diff --git a/ports/esp32s2/common-hal/wifi/Radio.c b/ports/esp32s2/common-hal/wifi/Radio.c index 05506783e..3bc2258a4 100644 --- a/ports/esp32s2/common-hal/wifi/Radio.c +++ b/ports/esp32s2/common-hal/wifi/Radio.c @@ -198,6 +198,17 @@ mp_obj_t common_hal_wifi_radio_get_ap_info(wifi_radio_obj_t *self) { if (esp_wifi_sta_get_ap_info(&self->ap_info.record) != ESP_OK){ return mp_const_none; } else { + if (strlen(self->ap_info.record.country.cc) == 0) { + // Workaround to fill country related information in ap_info until ESP-IDF carries a fix + // esp_wifi_sta_get_ap_info does not appear to fill wifi_country_t (e.g. country.cc) details + // (IDFGH-4437) #6267 + // Note: It is possible that Wi-Fi APs don't have a CC set, then even after this workaround + // the element would remain empty. + memset(&self->ap_info.record.country, 0, sizeof(wifi_country_t)); + if (esp_wifi_get_country(&self->ap_info.record.country) != ESP_OK) { + return mp_const_none; + } + } memcpy(&ap_info->record, &self->ap_info.record, sizeof(wifi_ap_record_t)); return MP_OBJ_FROM_PTR(ap_info); } |
