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

WiFi.begin() should choose the nearest/strongest AP, not the first one found (which is default now) #4947

Merged
merged 1 commit into from
Mar 15, 2021

Conversation

BugerDread
Copy link
Contributor

In case you have multiple APs with the same SSID/password and WiFi.begin(ssid, pwd) is called, ESP32 defaults to connect to THE FIRST AP FOUND matching ssid - according to:
https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/network/esp_wifi.html#_CPPv418wifi_scan_method_t

This can cause situations that ESP32 is trying to connect to AP which is far away from it (weak signal) even there is AP close to it, just as in my house - I have AP on channel 6 which is in the 1st floor (quite far from room where I do the programming) and AP on channel 13 in the same room I do the programming (which is in the 2nd floor) - result: ESP32 is trying to connect to the AP on channel 6 because it finds it first and never try the AP on channel 13 in the same room, result of this is very unreliable WiFi connection.

When scan_method is set to WIFI_ALL_CHANNEL_SCAN, ESP32 scans all channels and choose the nearest / strongest AP (matching the ssid of course) as expected - result is no connection problems at all.

Therefore I propose adding this parameter into WiFi.begin, connection problems as described above are quite confusing (especially for beginners), I can imagine that for example Schools there are usually using mutliple APs and this can cause intermittent connection problems without obvious reason.

…gin() to let the scan choose the nearest / strongest AP in case that there are multiple APs with the same SSID
@BugerDread BugerDread changed the title added scan_method = WIFI_ALL_CHANNEL_SCAN into wifi config in WiFi.begin() WiFi.begin() should choose the nearest/strongest AP, not the first one found (which is default now) Mar 15, 2021
@BugerDread
Copy link
Contributor Author

one more note: tried also to switch AP on channel 13 to 11 to check that this is not caused by the fact that channel 13 is not allowed is some countries, but the result was exactly the same, ESP always connected to AP on channel 6

@me-no-dev me-no-dev merged commit 3253de8 into espressif:master Mar 15, 2021
@me-no-dev
Copy link
Member

thanks :)

tuniii added a commit to tuniii/arduino-esp32 that referenced this pull request Dec 7, 2021
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

Successfully merging this pull request may close these issues.

2 participants