@@ -117,7 +117,7 @@ enum NetworkOption {
117
117
};
118
118
NetworkOption networkOption;
119
119
TaskHandle_t handleNetworkTask = NULL ;
120
- static bool otaInProgress = false ;
120
+ static bool firmwareUpdateInProgress = false ;
121
121
122
122
static uint32_t factoryBtnPressTime = 0 ;
123
123
static AgFirmwareMode fwMode = FW_MODE_I_9PSL;
@@ -318,8 +318,8 @@ void loop() {
318
318
// Schedule to feed external watchdog
319
319
watchdogFeedSchedule.run ();
320
320
321
- if (otaInProgress ) {
322
- // OTA currently in progress, temporarily disable running sensor schedules
321
+ if (firmwareUpdateInProgress ) {
322
+ // Firmare update currently in progress, temporarily disable running sensor schedules
323
323
delay (10000 );
324
324
return ;
325
325
}
@@ -562,43 +562,43 @@ void checkForFirmwareUpdate(void) {
562
562
agOta = new AirgradientOTACellular (cellularCard);
563
563
}
564
564
565
- // Indicate main task that ota is performing
566
- Serial.println (" Check for firmware update, disabling main task" );
567
- otaInProgress = true ;
568
- if (configuration.hasSensorSGP && networkOption == UseCellular) {
569
- // Only for cellular because it can disturb i2c line
570
- Serial.println (" Disable SGP41 task for cellular OTA" );
571
- ag->sgp41 .end ();
572
- }
565
+ // Indicate main task that firmware update is in progress
566
+ firmwareUpdateInProgress = true ;
573
567
574
568
agOta->setHandlerCallback (otaHandlerCallback);
575
569
agOta->updateIfAvailable (ag->deviceId ().c_str (), GIT_VERSION);
576
570
577
- // Only goes to this line if OTA is not success
571
+ // Only goes to this line if firmware update is not success
578
572
// Handled by otaHandlerCallback
579
573
580
- otaInProgress = false ;
581
- if (configuration.hasSensorSGP && networkOption == UseCellular) {
582
- // Re-start SGP41 task
583
- if (!sgp41Init ()) {
584
- Serial.println (" Failed re-start SGP41 task" );
585
- }
586
- }
574
+ // Indicate main task that firmware update finish
575
+ firmwareUpdateInProgress = false ;
587
576
588
577
delete agOta;
589
578
Serial.println ();
590
579
}
591
580
592
581
void otaHandlerCallback (AirgradientOTA::OtaResult result, const char *msg) {
593
582
switch (result) {
594
- case AirgradientOTA::Starting:
583
+ case AirgradientOTA::Starting: {
584
+ Serial.println (" Firmware update starting..." );
585
+ if (configuration.hasSensorSGP && networkOption == UseCellular) {
586
+ // Temporary pause SGP41 task while cellular firmware update is in progress
587
+ ag->sgp41 .pause ();
588
+ }
595
589
displayExecuteOta (result, fwNewVersion, 0 );
596
590
break ;
591
+ }
597
592
case AirgradientOTA::InProgress:
598
593
Serial.printf (" OTA progress: %s\n " , msg);
599
594
displayExecuteOta (result, " " , std::stoi (msg));
600
595
break ;
601
596
case AirgradientOTA::Failed:
597
+ displayExecuteOta (result, " " , 0 );
598
+ if (configuration.hasSensorSGP && networkOption == UseCellular) {
599
+ ag->sgp41 .resume ();
600
+ }
601
+ break ;
602
602
case AirgradientOTA::Skipped:
603
603
case AirgradientOTA::AlreadyUpToDate:
604
604
displayExecuteOta (result, " " , 0 );
@@ -665,7 +665,11 @@ static void displayExecuteOta(AirgradientOTA::OtaResult result, String msg, int
665
665
}
666
666
delay (1000 );
667
667
}
668
- oledDisplay.setAirGradient (0 );
668
+
669
+ if (ag->isOne ()) {
670
+ oledDisplay.setAirGradient (0 );
671
+ oledDisplay.setBrightness (0 );
672
+ }
669
673
break ;
670
674
}
671
675
default :
@@ -1548,10 +1552,7 @@ void restartIfCeClientIssueOverTwoHours() {
1548
1552
1549
1553
void networkingTask (void *args) {
1550
1554
// OTA check on boot
1551
- #ifdef ESP8266
1552
- // ota not supported
1553
- #else
1554
- // because cellular it takes too long, watchdog triggered
1555
+ #ifndef ESP8266
1555
1556
checkForFirmwareUpdate ();
1556
1557
checkForUpdateSchedule.update ();
1557
1558
#endif
0 commit comments