Skip to content

Commit dc75c8b

Browse files
authored
Merge branch 'master' into exceptions
2 parents e239a74 + 5fcb8f1 commit dc75c8b

File tree

3 files changed

+38
-4
lines changed

3 files changed

+38
-4
lines changed

libraries/ESP8266WiFi/keywords.txt

+1
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ softAPgetStationNum KEYWORD2
6969

7070
#ESP8266WiFiMulti
7171
addAP KEYWORD2
72+
existsAP KEYWORD2
7273
run KEYWORD2
7374

7475
#ESP8266WiFiScan

libraries/ESP8266WiFi/src/ESP8266WiFiMulti.cpp

+35-4
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ bool ESP8266WiFiMulti::addAP(const char* ssid, const char *passphrase) {
3838
return APlistAdd(ssid, passphrase);
3939
}
4040

41+
bool ESP8266WiFiMulti::existsAP(const char* ssid, const char *passphrase) {
42+
return APlistExists(ssid, passphrase);
43+
}
44+
4145
wl_status_t ESP8266WiFiMulti::run(void) {
4246

4347
wl_status_t status = WiFi.status();
@@ -184,18 +188,23 @@ bool ESP8266WiFiMulti::APlistAdd(const char* ssid, const char *passphrase) {
184188
WifiAPEntry newAP;
185189

186190
if(!ssid || *ssid == 0x00 || strlen(ssid) > 31) {
187-
// fail SSID to long or missing!
188-
DEBUG_WIFI_MULTI("[WIFI][APlistAdd] no ssid or ssid to long\n");
191+
// fail SSID too long or missing!
192+
DEBUG_WIFI_MULTI("[WIFI][APlistAdd] no ssid or ssid too long\n");
189193
return false;
190194
}
191195

192196
//for passphrase, max is 63 ascii + null. For psk, 64hex + null.
193197
if(passphrase && strlen(passphrase) > 64) {
194-
// fail passphrase to long!
195-
DEBUG_WIFI_MULTI("[WIFI][APlistAdd] passphrase to long\n");
198+
// fail passphrase too long!
199+
DEBUG_WIFI_MULTI("[WIFI][APlistAdd] passphrase too long\n");
196200
return false;
197201
}
198202

203+
if(APlistExists(ssid, passphrase)) {
204+
DEBUG_WIFI_MULTI("[WIFI][APlistAdd] SSID: %s already exists\n", ssid);
205+
return true;
206+
}
207+
199208
newAP.ssid = strdup(ssid);
200209

201210
if(!newAP.ssid) {
@@ -220,6 +229,28 @@ bool ESP8266WiFiMulti::APlistAdd(const char* ssid, const char *passphrase) {
220229
return true;
221230
}
222231

232+
bool ESP8266WiFiMulti::APlistExists(const char* ssid, const char *passphrase) {
233+
if(!ssid || *ssid == 0x00 || strlen(ssid) > 31) {
234+
// fail SSID too long or missing!
235+
DEBUG_WIFI_MULTI("[WIFI][APlistExists] no ssid or ssid too long\n");
236+
return false;
237+
}
238+
for(auto entry : APlist) {
239+
if(!strcmp(entry.ssid, ssid)) {
240+
if(!passphrase) {
241+
if(!strcmp(entry.passphrase, "")) {
242+
return true;
243+
}
244+
} else {
245+
if(!strcmp(entry.passphrase, passphrase)) {
246+
return true;
247+
}
248+
}
249+
}
250+
}
251+
return false;
252+
}
253+
223254
void ESP8266WiFiMulti::APlistClean(void) {
224255
for(auto entry : APlist) {
225256
if(entry.ssid) {

libraries/ESP8266WiFi/src/ESP8266WiFiMulti.h

+2
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,14 @@ class ESP8266WiFiMulti {
5353
~ESP8266WiFiMulti();
5454

5555
bool addAP(const char* ssid, const char *passphrase = NULL);
56+
bool existsAP(const char* ssid, const char *passphrase = NULL);
5657

5758
wl_status_t run(void);
5859

5960
private:
6061
WifiAPlist APlist;
6162
bool APlistAdd(const char* ssid, const char *passphrase = NULL);
63+
bool APlistExists(const char* ssid, const char *passphrase = NULL);
6264
void APlistClean(void);
6365

6466
};

0 commit comments

Comments
 (0)