[GH-ISSUE #153] Connection not possible with a smartphone using the default channel 1 if other WiFi AP is using it #119

Closed
opened 2026-02-28 01:23:32 +03:00 by kerem · 1 comment
Owner

Originally created by @jjbubka on GitHub (Apr 14, 2016).
Original GitHub issue: https://github.com/tzapu/WiFiManager/issues/153

First of all, thank you for this awesome library.

I want to share with you one problem regardin the connection to the ESP with a smartphone. This is happening because of the collision of the WiFi signal (other APs in channel 1). I have a workaround to first scan the environment and selecting the first free channel (if possible). Of course this algorithm could be improved, but this works very good.

in WiFiManager::setupConfigPortal() I have changed:

WiFi.softAP(_apName.c_str(), _apPassword);

to this:

WiFi.softAP(_apName.c_str(), _apPassword, getFirstFreeChannel()); //modified to avoid WiFi collisions

where the function to select the channel is:

uint8_t WiFiManager::getFirstFreeChannel() {

    int n = WiFi.scanNetworks();
    if (n == 0)
        return 1;

    uint8_t channel = 0;
    bool used = true;

    while (used) {
        ++channel;
        used = false;
        for (int i = 0; i < n; i++) {
            if (WiFi.channel(i) == channel) {
                used = true;
                break;
            }
        }

        if (channel >= 11 && used)
            return 1;
    }

    return channel;

}
Originally created by @jjbubka on GitHub (Apr 14, 2016). Original GitHub issue: https://github.com/tzapu/WiFiManager/issues/153 First of all, thank you for this **awesome** library. I want to share with you one problem regardin the connection to the ESP with a smartphone. This is happening because of the collision of the WiFi signal (other APs in channel 1). I have a workaround to first scan the environment and selecting the first free channel (if possible). Of course this algorithm could be improved, but this works very good. in **WiFiManager::setupConfigPortal()** I have changed: `WiFi.softAP(_apName.c_str(), _apPassword);` to this: `WiFi.softAP(_apName.c_str(), _apPassword, getFirstFreeChannel()); //modified to avoid WiFi collisions` where the function to select the channel is: ``` uint8_t WiFiManager::getFirstFreeChannel() { int n = WiFi.scanNetworks(); if (n == 0) return 1; uint8_t channel = 0; bool used = true; while (used) { ++channel; used = false; for (int i = 0; i < n; i++) { if (WiFi.channel(i) == channel) { used = true; break; } } if (channel >= 11 && used) return 1; } return channel; } ```
kerem closed this issue 2026-02-28 01:23:32 +03:00
Author
Owner

@tzapu commented on GitHub (May 8, 2016):

hi, this is very very interesting, might explain why at some rare but random times, i can t manage to connect from some devices.

thanks for letting me know, will see about adding it

<!-- gh-comment-id:217699872 --> @tzapu commented on GitHub (May 8, 2016): hi, this is very very interesting, might explain why at some rare but random times, i can t manage to connect from some devices. thanks for letting me know, will see about adding it
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/WiFiManager#119
No description provided.