Wifi scan while connected to an AP
-
- Posts: 8
- Joined: Wed Sep 25, 2019 8:31 pm
Wifi scan while connected to an AP
I'm dealing with an application where I have to scan to search for some devices while the esp is connected to an AP, but when I try to do this, the function esp_wifi_scan_get_ap_num return 0, and the function esp_wifi_scan_get_ap_records do not put devices in the structure. Isn't possible to realize a scan while I'm connected to an AP? I'm using idf 4.0.4
Re: Wifi scan while connected to an AP
Have you also called esp_wifi_scan_start before esp_wifi_scan_get_ap_num? If yes, could you check the return code of esp_wifi_scan_start?
-
- Posts: 8
- Joined: Wed Sep 25, 2019 8:31 pm
Re: Wifi scan while connected to an AP
Yes, I called esp_wifi_scan_start before, it's returning 0.
Re: Wifi scan while connected to an AP
The same here.
If I try to perform AP scan while in STA mode and already connected to an AP, the esp_wifi_scan_get_ap_num() returns 0.
This is a snippet of my code
When the device is in APSTA mode it works correctly.
I'm developing on eSP32-S3-DevKitC, using esp-idf v4.4.2 on Linux.
If I try to perform AP scan while in STA mode and already connected to an AP, the esp_wifi_scan_get_ap_num() returns 0.
This is a snippet of my code
Code: Select all
// blocking scan
err_code = esp_wifi_scan_start(NULL, true);
if (err_code != ESP_OK)
{
LOGE("esp_wifi_scan_start() failed, error: %d", err_code);
goto _exit;
}
// scan done
uint16_t ap_count = 0;
err_code = esp_wifi_scan_get_ap_num(&ap_count);
if (err_code != ESP_OK)
{
LOGE("esp_wifi_scan_get_ap_num() failed, error: %d", err_code);
goto _exit;
}
if (ap_count > 0)
{
ap_list = (wifi_ap_record_t *)malloc(ap_count * sizeof(wifi_ap_record_t));
if (ap_list == NULL)
{
goto _exit;
}
memset(ap_list, 0, ap_count * sizeof(wifi_ap_record_t));
err_code = esp_wifi_scan_get_ap_records(&ap_count, ap_list);
if (err_code != ESP_OK)
{
LOGE("esp_wifi_scan_get_ap_records() failed, error: %d", err_code);
goto _exit;
}
for (int i = 0; i < ap_count; i++)
{
// force last character of country code
ap_list[i].country.cc[2] = '\0';
LOGI("%d - %s [%d] (%d) %s", i, ap_list[i].ssid, ap_list[i].primary, ap_list[i].rssi, ap_list[i].country.cc);
}
}
I'm developing on eSP32-S3-DevKitC, using esp-idf v4.4.2 on Linux.
Re: Wifi scan while connected to an AP
I understand which was my problem.
Reading the wifi documentation I have found this:
Reading the wifi documentation I have found this:
Since I also have an event handler in which I was processing the ap_records, the internal ap_records list was freed when I read it inside the event handler, and when I try to read it after the blocking scan it was empty.the found APs are stored in WiFi driver dynamic allocated memory and they will be
freed in esp_wifi_scan_get_ap_records, so generally, call esp_wifi_scan_get_ap_records
to cause the memory to be freed once the scan is done
Who is online
Users browsing this forum: Bing [Bot] and 100 guests