mirror of
https://github.com/airgradienthq/arduino.git
synced 2025-07-31 01:17:16 +02:00
Tested ota cellular integration
This commit is contained in:
@ -110,11 +110,10 @@ enum NetworkOption {
|
|||||||
};
|
};
|
||||||
NetworkOption networkOption;
|
NetworkOption networkOption;
|
||||||
TaskHandle_t handleNetworkTask = NULL;
|
TaskHandle_t handleNetworkTask = NULL;
|
||||||
|
static bool otaInProgress = false;
|
||||||
|
|
||||||
static uint32_t factoryBtnPressTime = 0;
|
static uint32_t factoryBtnPressTime = 0;
|
||||||
static AgFirmwareMode fwMode = FW_MODE_I_9PSL;
|
static AgFirmwareMode fwMode = FW_MODE_I_9PSL;
|
||||||
|
|
||||||
static bool ledBarButtonTest = false;
|
static bool ledBarButtonTest = false;
|
||||||
static String fwNewVersion;
|
static String fwNewVersion;
|
||||||
|
|
||||||
@ -291,11 +290,18 @@ void setup() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
// Schedule to update display and led
|
|
||||||
dispLedSchedule.run();
|
|
||||||
// Schedule to feed external watchdog
|
// Schedule to feed external watchdog
|
||||||
watchdogFeedSchedule.run();
|
watchdogFeedSchedule.run();
|
||||||
|
|
||||||
|
if (otaInProgress) {
|
||||||
|
Serial.println("Firmware update in progress, pausing sensor readings");
|
||||||
|
delay(2 * 60000);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Schedule to update display and led
|
||||||
|
dispLedSchedule.run();
|
||||||
|
|
||||||
// No need to run measurement cycle schedule when mode is offline or connection to AG disabled
|
// No need to run measurement cycle schedule when mode is offline or connection to AG disabled
|
||||||
if (configuration.isOfflineMode() == false ||
|
if (configuration.isOfflineMode() == false ||
|
||||||
configuration.isCloudConnectionDisabled() == false) {
|
configuration.isCloudConnectionDisabled() == false) {
|
||||||
@ -528,11 +534,30 @@ void checkForFirmwareUpdate(void) {
|
|||||||
agOta = new AirgradientOTACellular(cell);
|
agOta = new AirgradientOTACellular(cell);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: This might be too long and new measurement cycle queue will be big
|
// Indicate main task that ota is performing
|
||||||
|
// Only for cellular because it can disturb i2c line
|
||||||
|
if (networkOption == UseCellular) {
|
||||||
|
otaInProgress = true;
|
||||||
|
if (configuration.hasSensorSGP) {
|
||||||
|
ag->sgp41.end();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Serial.println("Check for firmware update");
|
Serial.println("Check for firmware update");
|
||||||
agOta->setHandlerCallback(otaHandlerCallback);
|
agOta->setHandlerCallback(otaHandlerCallback);
|
||||||
agOta->updateIfAvailable(ag->getDeviceId(), GIT_VERSION);
|
agOta->updateIfAvailable(ag->getDeviceId(), GIT_VERSION);
|
||||||
// agOta->updateIfAvailable("aabbccddeeff", GIT_VERSION);
|
|
||||||
|
// Only goes to this line if OTA is not success
|
||||||
|
// Handled by otaHandlerCallback
|
||||||
|
if (networkOption == UseCellular) {
|
||||||
|
otaInProgress = false;
|
||||||
|
if (configuration.hasSensorSGP) {
|
||||||
|
if (!sgp41Init()) {
|
||||||
|
Serial.println("Failed re-start SGP41 task");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
delete agOta;
|
delete agOta;
|
||||||
Serial.println();
|
Serial.println();
|
||||||
}
|
}
|
||||||
@ -953,13 +978,6 @@ void initializeNetwork() {
|
|||||||
// Send data for the first time to AG server at boot
|
// Send data for the first time to AG server at boot
|
||||||
sendDataToAg();
|
sendDataToAg();
|
||||||
|
|
||||||
// OTA check
|
|
||||||
#ifdef ESP8266
|
|
||||||
// ota not supported
|
|
||||||
#else
|
|
||||||
checkForFirmwareUpdate();
|
|
||||||
checkForUpdateSchedule.update();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
std::string config = agClient->httpFetchConfig(ag->getDeviceId());
|
std::string config = agClient->httpFetchConfig(ag->getDeviceId());
|
||||||
configSchedule.update();
|
configSchedule.update();
|
||||||
@ -1392,6 +1410,15 @@ int calculateMaxPeriod(int updateInterval) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void networkingTask(void *args) {
|
void networkingTask(void *args) {
|
||||||
|
// OTA check on boot
|
||||||
|
#ifdef ESP8266
|
||||||
|
// ota not supported
|
||||||
|
#else
|
||||||
|
// because cellular it takes too long, watchdog triggered
|
||||||
|
checkForFirmwareUpdate();
|
||||||
|
checkForUpdateSchedule.update();
|
||||||
|
#endif
|
||||||
|
|
||||||
// TODO: Need to better define delay value
|
// TODO: Need to better define delay value
|
||||||
|
|
||||||
// Reset scheduler
|
// Reset scheduler
|
||||||
@ -1412,6 +1439,7 @@ void networkingTask(void *args) {
|
|||||||
// It can be an indication that module has a problem
|
// It can be an indication that module has a problem
|
||||||
if (agClient->isLastFetchConfigSucceed() == false ||
|
if (agClient->isLastFetchConfigSucceed() == false ||
|
||||||
agClient->isLastPostMeasureSucceed() == false) {
|
agClient->isLastPostMeasureSucceed() == false) {
|
||||||
|
Serial.println("Last server communication might failed, checking...");
|
||||||
if (agClient->ensureClientConnection() == false) {
|
if (agClient->ensureClientConnection() == false) {
|
||||||
Serial.println("Cellular client connection not ready, retry in 5s...");
|
Serial.println("Cellular client connection not ready, retry in 5s...");
|
||||||
delay(5000);
|
delay(5000);
|
||||||
|
Submodule src/Libraries/airgradient-client updated: 24ec7c9e67...486ee4f6ef
Reference in New Issue
Block a user