wifi scan 定时扫描多次后wifi列表变成空列表

illusion
Posts: 2
Joined: Mon Jan 16, 2023 3:29 pm

wifi scan 定时扫描多次后wifi列表变成空列表

Postby illusion » Tue Jan 17, 2023 9:15 am

如标题,环境为idf V4.4.1,参考wifi的scan例程。我目的是创建一个任务定时扫描wifi获取四个参考节点(ESP_AP)的rssi值,wifi模式为ap/sta共存模式,wifi扫描通道为7,相关配置参数如下:
wifi_scan_config_t scan_config = {
.ssid = NULL,
.bssid = NULL,
.channel = 7,
.show_hidden = false,
.scan_type = WIFI_SCAN_TYPE_ACTIVE
};
然后用任务循环以下代码:
esp_wifi_scan_start(&scan_config, false);
vTaskDelay(200 / portTICK_PERIOD_MS);
ESP_ERROR_CHECK(esp_wifi_scan_get_ap_records(&number, ap_info));
ESP_ERROR_CHECK(esp_wifi_scan_get_ap_num(&ap_count));
ESP_LOGI(TAG, "Total APs scanned = %u", ap_count);
for (int i = 0; (i < DEFAULT_SCAN_LIST_SIZE) && (i < ap_count); i++) {
ESP_LOGI(TAG, "SSID \t\t%s", ap_info.ssid);
ESP_LOGI(TAG, "RSSI \t\t%d", ap_info.rssi);
ESP_LOGI(TAG, "Channel \t\t%d\n", ap_info.primary);
}
但在开发板esp32-wroom中运行时,有时正常,有时会多次扫描后的数据中变成了空的wifi列表,最终变成全空。那四个ESP_AP为我设置的非隐藏的wifi ap,却无法正常的获取到wifi信息。希望大佬们帮我看看,哪里出了问题。以下为我截取的三组wifi扫描串口数据:
[0;32mI (30607) esp_apsta: Total APs scanned = 4
[0;32mI (30607) esp_apsta: SSID ESP_AP1
[0;32mI (30607) esp_apsta: RSSI -65
[0;32mI (30607) esp_apsta: Channel 7
[0m
[0;32mI (30607) esp_apsta: SSID ESP_AP3
[0;32mI (30617) esp_apsta: RSSI -83
[0;32mI (30617) esp_apsta: Channel 7
[0m
[0;32mI (30617) esp_apsta: SSID ESP_AP4
[0;32mI (30627) esp_apsta: RSSI -88
[0;32mI (30627) esp_apsta: Channel 7
[0m
[0;32mI (30637) esp_apsta: SSID ESP_AP2
[0;32mI (30637) esp_apsta: RSSI -88
[0;32mI (30637) esp_apsta: Channel 7

[0;32mI (35607) esp_apsta: Total APs scanned = 4
[0;32mI (35607) esp_apsta: SSID ESP_AP1
[0;32mI (35607) esp_apsta: RSSI -67
[0;32mI (35607) esp_apsta: Channel 7
[0m
[0;32mI (35607) esp_apsta: SSID ESP_AP3
[0;32mI (35617) esp_apsta: RSSI -86
[0;32mI (35617) esp_apsta: Channel 7
[0m
[0;32mI (35617) esp_apsta: SSID ESP_AP4
[0;32mI (35627) esp_apsta: RSSI -90
[0;32mI (35627) esp_apsta: Channel 7
[0m
[0;32mI (35637) esp_apsta: SSID
[0;32mI (35637) esp_apsta: RSSI 0
[0;32mI (35637) esp_apsta: Channel 0

[0;32mI (204597) esp_apsta: Total APs scanned = 6
[0;32mI (204597) esp_apsta: SSID ESP_AP1
[0;32mI (204597) esp_apsta: RSSI -62
[0;32mI (204597) esp_apsta: Channel 7
[0m
[0;32mI (204597) esp_apsta: SSID ESP_AP3
[0;32mI (204607) esp_apsta: RSSI -85
[0;32mI (204607) esp_apsta: Channel 7
[0m
[0;32mI (204607) esp_apsta: SSID
[0;32mI (204617) esp_apsta: RSSI 0
[0;32mI (204617) esp_apsta: Channel 0
[0m
[0;32mI (204627) esp_apsta: SSID
[0;32mI (204627) esp_apsta: RSSI 0
[0;32mI (204627) esp_apsta: Channel 0
[0m
[0;32mI (204637) esp_apsta: SSID
[0;32mI (204637) esp_apsta: RSSI 0
[0;32mI (204637) esp_apsta: Channel 0
[0m
[0;32mI (204647) esp_apsta: SSID
[0;32mI (204647) esp_apsta: RSSI 0
[0;32mI (204657) esp_apsta: Channel 0

illusion
Posts: 2
Joined: Mon Jan 16, 2023 3:29 pm

Re: wifi scan 定时扫描多次后wifi列表变成空列表

Postby illusion » Thu Jan 19, 2023 2:35 pm

已解决,ap列表改成用链表分配内存保存
wifi_ap_record_t *ap_info = (wifi_ap_record_t *)malloc(sizeof(wifi_ap_record_t) * ap_count);
wifi列表终于不再为空

Who is online

Users browsing this forum: No registered users and 91 guests