Skip to content

Commit ecc217c

Browse files
committed
add limit for returning the first 12 access points with highest rssi
1 parent 1169821 commit ecc217c

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

Diff for: libraries/WiFiS3/src/WiFi.cpp

+23-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#include "WiFi.h"
22

3+
#define SSID_MAX_COUNT 12
4+
35
using namespace std;
46

57
/* -------------------------------------------------------------------------- */
@@ -265,7 +267,7 @@ int8_t CWifi::scanNetworks() {
265267

266268
vector<string> aps;
267269
if(modem.write(string(PROMPT(_WIFISCAN)),res,CMD(_WIFISCAN))) {
268-
270+
269271
split(aps, res, string("\r\n"));
270272
for(uint16_t i = 0; i < aps.size(); i++) {
271273
CAccessPoint ap;
@@ -278,7 +280,26 @@ int8_t CWifi::scanNetworks() {
278280
ap.rssi = tokens[2];
279281
ap.channel = tokens[3];
280282
ap.encryption_mode = tokens[4];
281-
access_points.push_back(ap);
283+
284+
if(access_points.size() == 0) {
285+
access_points.push_back(ap);
286+
}
287+
else {
288+
if(RSSI(access_points.size()-1) < atoi(ap.rssi.c_str())) {
289+
if(access_points.size() < SSID_MAX_COUNT){
290+
std::vector<CAccessPoint>::reverse_iterator rit = access_points.rbegin();
291+
access_points.insert(rit.base(), ap);
292+
}
293+
else {
294+
access_points.pop_back();
295+
access_points.push_back(ap);
296+
}
297+
}else{
298+
if(access_points.size() < SSID_MAX_COUNT){
299+
access_points.push_back(ap);
300+
}
301+
}
302+
}
282303
}
283304
}
284305
}

0 commit comments

Comments
 (0)