66#include " Draw.h"
77
88#include < WiFi.h>
9+ #include < WiFiMulti.h>
910#include < WiFiUdp.h>
1011#include < AsyncTCP.h>
1112#include < ESPAsyncWebServer.h>
1415
1516#define CONNECT_TIME 3000 // Time of inactivity to start connecting WiFi
1617
18+ WiFiMulti wifiMulti;
19+
1720//
1821// Access Point (AP) mode settings
1922//
@@ -242,16 +245,18 @@ static bool wifiInitAP()
242245//
243246static bool wifiConnect ()
244247{
245- String status = " Connecting to WiFi network.." ;
246- wifi_mode_t mode = WiFi.getMode ();
248+ String status = " Connecting to WiFi network..." ;
249+
250+ // Clean credentials
251+ wifiMulti.APlistClean ();
247252
248253 // Get the preferences
249254 prefs.begin (" network" , true , STORAGE_PARTITION);
250255 loginUsername = prefs.getString (" loginusername" , " " );
251256 loginPassword = prefs.getString (" loginpassword" , " " );
252257
253258 // Try connecting to known WiFi networks
254- for (int j=0 ; (j<3 ) && (WiFi. status ()!=WL_CONNECTED) ; j++)
259+ for (int j=0 ; (j<3 ) ; j++)
255260 {
256261 char nameSSID[16 ], namePASS[16 ];
257262 sprintf (nameSSID, " wifissid%d" , j+1 );
@@ -261,34 +266,16 @@ static bool wifiConnect()
261266 String password = prefs.getString (namePASS, " " );
262267
263268 if (ssid != " " )
264- {
265- // Workaround for https://github.com/espressif/arduino-esp32/issues/11742
266- WiFi.mode (WIFI_MODE_NULL);
267- WiFi.mode (mode);
268-
269- WiFi.begin (ssid, password);
270- for (int j=0 ; (WiFi.status ()!=WL_CONNECTED) && (j<24 ) ; j++)
271- {
272- if (!(j&7 ))
273- {
274- status += " ." ;
275- drawScreen (status.c_str ());
276- }
277- delay (500 );
278- if (digitalRead (ENCODER_PUSH_BUTTON)==LOW)
279- {
280- WiFi.disconnect ();
281- break ;
282- }
283- }
284- }
269+ wifiMulti.addAP (ssid.c_str (), password.c_str ());
285270 }
286271
287272 // Done with preferences
288273 prefs.end ();
289274
275+ drawScreen (status.c_str ());
276+
290277 // If failed connecting to WiFi network...
291- if (WiFi. status ()!= WL_CONNECTED)
278+ if (wifiMulti. run () != WL_CONNECTED)
292279 {
293280 // WiFi connection failed
294281 drawScreen (status.c_str (), " No WiFi connection" );
0 commit comments