Skip to content

Commit 9bba897

Browse files
committed
Fix sgp unreliable value by only pause task when performing ota
1 parent 81945a3 commit 9bba897

File tree

2 files changed

+26
-26
lines changed

2 files changed

+26
-26
lines changed

examples/OneOpenAir/OneOpenAir.ino

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ enum NetworkOption {
117117
};
118118
NetworkOption networkOption;
119119
TaskHandle_t handleNetworkTask = NULL;
120-
static bool otaInProgress = false;
120+
static bool firmwareUpdateInProgress = false;
121121

122122
static uint32_t factoryBtnPressTime = 0;
123123
static AgFirmwareMode fwMode = FW_MODE_I_9PSL;
@@ -318,8 +318,8 @@ void loop() {
318318
// Schedule to feed external watchdog
319319
watchdogFeedSchedule.run();
320320

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
323323
delay(10000);
324324
return;
325325
}
@@ -562,38 +562,33 @@ void checkForFirmwareUpdate(void) {
562562
agOta = new AirgradientOTACellular(cellularCard);
563563
}
564564

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;
573567

574568
agOta->setHandlerCallback(otaHandlerCallback);
575569
agOta->updateIfAvailable(ag->deviceId().c_str(), GIT_VERSION);
576570

577-
// Only goes to this line if OTA is not success
571+
// Only goes to this line if firmware update is not success
578572
// Handled by otaHandlerCallback
579573

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;
587576

588577
delete agOta;
589578
Serial.println();
590579
}
591580

592581
void otaHandlerCallback(AirgradientOTA::OtaResult result, const char *msg) {
593582
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.pauseHandle();
588+
}
595589
displayExecuteOta(result, fwNewVersion, 0);
596590
break;
591+
}
597592
case AirgradientOTA::InProgress:
598593
Serial.printf("OTA progress: %s\n", msg);
599594
displayExecuteOta(result, "", std::stoi(msg));
@@ -602,6 +597,10 @@ void otaHandlerCallback(AirgradientOTA::OtaResult result, const char *msg) {
602597
case AirgradientOTA::Skipped:
603598
case AirgradientOTA::AlreadyUpToDate:
604599
displayExecuteOta(result, "", 0);
600+
if (configuration.hasSensorSGP && networkOption == UseCellular) {
601+
// Cellular firmware update finish, resuming SGP41 task
602+
ag->sgp41.resumeHandle();
603+
}
605604
break;
606605
case AirgradientOTA::Success:
607606
displayExecuteOta(result, "", 0);
@@ -665,7 +664,11 @@ static void displayExecuteOta(AirgradientOTA::OtaResult result, String msg, int
665664
}
666665
delay(1000);
667666
}
668-
oledDisplay.setAirGradient(0);
667+
668+
if (ag->isOne()) {
669+
oledDisplay.setAirGradient(0);
670+
oledDisplay.setBrightness(0);
671+
}
669672
break;
670673
}
671674
default:
@@ -1548,10 +1551,7 @@ void restartIfCeClientIssueOverTwoHours() {
15481551

15491552
void networkingTask(void *args) {
15501553
// OTA check on boot
1551-
#ifdef ESP8266
1552-
// ota not supported
1553-
#else
1554-
// because cellular it takes too long, watchdog triggered
1554+
#ifndef ESP8266
15551555
checkForFirmwareUpdate();
15561556
checkForUpdateSchedule.update();
15571557
#endif

0 commit comments

Comments
 (0)