Decrease delay otaInProgress check

Do not run NetworkingTask when in offline mode
This commit is contained in:
samuelbles07
2025-03-18 00:01:04 +07:00
parent 26db6372cd
commit e93009f31c
2 changed files with 23 additions and 20 deletions

View File

@ -204,8 +204,7 @@ void setup() {
setMeasurementMaxPeriod(); setMeasurementMaxPeriod();
// Comment below line to disable debug measurement readings // Comment below line to disable debug measurement readings
measurements.setDebug(false); measurements.setDebug(true);
// bool connectToWifi = false; // bool connectToWifi = false;
bool connectToNetwork = true; bool connectToNetwork = true;
@ -241,6 +240,7 @@ void setup() {
// Initialize networking configuration // Initialize networking configuration
if (connectToNetwork) { if (connectToNetwork) {
oledDisplay.setText("Initialize", "network...", "");
initializeNetwork(); initializeNetwork();
} }
@ -264,13 +264,15 @@ void setup() {
// Initialize mutex to access mesurementCycleQueue // Initialize mutex to access mesurementCycleQueue
mutexMeasurementCycleQueue = xSemaphoreCreateMutex(); mutexMeasurementCycleQueue = xSemaphoreCreateMutex();
// Only run network task if monitor is not in offline mode
if (configuration.isOfflineMode() == false) {
BaseType_t xReturned = BaseType_t xReturned =
xTaskCreate(networkingTask, "NetworkingTask", 4096, null, 5, &handleNetworkTask); xTaskCreate(networkingTask, "NetworkingTask", 4096, null, 5, &handleNetworkTask);
if (xReturned == pdPASS) { if (xReturned == pdPASS) {
Serial.println("Success create networking task"); Serial.println("Success create networking task");
} else { } else {
Serial.println("Failed to create networking task"); assert("Failed to create networking task");
// TODO: What to do here? }
} }
// Log monitor mode for debugging purpose // Log monitor mode for debugging purpose
@ -294,8 +296,8 @@ void loop() {
watchdogFeedSchedule.run(); watchdogFeedSchedule.run();
if (otaInProgress) { if (otaInProgress) {
Serial.println("Firmware update in progress, pausing sensor readings"); // OTA currently in progress, temporarily disable running sensor schedules
delay(2 * 60000); delay(10000);
return; return;
} }
@ -536,14 +538,15 @@ void checkForFirmwareUpdate(void) {
// Indicate main task that ota is performing // Indicate main task that ota is performing
// Only for cellular because it can disturb i2c line // Only for cellular because it can disturb i2c line
Serial.println("Check for firmware update");
if (networkOption == UseCellular) { if (networkOption == UseCellular) {
Serial.println("Disabling scheduler to read sensors for cellular OTA");
otaInProgress = true; otaInProgress = true;
if (configuration.hasSensorSGP) { if (configuration.hasSensorSGP) {
ag->sgp41.end(); ag->sgp41.end();
} }
} }
Serial.println("Check for firmware update");
agOta->setHandlerCallback(otaHandlerCallback); agOta->setHandlerCallback(otaHandlerCallback);
agOta->updateIfAvailable(ag->getDeviceId(), GIT_VERSION); agOta->updateIfAvailable(ag->getDeviceId(), GIT_VERSION);
@ -935,9 +938,8 @@ void initializeNetwork() {
} }
if (!agClient->begin()) { if (!agClient->begin()) {
// TODO: Need to do retry when agclient already in other task // TODO: Is assert here properly added?
Serial.println("Failed start Airgradient Client FAILED"); assert("Failed start Airgradient Client");
assert(0);
} }
if (networkOption == UseWifi) { if (networkOption == UseWifi) {
@ -1106,11 +1108,12 @@ static void updateDisplayAndLedBar(void) {
return; return;
} }
// if (wifiConnector.isConnected() == false) { if (wifiConnector.isConnected() == false) {
// stateMachine.displayHandle(AgStateMachineWiFiLost); stateMachine.displayHandle(AgStateMachineWiFiLost);
// stateMachine.handleLeds(AgStateMachineWiFiLost); stateMachine.handleLeds(AgStateMachineWiFiLost);
// return; return;
// } }
// TODO: Also show for cellular connection
if (configuration.isCloudConnectionDisabled()) { if (configuration.isCloudConnectionDisabled()) {
// Ignore API related check since cloud is disabled // Ignore API related check since cloud is disabled

View File

@ -12,7 +12,7 @@
platform = espressif32 platform = espressif32
board = esp32-c3-devkitm-1 board = esp32-c3-devkitm-1
framework = arduino framework = arduino
build_flags = !echo '-D ARDUINO_USB_CDC_ON_BOOT=1 -D ARDUINO_USB_MODE=1 -D GIT_VERSION=\\"'$(git describe --tags --always --dirty)'\\"' build_flags = !echo '-D ARDUINO_USB_CDC_ON_BOOT=1 -D ARDUINO_USB_MODE=1 -D CORE_DEBUG_LEVEL=3 -D GIT_VERSION=\\"'$(git describe --tags --always --dirty)'\\"'
board_build.partitions = partitions.csv board_build.partitions = partitions.csv
monitor_speed = 115200 monitor_speed = 115200
lib_deps = lib_deps =