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