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

Connect to strongest network signal where duplicate AP's exist. #1707

Open
andrewmunro opened this issue Feb 4, 2024 · 0 comments
Open

Connect to strongest network signal where duplicate AP's exist. #1707

andrewmunro opened this issue Feb 4, 2024 · 0 comments

Comments

@andrewmunro
Copy link

andrewmunro commented Feb 4, 2024

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...

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