@@ -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+
4145wl_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+
223254void ESP8266WiFiMulti::APlistClean (void ) {
224255 for (auto entry : APlist) {
225256 if (entry.ssid ) {
0 commit comments