Skip to content

Commit ae3b440

Browse files
committed
more fixes and still with debug
1 parent 2e393ed commit ae3b440

File tree

3 files changed

+45
-2
lines changed

3 files changed

+45
-2
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ 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-
return mp_obj_new_str(cstr, strlen(cstr));
54+
// We know that we only want the CC thus limiting to two chars
55+
return mp_obj_new_str(cstr, 2);
5556
}
5657

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

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,37 @@ mp_obj_t common_hal_wifi_radio_get_ap_info(wifi_radio_obj_t *self) {
198198
if (esp_wifi_sta_get_ap_info(&self->ap_info.record) != ESP_OK){
199199
return mp_const_none;
200200
} else {
201+
ESP_EARLY_LOGW(TAG, "country before handler country: %s", (char *)&self->ap_info.record.country);
202+
ESP_EARLY_LOGW(TAG, "country memory at: %p", self->ap_info.record.country);
203+
ESP_EARLY_LOGW(TAG, "countryCC memory at: %p", self->ap_info.record.country.cc);
204+
ESP_EARLY_LOGW(TAG, "countryCC strlen: %d", strlen(self->ap_info.record.country.cc));
205+
// The struct member appears to be <null> (not NULL!), I don't know how to properly test for it.
206+
// If the ESP-IDF starts working fine, this "if" wouldn't trigger.
207+
// Note: It is possible that Wi-Fi APs don't have a CC set, then even after this workaround
208+
// the element would remain empty.
209+
if (strlen(self->ap_info.record.country.cc) == 0) {
210+
// Workaround to fill country related information in ap_info until ESP-IDF carries a fix
211+
// esp_wifi_sta_get_ap_info does not appear to fill wifi_country_t (e.g. country.cc) details
212+
// (IDFGH-4437) #6267
213+
ESP_EARLY_LOGW(TAG, "Triggered missing country workaround");
214+
if (esp_wifi_get_country(&self->ap_info.record.country) == ESP_OK) {
215+
ESP_EARLY_LOGW(TAG, "Workaround worked fine!");
216+
ESP_EARLY_LOGW(TAG, "country: %d", self->ap_info.record.country);
217+
ESP_EARLY_LOGW(TAG, "CC: %s", self->ap_info.record.country.cc);
218+
} else {
219+
ESP_EARLY_LOGW(TAG, "Workaround failed!");
220+
}
221+
//} else {
222+
// ESP_EARLY_LOGW(TAG, "Triggered missing country workaround IN ELSE");
223+
// //memset(&self->ap_info.record.country, 0, sizeof(wifi_country_t));
224+
// if (esp_wifi_get_country(&self->ap_info.record.country) == ESP_OK) {
225+
// //if (esp_wifi_get_country(&self->ap_info.record.country) == ESP_OK) {
226+
// ESP_EARLY_LOGW(TAG, "Workaround worked fine!");
227+
// ESP_EARLY_LOGW(TAG, "CC: %s", self->ap_info.record.country.cc);
228+
// } else {
229+
// ESP_EARLY_LOGW(TAG, "Workaround failed!");
230+
// }
231+
}
201232
ESP_EARLY_LOGW(TAG, "ssid: %s", self->ap_info.record.ssid);
202233
ESP_EARLY_LOGW(TAG, "channel: %d", self->ap_info.record.primary);
203234
ESP_EARLY_LOGW(TAG, "secondary: %d", self->ap_info.record.second);
@@ -209,8 +240,13 @@ mp_obj_t common_hal_wifi_radio_get_ap_info(wifi_radio_obj_t *self) {
209240
ESP_EARLY_LOGW(TAG, "11g: %d", self->ap_info.record.phy_11g);
210241
ESP_EARLY_LOGW(TAG, "11n: %d", self->ap_info.record.phy_11n);
211242
ESP_EARLY_LOGW(TAG, "phy_lr: %d", self->ap_info.record.phy_lr);
212-
ESP_EARLY_LOGW(TAG, "country: %s", self->ap_info.record.country);
243+
ESP_EARLY_LOGW(TAG, "ap_info.record: %s", self->ap_info.record);
244+
ESP_EARLY_LOGW(TAG, "country with cast: %s", (char *)&self->ap_info.record.country);
245+
//ESP_EARLY_LOGW(TAG, "country: %s", self->ap_info.record.country);
246+
ESP_EARLY_LOGW(TAG, "country memory at: %p", self->ap_info.record.country);
213247
ESP_EARLY_LOGW(TAG, "countryCC: %s", self->ap_info.record.country.cc);
248+
ESP_EARLY_LOGW(TAG, "countryCC memory at: %p", self->ap_info.record.country.cc);
249+
ESP_EARLY_LOGW(TAG, "countryCC strlen: %d", strlen(self->ap_info.record.country.cc));
214250
memcpy(&ap_info->record, &self->ap_info.record, sizeof(wifi_ap_record_t));
215251
return MP_OBJ_FROM_PTR(ap_info);
216252
}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@
3939

4040
#include "components/esp_wifi/include/esp_wifi.h"
4141

42+
#include "components/log/include/esp_log.h"
43+
44+
static const char* TAG = "wifi";
45+
4246
static void wifi_scannednetworks_done(wifi_scannednetworks_obj_t *self) {
4347
self->done = true;
4448
if (self->results != NULL) {
@@ -117,6 +121,8 @@ mp_obj_t common_hal_wifi_scannednetworks_next(wifi_scannednetworks_obj_t *self)
117121

118122
wifi_network_obj_t *entry = m_new_obj(wifi_network_obj_t);
119123
entry->base.type = &wifi_network_type;
124+
// benny remove again
125+
ESP_EARLY_LOGW(TAG, "scan country: %s", &self->results[self->current_result].country);
120126
memcpy(&entry->record, &self->results[self->current_result], sizeof(wifi_ap_record_t));
121127
self->current_result++;
122128

0 commit comments

Comments
 (0)