mirror of
https://github.com/alexhopeoconnor/WiFiManager.git
synced 2026-10-13 14:51:21 +10:00
Merge pull request #124 from tablatronix/remove-duplicate-aps
Remove duplicate aps
This commit is contained in:
+30
-17
@@ -390,37 +390,50 @@ void WiFiManager::handleWifi(boolean scan) {
|
||||
DEBUG_WM(F("No networks found"));
|
||||
page += F("No networks found. Refresh to scan again.");
|
||||
} else {
|
||||
|
||||
//sort networks
|
||||
/*int indices[n];
|
||||
|
||||
for (int i = 0; i < n; i++) {
|
||||
indices[i] = i;
|
||||
}
|
||||
|
||||
for (int i = 0; i < n; i++) {
|
||||
for (int j = i + 1; j < n; j++) {
|
||||
if (WiFi.RSSI(indices[j]) > WiFi.RSSI(indices[i])) {
|
||||
//int temp = indices[j];
|
||||
//indices[j] = indices[i];
|
||||
//indices[i] = temp;
|
||||
std::swap(indices[i], indices[j]);
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
int indices[n];
|
||||
for (int i = 0; i < n; i++) {
|
||||
indices[i] = i;
|
||||
}
|
||||
|
||||
// RSSI SORT
|
||||
|
||||
// old sort
|
||||
// for (int i = 0; i < n; i++) {
|
||||
// for (int j = i + 1; j < n; j++) {
|
||||
// if (WiFi.RSSI(indices[j]) > WiFi.RSSI(indices[i])) {
|
||||
// //int temp = indices[j];
|
||||
// //indices[j] = indices[i];
|
||||
// //indices[i] = temp;
|
||||
// std::swap(indices[i], indices[j]);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
std::sort(indices, indices + n, [](const int & a, const int & b) -> bool
|
||||
{
|
||||
return WiFi.RSSI(a) > WiFi.RSSI(b);
|
||||
});
|
||||
|
||||
// remove duplicates ( must be RSSI sorted )
|
||||
if(_removeDupAps){
|
||||
String cssid;
|
||||
for (int i = 0; i < n; i++) {
|
||||
if(indices[i] == -1) continue;
|
||||
cssid = WiFi.SSID(indices[i]);
|
||||
for (int j = i + 1; j < n; j++) {
|
||||
if(cssid == WiFi.SSID(indices[j])){
|
||||
DEBUG_WM("DUP AP: " + WiFi.SSID(indices[j]));
|
||||
indices[j] = -1; // set dup aps to index -1
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//display networks in page
|
||||
for (int i = 0; i < n; i++) {
|
||||
if(indices[i] == -1) continue; // skip dups
|
||||
DEBUG_WM(WiFi.SSID(indices[i]));
|
||||
DEBUG_WM(WiFi.RSSI(indices[i]));
|
||||
int quality = getRSSIasQuality(WiFi.RSSI(indices[i]));
|
||||
|
||||
@@ -141,6 +141,7 @@ class WiFiManager
|
||||
|
||||
int _paramsCount = 0;
|
||||
int _minimumQuality = -1;
|
||||
boolean _removeDupAps = true;
|
||||
boolean _shouldBreakAfterConfig = false;
|
||||
boolean _tryWPS = false;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user