@@ -129,10 +129,13 @@ void wifiSetState(byte newState)
129129
130130// Start the access point for user to connect to and configure device
131131// We can also start as a WiFi station and attempt to connect to local WiFi for config
132- void wifiStartAP ()
132+ bool wifiStartAP ()
133133{
134134 if (settings.wifiConfigOverAP == true )
135135 {
136+ // Stop any current WiFi activity
137+ wifiStop ();
138+
136139 // Start in AP mode
137140 WiFi.mode (WIFI_AP);
138141
@@ -148,7 +151,7 @@ void wifiStartAP()
148151 if (WiFi.softAP (" RTK Config" ) == false ) // Must be short enough to fit OLED Width
149152 {
150153 systemPrintln (" WiFi AP failed to start" );
151- return ;
154+ return ( false ) ;
152155 }
153156 systemPrint (" WiFi AP Started with IP: " );
154157 systemPrintln (WiFi.softAPIP ());
@@ -158,9 +161,11 @@ void wifiStartAP()
158161 // Start webserver on local WiFi instead of AP
159162 wifiStart (); // Makes sure any ESP-Now settings have been cleared
160163
161- // Attempt to connect to local WiFi 3 times with increasing timeouts
164+ // Attempt to connect to local WiFi with increasing timeouts
162165 int timeout = 0 ;
163- for (int x = 0 ; x < 3 ; x++)
166+ int x = 0 ;
167+ const int maxTries = 2 ;
168+ for ( ; x < maxTries ; x++)
164169 {
165170 timeout += 5000 ;
166171 if (wifiConnect (timeout) == true ) // Attempt to connect to any SSID on settings list
@@ -169,7 +174,15 @@ void wifiStartAP()
169174 break ;
170175 }
171176 }
177+ if (x == maxTries)
178+ {
179+ displayNoWiFi (2000 );
180+ requestChangeState (STATE_ROVER_NOT_STARTED);
181+ return (false );
182+ }
172183 }
184+
185+ return (true );
173186}
174187
175188#endif // COMPILE_WIFI
@@ -227,7 +240,7 @@ void wifiUpdate()
227240 else
228241 {
229242 systemPrintln (" WiFi connection failed. Giving up." );
230- // paintWiFiFail(4000, true); //TODO
243+ displayNoWiFi ( 2000 );
231244 wifiStop (); // Move back to WIFI_OFF
232245 }
233246 }
@@ -420,7 +433,7 @@ bool wifiIsNeeded()
420433
421434 // If WiFi is on while we are in the following states, allow WiFi to continue to operate
422435 if (systemState >= STATE_BUBBLE_LEVEL && systemState <= STATE_PROFILE)
423- {
436+ {
424437 // Keep WiFi on if user presses setup button, enters bubble level, is in AP config mode, etc
425438 needed = true ;
426439 }
0 commit comments