Skip to content

Commit 1a6b1b1

Browse files
committed
implementing suggested changes
1 parent e9c9fce commit 1a6b1b1

File tree

2 files changed

+8
-14
lines changed

2 files changed

+8
-14
lines changed

ports/esp32s2/common-hal/wifi/Network.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ mp_obj_t common_hal_wifi_network_get_channel(wifi_network_obj_t *self) {
5151

5252
mp_obj_t common_hal_wifi_network_get_country(wifi_network_obj_t *self) {
5353
const char* cstr = (const char*) self->record.country.cc;
54-
// We know that we only want the CC thus limiting to two chars
54+
// To address esp_wifi_get_country() returned/set wifi_country_t structure
55+
// doesn't follow the documented behaviour (IDFGH-4486) #6315
56+
// 2 instead of strlen(cstr) which would be 6 and contain full element
5557
return mp_obj_new_str(cstr, 2);
5658
}
57-

ports/esp32s2/common-hal/wifi/Radio.c

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,6 @@
4242

4343
#define MAC_ADDRESS_LENGTH 6
4444

45-
#include "components/log/include/esp_log.h"
46-
47-
static const char* TAG = "wifi";
48-
4945
static void start_station(wifi_radio_obj_t *self) {
5046
if (self->sta_mode) {
5147
return;
@@ -198,18 +194,15 @@ mp_obj_t common_hal_wifi_radio_get_ap_info(wifi_radio_obj_t *self) {
198194
if (esp_wifi_sta_get_ap_info(&self->ap_info.record) != ESP_OK){
199195
return mp_const_none;
200196
} else {
201-
// The struct member appears to be <null> (not NULL!), I don't know how to properly test for it.
202-
// When the ESP-IDF starts working fine (when their bugfix is available), this "if" wouldn't trigger.
203-
// Note: It is possible that Wi-Fi APs don't have a CC set, then even after this workaround
204-
// the element would remain empty.
205197
if (strlen(self->ap_info.record.country.cc) == 0) {
206198
// Workaround to fill country related information in ap_info until ESP-IDF carries a fix
207199
// esp_wifi_sta_get_ap_info does not appear to fill wifi_country_t (e.g. country.cc) details
208200
// (IDFGH-4437) #6267
209-
if (esp_wifi_get_country(&self->ap_info.record.country) == ESP_OK) {
210-
ESP_EARLY_LOGW(TAG, "Country Code: %s", self->ap_info.record.country.cc);
211-
} else {
212-
ESP_EARLY_LOGW(TAG, "Country Code - Workaround failed!");
201+
// Note: It is possible that Wi-Fi APs don't have a CC set, then even after this workaround
202+
// the element would remain empty.
203+
memset(&self->ap_info.record.country, 0, sizeof(wifi_country_t));
204+
if (esp_wifi_get_country(&self->ap_info.record.country) != ESP_OK) {
205+
return mp_const_none;
213206
}
214207
}
215208
memcpy(&ap_info->record, &self->ap_info.record, sizeof(wifi_ap_record_t));

0 commit comments

Comments
 (0)