@@ -160,14 +160,9 @@ void menuFirmware()
160
160
161
161
else if ((incoming == ' u' ) && newOTAFirmwareAvailable)
162
162
{
163
- bool previouslyConnected = wifiIsConnected ();
164
-
165
- otaUpdate ();
163
+ otaUpdate (); // otaUpdate will call wifiConnect if needed. Also does previouslyConnected check
166
164
167
165
// We get here if WiFi failed or the server was not available
168
-
169
- if (previouslyConnected == false )
170
- WIFI_STOP ();
171
166
}
172
167
173
168
else if (incoming == ' x' )
@@ -476,7 +471,9 @@ bool otaCheckVersion(char *versionAvailable, uint8_t versionAvailableLength)
476
471
#ifdef COMPILE_WIFI
477
472
bool previouslyConnected = wifiIsConnected ();
478
473
479
- if (wifiConnect (10000 ) == true )
474
+ bool wasInAPmode;
475
+
476
+ if (wifiConnect (10000 , true , &wasInAPmode) == true ) // Use WIFI_AP_STA if already in WIFI_AP mode
480
477
{
481
478
char versionString[21 ];
482
479
getFirmwareVersion (versionString, sizeof (versionString), enableRCFirmware);
@@ -512,6 +509,11 @@ bool otaCheckVersion(char *versionAvailable, uint8_t versionAvailableLength)
512
509
systemPrintln (" WiFi not available." );
513
510
}
514
511
512
+ // If we were in WIFI_AP mode, return to WIFI_AP mode
513
+ // There may be some overlap with systemState STATE_WIFI_CONFIG ? Not sure...
514
+ if (wasInAPmode)
515
+ WiFi.mode (WIFI_AP);
516
+
515
517
if (systemState != STATE_WIFI_CONFIG)
516
518
{
517
519
// WIFI_STOP() turns off the entire radio including the webserver. We need to turn off Station mode only.
@@ -573,9 +575,15 @@ void otaUpdate()
573
575
#ifdef COMPILE_WIFI
574
576
bool previouslyConnected = wifiIsConnected ();
575
577
576
- if (wifiConnect (10000 ) == true )
578
+ bool wasInAPmode;
579
+
580
+ if (wifiConnect (10000 , true , &wasInAPmode) == true ) // Use WIFI_AP_STA if already in WIFI_AP mode
577
581
overTheAirUpdate ();
578
582
583
+ // Update failed. If we were in WIFI_AP mode, return to WIFI_AP mode
584
+ if (wasInAPmode)
585
+ WiFi.mode (WIFI_AP);
586
+
579
587
// Update failed. If WiFi was originally off, turn it off again
580
588
if (previouslyConnected == false )
581
589
WIFI_STOP ();
0 commit comments