[GH-ISSUE #1707] Connect to strongest network signal where duplicate AP's exist. #1448

Open
opened 2026-02-28 01:30:07 +03:00 by kerem · 0 comments
Owner

Originally created by @andrewmunro on GitHub (Feb 4, 2024).
Original GitHub issue: https://github.com/tzapu/WiFiManager/issues/1707

Heya,

I live in a house with terrible wifi signal, and so I have many APs setup with duplicate SSIDs. I've found that when using my ESP32, it seems to frequently connect to a distant AP despite being next to one, resulting in poor signal. I have to keep rebooting it until it finds the AP that is next to it...

I've found a person with a similar issue here. It looks like they solve it by doing a scan and supplying the bssid field to the WiFi.begin method, e.g:

String scanAndConnectToStrongestNetwork() {
  int i_strongest = -1;
  int32_t rssi_strongest = -100;
  Serial.printf("Start scanning for SSID %s\r\n", wifi_ssid);

  int n = WiFi.scanNetworks(); // WiFi.scanNetworks will return the number of networks found
  Serial.println("Scan done.");

  if (n == 0) {
    Serial.println("No networks found!");
    return ("");
  } else {
    Serial.printf("%d networks found:", n);
    for (int i = 0; i < n; ++i) {
      // Print SSID and RSSI for each network found
      Serial.printf("%d: BSSID: %s  %2ddBm, %3d%%  %9s  %s\r\n", i, WiFi.BSSIDstr(i).c_str(), WiFi.RSSI(i), constrain(2 * (WiFi.RSSI(i) + 100), 0, 100), (WiFi.encryptionType(i) == WIFI_AUTH_OPEN) ? "open" : "encrypted", WiFi.SSID(i).c_str());
      if ((String(wifi_ssid) == String(WiFi.SSID(i)) && (WiFi.RSSI(i)) > rssi_strongest)) {
        rssi_strongest = WiFi.RSSI(i);
        i_strongest = i;
      }
    }
  }

  if (i_strongest < 0) {
    Serial.printf("No network with SSID %s found!\r\n", wifi_ssid);
    return ("");
  }
  Serial.printf("SSID match found at %d. Connecting...\r\n", i_strongest);
  WiFi.begin(wifi_ssid, wifi_pass, 0, WiFi.BSSID(i_strongest));
  return (WiFi.BSSIDstr(i_strongest));
}

Could we add an option for this to the connection made in https://github.com/tzapu/WiFiManager/blob/master/WiFiManager.cpp#L1113? This is a really cool library and I'd love to continue using it, but I may have to just hard code the AP for now and implement something similar above...

Originally created by @andrewmunro on GitHub (Feb 4, 2024). Original GitHub issue: https://github.com/tzapu/WiFiManager/issues/1707 Heya, I live in a house with terrible wifi signal, and so I have many APs setup with duplicate SSIDs. I've found that when using my ESP32, it seems to frequently connect to a distant AP despite being next to one, resulting in poor signal. I have to keep rebooting it until it finds the AP that is next to it... I've found a person with a [similar issue here](https://www.esp32.com/viewtopic.php?f=19&t=18979&sid=eb327c882374ec3137f02f30f705a8d8&start=10#p113873). It looks like they solve it by doing a scan and supplying the `bssid` field to the `WiFi.begin` method, e.g: ```ino String scanAndConnectToStrongestNetwork() { int i_strongest = -1; int32_t rssi_strongest = -100; Serial.printf("Start scanning for SSID %s\r\n", wifi_ssid); int n = WiFi.scanNetworks(); // WiFi.scanNetworks will return the number of networks found Serial.println("Scan done."); if (n == 0) { Serial.println("No networks found!"); return (""); } else { Serial.printf("%d networks found:", n); for (int i = 0; i < n; ++i) { // Print SSID and RSSI for each network found Serial.printf("%d: BSSID: %s %2ddBm, %3d%% %9s %s\r\n", i, WiFi.BSSIDstr(i).c_str(), WiFi.RSSI(i), constrain(2 * (WiFi.RSSI(i) + 100), 0, 100), (WiFi.encryptionType(i) == WIFI_AUTH_OPEN) ? "open" : "encrypted", WiFi.SSID(i).c_str()); if ((String(wifi_ssid) == String(WiFi.SSID(i)) && (WiFi.RSSI(i)) > rssi_strongest)) { rssi_strongest = WiFi.RSSI(i); i_strongest = i; } } } if (i_strongest < 0) { Serial.printf("No network with SSID %s found!\r\n", wifi_ssid); return (""); } Serial.printf("SSID match found at %d. Connecting...\r\n", i_strongest); WiFi.begin(wifi_ssid, wifi_pass, 0, WiFi.BSSID(i_strongest)); return (WiFi.BSSIDstr(i_strongest)); } ``` Could we add an option for this to the connection made in https://github.com/tzapu/WiFiManager/blob/master/WiFiManager.cpp#L1113? This is a really cool library and I'd love to continue using it, but I may have to just hard code the AP for now and implement something similar above...
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#1448
No description provided.