Merge pull request #3868 from BennyE/wifi-enhancement-countrycode

esp32-s2: wifi enhancement to include countrycode
This commit is contained in:
Scott Shawcroft 2020-12-28 11:49:41 -08:00 committed by GitHub
commit c3396e4b49
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 36 additions and 1 deletions

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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);

View File

@ -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

View File

@ -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);