@@ -11,8 +11,8 @@ menuFirmware.ino
11
11
#ifdef COMPILE_OTA_AUTO
12
12
13
13
static const char *const otaStateNames[] = {" OTA_STATE_OFF" ,
14
- " OTA_STATE_START_WIFI " ,
15
- " OTA_STATE_WAIT_FOR_WIFI " ,
14
+ " OTA_STATE_START_NETWORK " ,
15
+ " OTA_STATE_WAIT_FOR_NETWORK " ,
16
16
" OTA_STATE_GET_FIRMWARE_VERSION" ,
17
17
" OTA_STATE_CHECK_FIRMWARE_VERSION" ,
18
18
" OTA_STATE_UPDATE_FIRMWARE" };
@@ -468,74 +468,87 @@ const char *otaGetUrl()
468
468
bool otaCheckVersion (char *versionAvailable, uint8_t versionAvailableLength)
469
469
{
470
470
bool gotVersion = false ;
471
- #ifdef COMPILE_WIFI
471
+ #ifdef COMPILE_NETWORK
472
472
bool previouslyConnected = wifiIsConnected ();
473
473
474
474
bool wasInAPmode;
475
475
476
- if (wifiConnect (settings.wifiConnectTimeoutMs , true , &wasInAPmode) == true ) // Use WIFI_AP_STA if already in WIFI_AP mode
476
+ uint8_t networkType = networkGetActiveType ();
477
+ if ((networkType == NETWORK_TYPE_WIFI)
478
+ && (wifiNetworkCount () == 0 ))
479
+ {
480
+ systemPrintln (" Error: Please enter at least one SSID before getting keys" );
481
+ }
482
+ else
477
483
{
478
- char versionString[21 ];
479
- getFirmwareVersion (versionString, sizeof (versionString), enableRCFirmware);
480
- systemPrintf (" Current firmware version: %s\r\n " , versionString);
484
+ if ((networkType != NETWORK_TYPE_WIFI)
485
+ || (wifiConnect (settings.wifiConnectTimeoutMs , true , &wasInAPmode) == true )) // Use WIFI_AP_STA if already in WIFI_AP mode
486
+ {
487
+ char versionString[21 ];
488
+ getFirmwareVersion (versionString, sizeof (versionString), enableRCFirmware);
489
+ systemPrintf (" Current firmware version: %s\r\n " , versionString);
481
490
482
- const char *url = otaGetUrl ();
483
- systemPrintf (" Checking to see if an update is available from %s\r\n " , url);
491
+ const char *url = otaGetUrl ();
492
+ systemPrintf (" Checking to see if an update is available from %s\r\n " , url);
484
493
485
- ESP32OTAPull ota;
494
+ ESP32OTAPull ota;
486
495
487
- int response = ota.CheckForOTAUpdate (url, versionString, ESP32OTAPull::DONT_DO_UPDATE);
496
+ int response = ota.CheckForOTAUpdate (url, versionString, ESP32OTAPull::DONT_DO_UPDATE);
488
497
489
- // We don't care if the library thinks the available firmware is newer, we just need a successful JSON parse
490
- if (response == ESP32OTAPull::UPDATE_AVAILABLE || response == ESP32OTAPull::NO_UPDATE_AVAILABLE)
491
- {
492
- gotVersion = true ;
498
+ // We don't care if the library thinks the available firmware is newer, we just need a successful JSON parse
499
+ if (response == ESP32OTAPull::UPDATE_AVAILABLE || response == ESP32OTAPull::NO_UPDATE_AVAILABLE)
500
+ {
501
+ gotVersion = true ;
493
502
494
- // Call getVersion after original inquiry
495
- String otaVersion = ota.GetVersion ();
496
- otaVersion.toCharArray (versionAvailable, versionAvailableLength);
497
- }
498
- else if (response == ESP32OTAPull::HTTP_FAILED)
499
- {
500
- systemPrintln (" Firmware server not available" );
503
+ // Call getVersion after original inquiry
504
+ String otaVersion = ota.GetVersion ();
505
+ otaVersion.toCharArray (versionAvailable, versionAvailableLength);
506
+ }
507
+ else if (response == ESP32OTAPull::HTTP_FAILED)
508
+ {
509
+ systemPrintln (" Firmware server not available" );
510
+ }
511
+ else
512
+ {
513
+ systemPrintln (" OTA failed" );
514
+ }
515
+
516
+ if (networkType == NETWORK_TYPE_WIFI)
517
+ {
518
+ // If we were in WIFI_AP mode, return to WIFI_AP mode
519
+ // There may be some overlap with systemState STATE_WIFI_CONFIG ? Not sure...
520
+ if (wasInAPmode)
521
+ WiFi.mode (WIFI_AP);
522
+
523
+ if (systemState != STATE_WIFI_CONFIG)
524
+ {
525
+ // WIFI_STOP() turns off the entire radio including the webserver. We need to turn off Station mode only.
526
+ // For now, unit exits AP mode via reset so if we are in AP config mode, leave WiFi Station running.
527
+
528
+ // If WiFi was originally off, turn it off again
529
+ if (previouslyConnected == false )
530
+ WIFI_STOP ();
531
+ }
532
+ }
501
533
}
502
534
else
503
535
{
504
- systemPrintln (" OTA failed " );
536
+ systemPrintln (" Network not available for OTA! " );
505
537
}
506
538
}
507
- else
508
- {
509
- systemPrintln (" WiFi not available." );
510
- }
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
-
517
- if (systemState != STATE_WIFI_CONFIG)
518
- {
519
- // WIFI_STOP() turns off the entire radio including the webserver. We need to turn off Station mode only.
520
- // For now, unit exits AP mode via reset so if we are in AP config mode, leave WiFi Station running.
521
-
522
- // If WiFi was originally off, turn it off again
523
- if (previouslyConnected == false )
524
- WIFI_STOP ();
525
- }
526
539
527
540
if (gotVersion == true )
528
541
log_d (" Available OTA firmware version: %s\r\n " , versionAvailable);
529
542
530
- #endif // COMPILE_WIFI
543
+ #endif // COMPILE_NETWORK
531
544
return (gotVersion);
532
545
}
533
546
534
547
// Force updates firmware using OTA pull
535
548
// Exits by either updating firmware and resetting, or failing to connect
536
549
void overTheAirUpdate ()
537
550
{
538
- #ifdef COMPILE_WIFI
551
+ #ifdef COMPILE_NETWORK
539
552
char versionString[9 ];
540
553
formatFirmwareVersion (0 , 0 , versionString, sizeof (versionString), false );
541
554
@@ -566,13 +579,13 @@ void overTheAirUpdate()
566
579
systemPrintln (" OTA Update: Firmware server not available" );
567
580
else
568
581
systemPrintln (" OTA Update: OTA failed" );
569
- #endif
582
+ #endif // COMPILE_NETWORK
570
583
}
571
584
572
585
// Start WiFi and perform the over-the-air update
573
586
void otaUpdate ()
574
587
{
575
- #ifdef COMPILE_WIFI
588
+ #ifdef COMPILE_NETWORK
576
589
bool previouslyConnected = wifiIsConnected ();
577
590
578
591
bool wasInAPmode;
@@ -588,7 +601,7 @@ void otaUpdate()
588
601
if (previouslyConnected == false )
589
602
WIFI_STOP ();
590
603
591
- #endif // COMPILE_WIFI
604
+ #endif // COMPILE_NETWORK
592
605
}
593
606
594
607
// Called while the OTA Pull update is happening
@@ -633,7 +646,7 @@ void otaDisplayPercentage(int bytesWritten, int totalLength, bool alwaysDisplay)
633
646
634
647
const char *otaPullErrorText (int code)
635
648
{
636
- #ifdef COMPILE_WIFI
649
+ #ifdef COMPILE_NETWORK
637
650
switch (code)
638
651
{
639
652
case ESP32OTAPull::UPDATE_AVAILABLE:
@@ -657,7 +670,7 @@ const char *otaPullErrorText(int code)
657
670
return " Unexpected HTTP response code" ;
658
671
break ;
659
672
}
660
- #endif // COMPILE_WIFI
673
+ #endif // COMPILE_NETWORK
661
674
return " Unknown error" ;
662
675
}
663
676
@@ -871,7 +884,7 @@ void otaAutoUpdate()
871
884
if ((millis () - otaLastUpdateCheck) >= checkIntervalMillis)
872
885
{
873
886
otaLastUpdateCheck = millis ();
874
- otaSetState (OTA_STATE_START_WIFI );
887
+ otaSetState (OTA_STATE_START_NETWORK );
875
888
}
876
889
}
877
890
@@ -892,20 +905,20 @@ void otaAutoUpdate()
892
905
break ;
893
906
894
907
// Start the WiFi network
895
- case OTA_STATE_START_WIFI :
908
+ case OTA_STATE_START_NETWORK :
896
909
if (settings.debugFirmwareUpdate )
897
910
systemPrintln (" Firmware update starting WiFi" );
898
- if (!networkUserOpen (NETWORK_USER_OTA_AUTO_UPDATE, NETWORK_TYPE_WIFI ))
911
+ if (!networkUserOpen (NETWORK_USER_OTA_AUTO_UPDATE, NETWORK_TYPE_ACTIVE ))
899
912
{
900
913
systemPrintln (" Firmware update failed, unable to start WiFi" );
901
914
otaAutoUpdateStop ();
902
915
}
903
916
else
904
- otaSetState (OTA_STATE_WAIT_FOR_WIFI );
917
+ otaSetState (OTA_STATE_WAIT_FOR_NETWORK );
905
918
break ;
906
919
907
920
// Wait for connection to the access point
908
- case OTA_STATE_WAIT_FOR_WIFI :
921
+ case OTA_STATE_WAIT_FOR_NETWORK :
909
922
// Determine if the network has failed
910
923
if (networkIsShuttingDown (NETWORK_USER_OTA_AUTO_UPDATE))
911
924
otaAutoUpdateStop ();
0 commit comments