@@ -38,6 +38,10 @@ bool ESP8266WiFiMulti::addAP(const char* ssid, const char *passphrase) {
38
38
return APlistAdd (ssid, passphrase);
39
39
}
40
40
41
+ bool ESP8266WiFiMulti::existsAP (const char * ssid, const char *passphrase) {
42
+ return APlistExists (ssid, passphrase);
43
+ }
44
+
41
45
wl_status_t ESP8266WiFiMulti::run (void ) {
42
46
43
47
wl_status_t status = WiFi.status ();
@@ -184,18 +188,23 @@ bool ESP8266WiFiMulti::APlistAdd(const char* ssid, const char *passphrase) {
184
188
WifiAPEntry newAP;
185
189
186
190
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 " );
189
193
return false ;
190
194
}
191
195
192
196
// for passphrase, max is 63 ascii + null. For psk, 64hex + null.
193
197
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 " );
196
200
return false ;
197
201
}
198
202
203
+ if (APlistExists (ssid, passphrase)) {
204
+ DEBUG_WIFI_MULTI (" [WIFI][APlistAdd] SSID: %s already exists\n " , ssid);
205
+ return true ;
206
+ }
207
+
199
208
newAP.ssid = strdup (ssid);
200
209
201
210
if (!newAP.ssid ) {
@@ -220,6 +229,28 @@ bool ESP8266WiFiMulti::APlistAdd(const char* ssid, const char *passphrase) {
220
229
return true ;
221
230
}
222
231
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
+
223
254
void ESP8266WiFiMulti::APlistClean (void ) {
224
255
for (auto entry : APlist) {
225
256
if (entry.ssid ) {
0 commit comments