summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorScott Shawcroft <scott@adafruit.com>2020-12-28 11:49:41 -0800
committerGitHub <noreply@github.com>2020-12-28 11:49:41 -0800
commitc3396e4b4938d28a4dcbe32b59df35826cb181aa (patch)
tree2cf38ce5a4dc7c8bc1be2936e034392fe4000ef7
parent171efd55e0447b19c9ae734116068cd24db5e78f (diff)
parent64bb055700d425617adff7748890354d925248fd (diff)
Merge pull request #3868 from BennyE/wifi-enhancement-countrycode
esp32-s2: wifi enhancement to include countrycode
-rw-r--r--ports/esp32s2/common-hal/wifi/Network.c6
-rw-r--r--ports/esp32s2/common-hal/wifi/Radio.c11
-rw-r--r--shared-bindings/wifi/Network.c17
-rw-r--r--shared-bindings/wifi/Network.h1
-rw-r--r--shared-bindings/wifi/Radio.c2
5 files changed, 36 insertions, 1 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);
}
diff --git a/shared-bindings/wifi/Network.c b/shared-bindings/wifi/Network.c
index bf970a9c0..009712ad1 100644
--- a/shared-bindings/wifi/Network.c
+++ b/shared-bindings/wifi/Network.c
@@ -108,12 +108,29 @@ const mp_obj_property_t wifi_network_channel_obj = {
(mp_obj_t)&mp_const_none_obj },
};
+//| country: str
+//| """String id of the country code"""
+//|
+STATIC mp_obj_t wifi_network_get_country(mp_obj_t self) {
+ return common_hal_wifi_network_get_country(self);
+
+}
+MP_DEFINE_CONST_FUN_OBJ_1(wifi_network_get_country_obj, wifi_network_get_country);
+
+const mp_obj_property_t wifi_network_country_obj = {
+ .base.type = &mp_type_property,
+ .proxy = { (mp_obj_t)&wifi_network_get_country_obj,
+ (mp_obj_t)&mp_const_none_obj,
+ (mp_obj_t)&mp_const_none_obj },
+};
+
STATIC const mp_rom_map_elem_t wifi_network_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_ssid), MP_ROM_PTR(&wifi_network_ssid_obj) },
{ MP_ROM_QSTR(MP_QSTR_bssid), MP_ROM_PTR(&wifi_network_bssid_obj) },
{ MP_ROM_QSTR(MP_QSTR_rssi), MP_ROM_PTR(&wifi_network_rssi_obj) },
{ MP_ROM_QSTR(MP_QSTR_channel), MP_ROM_PTR(&wifi_network_channel_obj) },
+ { MP_ROM_QSTR(MP_QSTR_country), MP_ROM_PTR(&wifi_network_country_obj) },
};
STATIC MP_DEFINE_CONST_DICT(wifi_network_locals_dict, wifi_network_locals_dict_table);
diff --git a/shared-bindings/wifi/Network.h b/shared-bindings/wifi/Network.h
index c9bbc685e..e672e3108 100644
--- a/shared-bindings/wifi/Network.h
+++ b/shared-bindings/wifi/Network.h
@@ -39,5 +39,6 @@ extern mp_obj_t common_hal_wifi_network_get_ssid(wifi_network_obj_t *self);
extern mp_obj_t common_hal_wifi_network_get_bssid(wifi_network_obj_t *self);
extern mp_obj_t common_hal_wifi_network_get_rssi(wifi_network_obj_t *self);
extern mp_obj_t common_hal_wifi_network_get_channel(wifi_network_obj_t *self);
+extern mp_obj_t common_hal_wifi_network_get_country(wifi_network_obj_t *self);
#endif // MICROPY_INCLUDED_SHARED_BINDINGS_WIFI_NETWORK_H
diff --git a/shared-bindings/wifi/Radio.c b/shared-bindings/wifi/Radio.c
index edbd9fd2f..723572a32 100644
--- a/shared-bindings/wifi/Radio.c
+++ b/shared-bindings/wifi/Radio.c
@@ -295,7 +295,7 @@ const mp_obj_property_t wifi_radio_ipv4_dns_obj = {
};
//| ap_info: Optional[Network]
-//| """Network object containing BSSID, SSID, channel, and RSSI when connected to an access point. None otherwise."""
+//| """Network object containing BSSID, SSID, channel, country and RSSI when connected to an access point. None otherwise."""
//|
STATIC mp_obj_t wifi_radio_get_ap_info(mp_obj_t self) {
return common_hal_wifi_radio_get_ap_info(self);