[Wi-Fi scanning] esp_wifi_scan_get_ap_records() crashing with fixed array
Posted: Fri Apr 27, 2018 5:47 pm
Hi, I'm scanning for AP's nearby using the esp_wifi_scan_start() function.
However the program crashes when I call esp_wifi_scan_get_ap_records(&size, list);
If I perform a malloc to get a pointer and pass it to esp_wifi_scan_get_ap_records(), it works.
But in my application, memory fragmentation is a serious issue and I'd like to avoid that at all cost.
What is a better way to do this?
Many thanks.
Code: Select all
static esp_err_t __wifi_event_handler(void *ctx, system_event_t *event) {
switch (event->event_id) {
:
:
case SYSTEM_EVENT_SCAN_DONE: {
{
ESP_LOGI(TAG, "[%s] SYSTEM_EVENT_SCAN_DONE", __func__);
uint16_t apCount = 0;
esp_wifi_scan_get_ap_num(&apCount);
printf("Number of access points found: %d (apCount = %d)\n", event->event_info.scan_done.number,
apCount);
wifi_ap_record_t list[40];
uint16_t size = sizeof(t);
esp_wifi_scan_get_ap_records(&size, list); // <<<--------------- CRASHES HERE
for (uint16_t i = 0; i < size; i++) {
wifi_ap_record_t *ap = list + i;
char *ssid = (char *) ap->ssid;
char ap_str[20] = {0};
sprintf(ap_str, "%d,%s", ap->rssi,
ap->authmode == WIFI_AUTH_OPEN ? "open" :
ap->authmode == WIFI_AUTH_WEP ? "wep" :
ap->authmode == WIFI_AUTH_WPA_PSK ? "wpa-psk" :
ap->authmode == WIFI_AUTH_WPA2_PSK ? "wpa-psk" :
ap->authmode == WIFI_AUTH_WPA_WPA2_PSK ? "wpa-wpa2-psk" :
ap->authmode == WIFI_AUTH_WPA2_ENTERPRISE ? "wpa-eap" :
"unknown"
);
printf("#%d/%d | %s: %s\n", i, apCount, ssid, ap_str);
}
}
}
default:
break;
}
return ESP_OK;
}
If I perform a malloc to get a pointer and pass it to esp_wifi_scan_get_ap_records(), it works.
But in my application, memory fragmentation is a serious issue and I'd like to avoid that at all cost.
What is a better way to do this?
Many thanks.