Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

network scanning does not find any networks on ESP32 #2905

Closed
pljakobs opened this issue Oct 30, 2024 · 2 comments
Closed

network scanning does not find any networks on ESP32 #2905

pljakobs opened this issue Oct 30, 2024 · 2 comments

Comments

@pljakobs
Copy link
Contributor

on arch Esp32, network scan does not return any networks.
Tested with Basic_WiFi, the result is ok for Esp8266 but 0 for Esp32 devices.
I have added some debug code

void StationImpl::staticScanCompleted(wifi_event_sta_scan_done_t* event, uint8_t status)
{
    BssList list;
    if(status == OK) {
        debug_i("Scan completed successfully");
        if(station.scanCompletedCallback) {
            uint16_t number = event->number;
            debug_i("Number of networks found: %u", number);
            wifi_ap_record_t ap_info[number];
            uint16_t ap_count{0};
            memset(ap_info, 0, sizeof(ap_info));
            esp_err_t err;

            err = esp_wifi_scan_get_ap_records(&number, ap_info);
            if (err != ESP_OK) {
                debug_e("Failed to get AP records: %s", esp_err_to_name(err));
            }

            err = esp_wifi_scan_get_ap_num(&ap_count);
            if (err != ESP_OK) {
                debug_e("Failed to get AP count: %s", esp_err_to_name(err));
            }

            debug_i("AP count: %u", ap_count);

            // TODO: Handle hidden APs
            for(unsigned i = 0; (i < event->number) && (i < ap_count); i++) {
                debug_i("AP %u: SSID: %s, RSSI: %d", i, ap_info[i].ssid, ap_info[i].rssi);
                list.addElement(new BssInfoImpl(&ap_info[i]));
            }
            station.scanCompletedCallback(true, list);
        } else {
            debug_w("No scanCompletedCallback set");
        }

        debug_i("scan completed: %u found", list.count());
    } else {
        debug_e("scan failed %u", status);
        if(station.scanCompletedCallback) {
            station.scanCompletedCallback(false, list);
        } else {
            debug_w("No scanCompletedCallback set");
        }
    }
}

the resulting output is

5903497 Scan completed successfully
5903530 Number of networks found: 4
5904023 AP count: 0
5904108 scan completed: 0 found

also, on the Esp32, the scan seems to run only once while on the 8266, it runs continuously.

@pljakobs
Copy link
Contributor Author

it seems that esp_wifi_scan_get_ap_num() returns 0 even though there are valid networks (and I suppose APs for them)

outputing the elements of ap_info[] show the expected five networks, but since ap_count is the number used to return valid networks, zero are being returned.

removing the loop condition ap_count results in the correct number of networks being returned

    for(unsigned i = 0; (i < event->number) && (i < ap_count); i++) {
    for(unsigned i = 0; (i < event->number); i++) {

I can't see, why esp_wifi_scan_get_ap_num() returns 0, though.

5900183 Scan completed successfully
5900212 Number of networks found: 5
5900707 AP count: 0
5900743 AP 0: SSID: UranusHertz, RSSI: -70
5900863 AP 1: SSID: IoT, RSSI: -70
5900899 AP 2: SSID: IoT1, RSSI: -72
5901293 AP 3: SSID: SDongleA-HV2280314807, RSSI: -77
5901876 AP 4: SSID: SUN2000-HV2280486954, RSSI: -91
	WiFi: UranusHertz, WPA2_PSK
	WiFi: IoT, WPA2_PSK
	WiFi: IoT1, WPA2_PSK
	WiFi: SDongleA-HV2280314807, WPA2_PSK
	WiFi: SUN2000-HV2280486954, WPA2_PSK
5904077 scan completed: 5 found

@pljakobs
Copy link
Contributor Author

the issue was that esp_wifi_scan_get_ap_records() clears the ap data and therefore, if esp_wifi_scan_ap_num() is called afterwards, it doesn't find any APs. Switching the order around, fixes the problem.

			ESP_ERROR_CHECK(esp_wifi_scan_get_ap_num(&ap_count));
			ESP_ERROR_CHECK(esp_wifi_scan_get_ap_records(&number, ap_info));

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant