Skip to content

Support Regarding ESP32 Wi-Fi Connection Stability and Scanning Behavior #10979

@akhilkalariya0

Description

@akhilkalariya0

Board

ESP32-S3-WROOM-1-N16R8

Device Description

ESP32-S3-WROOM-1-N16R8 Module on Custom Board PCB.

Hardware Configuration

UART on IO18 and IO5 to communicate with other mcu (STM32).

Version

latest master (checkout manually)

IDE Name

Platform IO

Operating System

Windows 11

Flash frequency

40Mhz

PSRAM enabled

yes

Upload speed

115200

Description

Hello,

I am currently using the ESP32 module in an environment where most surrounding structures are made of metal. The ESP32 is connected to a Wi-Fi network, but I have observed frequent connection failures. To handle this, I am using WiFi.scanNetworks(false, false, true); to continuously scan for networks and reconnect when available.

Despite implementing this approach, I am still experiencing occasional failures in network detection and reconnection. Specifically:

The ESP32 does not always detect the network even when it is available.
The scanning process sometimes takes longer than expected or fails to find any networks.
I would like to understand:

Is there a recommended best practice for handling Wi-Fi reconnections more reliably?
Are there any known issues with scanNetworks(false, false, true); that could cause inconsistent results?
Would enabling/disabling Wi-Fi or restarting the ESP32 improve reliability?
Are there firmware updates or alternative solutions that can enhance Wi-Fi stability?
I appreciate your guidance on this matter, as stable network connectivity is critical for my application. Please let me know if additional information is needed.

Sketch

bool network_scanning_process() {
    station_mode.disconnect();
    int numNetworks = station_mode.scanNetworks(false, false, true);
    Serial.printf("Found %d networks\n", numNetworks);

    if (numNetworks == -2) {
        wifi_update_debug_println("WiFi scan failed: WiFi driver not initialized.");
        reinitializeWiFi();
    }

    for (int j = 0; j < numNetworks; j++) {
        String ssid = station_mode.SSID(j);

        for(uint8_t i = 0; i < MAX_SSID_HOLD; i++){
            if (!strcmp(local_ssid[i], ssid.c_str())) {
                Serial.printf("Network %d: %s (RSSI: %d)\n", i + 1, ssid.c_str(), WiFi.RSSI(i));
                wifi_update_debug_println("Target network found! Connecting...");
                connectToTargetNetwork(local_ssid[i], local_pwd[i]);
            }
        }
    }

    if(WL_CONNECTED == station_mode.status()) {
        return 1;
    }
    else {
        live_time_updated = 0;
        return 0;
    }
}

Debug Message

NA

Other Steps to Reproduce

Random Issue

I have checked existing issues, online documentation and the Troubleshooting Guide

  • I confirm I have checked existing issues, online documentation and Troubleshooting guide.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions