Skip to content

Commit 903f559

Browse files
committed
Remove single WiFi.begin()
If an area has multiple APs with identical SSIDs (common in office environments) WiFi.begin() will connect to the first it detects, not necessarily the strongest AP with that SSID. Using multiWifi is slower, but ensures that the network with the strongest RSSI is used.
1 parent 54f7633 commit 903f559

File tree

1 file changed

+8
-29
lines changed

1 file changed

+8
-29
lines changed

Firmware/RTK_Everywhere/WiFi.ino

Lines changed: 8 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -530,39 +530,18 @@ bool wifiConnect(unsigned long timeout)
530530

531531
int wifiResponse = WL_DISCONNECTED;
532532

533-
// WiFi.begin() is much faster than wifiMulti (requires scan time)
534-
// Use wifiMulti only if multiple credentials exist
535-
if (wifiNetworkCount() == 1)
536-
{
537-
systemPrint("Connecting WiFi");
533+
systemPrint("Connecting WiFi... ");
534+
WiFiMulti wifiMulti;
538535

539-
// Load SSID - may not be in spot 0
540-
for (int x = 0; x < MAX_WIFI_NETWORKS; x++)
541-
{
542-
if (strlen(settings.wifiNetworks[x].ssid) > 0)
543-
{
544-
WiFi.begin(settings.wifiNetworks[x].ssid, settings.wifiNetworks[x].password);
545-
break;
546-
}
547-
}
548-
549-
wifiResponse = WiFi.waitForConnectResult();
550-
}
551-
else
536+
// Load SSIDs
537+
for (int x = 0; x < MAX_WIFI_NETWORKS; x++)
552538
{
553-
systemPrint("Connecting WiFi... ");
554-
WiFiMulti wifiMulti;
555-
556-
// Load SSIDs
557-
for (int x = 0; x < MAX_WIFI_NETWORKS; x++)
558-
{
559-
if (strlen(settings.wifiNetworks[x].ssid) > 0)
560-
wifiMulti.addAP(settings.wifiNetworks[x].ssid, settings.wifiNetworks[x].password);
561-
}
562-
563-
wifiResponse = wifiMulti.run(timeout);
539+
if (strlen(settings.wifiNetworks[x].ssid) > 0)
540+
wifiMulti.addAP(settings.wifiNetworks[x].ssid, settings.wifiNetworks[x].password);
564541
}
565542

543+
wifiResponse = wifiMulti.run(timeout);
544+
566545
if (wifiResponse == WL_CONNECTED)
567546
{
568547
if (settings.enableTcpClient == true || settings.enableTcpServer == true || settings.enableUdpServer == true)

0 commit comments

Comments
 (0)