From ebbf0adf2fa037728a04be178abbd06aae247a90 Mon Sep 17 00:00:00 2001 From: MallocArray Date: Sat, 18 May 2024 21:19:40 -0500 Subject: [PATCH 1/6] Correct API value for boot --- src/AgValue.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/AgValue.cpp b/src/AgValue.cpp index 9d1fd87..14580ff 100644 --- a/src/AgValue.cpp +++ b/src/AgValue.cpp @@ -173,7 +173,7 @@ String Measurements::toString(bool localServer, AgFirmwareMode fwMode, int rssi, root["noxRaw"] = this->NOxRaw; } } - root["bootCount"] = bootCount; + root["boot"] = bootCount; if (localServer) { root["ledMode"] = config->getLedBarModeName(); From 805546b78e332b6116eaf618f3e8e5f1db40301b Mon Sep 17 00:00:00 2001 From: Phat Nguyen Date: Wed, 22 May 2024 11:34:42 +0700 Subject: [PATCH 2/6] check firmware update after powerup --- examples/OneOpenAir/OneOpenAir.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/OneOpenAir/OneOpenAir.ino b/examples/OneOpenAir/OneOpenAir.ino index ed911d5..a9f81eb 100644 --- a/examples/OneOpenAir/OneOpenAir.ino +++ b/examples/OneOpenAir/OneOpenAir.ino @@ -219,7 +219,7 @@ void setup() { #ifdef ESP8266 // ota not supported #else - // otaHandler.updateFirmwareIfOutdated(ag->deviceId()); + otaHandler.updateFirmwareIfOutdated(ag->deviceId()); #endif apiClient.fetchServerConfiguration(); From 7550ef7b0c9286310a983fba39f8df47c977e540 Mon Sep 17 00:00:00 2001 From: Phat Nguyen Date: Wed, 22 May 2024 11:45:56 +0700 Subject: [PATCH 3/6] change OTA update period each 2h. --- examples/OneOpenAir/OneOpenAir.ino | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/examples/OneOpenAir/OneOpenAir.ino b/examples/OneOpenAir/OneOpenAir.ino index a9f81eb..82742a1 100644 --- a/examples/OneOpenAir/OneOpenAir.ino +++ b/examples/OneOpenAir/OneOpenAir.ino @@ -220,6 +220,9 @@ void setup() { // ota not supported #else otaHandler.updateFirmwareIfOutdated(ag->deviceId()); + + /** Update first OTA */ + measurements.otaBootCount = 0; #endif apiClient.fetchServerConfiguration(); @@ -861,7 +864,9 @@ static void configUpdateHandle() { doOta = true; Serial.println("First OTA"); } else { - if ((measurements.bootCount - measurements.otaBootCount) >= 30) { + /** Only check for update each 2h*/ + const float otaBootCount = 120.0f / (SERVER_SYNC_INTERVAL / 60000.0f); + if ((measurements.bootCount - measurements.otaBootCount) >= (int)otaBootCount) { doOta = true; } else { Serial.println( From c5b7c43293ff5f6fa9d70a59d632f8f104e116a1 Mon Sep 17 00:00:00 2001 From: Phat Nguyen Date: Wed, 22 May 2024 12:13:57 +0700 Subject: [PATCH 4/6] disp.setText("Monitor not", "setup on", "dashboard") called when monitor is actually already on dashboard --- examples/OneOpenAir/OneOpenAir.ino | 6 ++++-- src/AgApiClient.cpp | 17 +++++++++++++++++ src/AgApiClient.h | 2 ++ 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/examples/OneOpenAir/OneOpenAir.ino b/examples/OneOpenAir/OneOpenAir.ino index ed911d5..f087079 100644 --- a/examples/OneOpenAir/OneOpenAir.ino +++ b/examples/OneOpenAir/OneOpenAir.ino @@ -226,8 +226,10 @@ void setup() { configSchedule.update(); if (apiClient.isFetchConfigureFailed()) { if (ag->isOne()) { - stateMachine.displayHandle( - AgStateMachineWiFiOkServerOkSensorConfigFailed); + if (apiClient.isNotAvailableOnDashboard()) { + stateMachine.displayHandle( + AgStateMachineWiFiOkServerOkSensorConfigFailed); + } } stateMachine.handleLeds( AgStateMachineWiFiOkServerOkSensorConfigFailed); diff --git a/src/AgApiClient.cpp b/src/AgApiClient.cpp index 699d5ae..1f7c83b 100644 --- a/src/AgApiClient.cpp +++ b/src/AgApiClient.cpp @@ -69,11 +69,17 @@ bool AgApiClient::fetchServerConfiguration(void) { if (retCode != 200) { client.end(); getConfigFailed = true; + + /** Return code 400 mean device not setup on cloud. */ + if (retCode == 400) { + notAvailableOnDashboard = true; + } return false; } /** clear failed */ getConfigFailed = false; + notAvailableOnDashboard = false; /** Get response string */ String respContent = client.getString(); @@ -144,6 +150,17 @@ bool AgApiClient::isFetchConfigureFailed(void) { return getConfigFailed; } */ bool AgApiClient::isPostToServerFailed(void) { return postToServerFailed; } +/** + * @brief Get status device has available on dashboard or not. should get after + * fetch configuration return failed + * + * @return true + * @return false + */ +bool AgApiClient::isNotAvailableOnDashboard(void) { + return notAvailableOnDashboard; +} + void AgApiClient::setAirGradient(AirGradient *ag) { this->ag = ag; } /** diff --git a/src/AgApiClient.h b/src/AgApiClient.h index 44ca691..4b37bf3 100644 --- a/src/AgApiClient.h +++ b/src/AgApiClient.h @@ -23,6 +23,7 @@ private: bool getConfigFailed; bool postToServerFailed; + bool notAvailableOnDashboard = false; // Device not setup on Airgradient cloud dashboard. public: AgApiClient(Stream &stream, Configuration &config); @@ -33,6 +34,7 @@ public: bool postToServer(String data); bool isFetchConfigureFailed(void); bool isPostToServerFailed(void); + bool isNotAvailableOnDashboard(void); void setAirGradient(AirGradient *ag); bool sendPing(int rssi, int bootCount); }; From d85d89087813dc1a345d8b79af2d99d1f9918a6d Mon Sep 17 00:00:00 2001 From: Phat Nguyen Date: Fri, 24 May 2024 08:26:24 +0700 Subject: [PATCH 5/6] Change OTA update period from 2h to 1h --- examples/OneOpenAir/OneOpenAir.ino | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/OneOpenAir/OneOpenAir.ino b/examples/OneOpenAir/OneOpenAir.ino index 82742a1..594878e 100644 --- a/examples/OneOpenAir/OneOpenAir.ino +++ b/examples/OneOpenAir/OneOpenAir.ino @@ -864,8 +864,8 @@ static void configUpdateHandle() { doOta = true; Serial.println("First OTA"); } else { - /** Only check for update each 2h*/ - const float otaBootCount = 120.0f / (SERVER_SYNC_INTERVAL / 60000.0f); + /** Only check for update each 1h*/ + const float otaBootCount = 60.0f / (SERVER_SYNC_INTERVAL / 60000.0f); if ((measurements.bootCount - measurements.otaBootCount) >= (int)otaBootCount) { doOta = true; } else { From 5770b41fd4b186667d90100f433b7c26528cc854 Mon Sep 17 00:00:00 2001 From: Phat Nguyen Date: Fri, 24 May 2024 08:45:50 +0700 Subject: [PATCH 6/6] remove `Update ignored due to local unofficial changes` --- src/AgConfigure.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/AgConfigure.cpp b/src/AgConfigure.cpp index a52dbf9..2fc5536 100644 --- a/src/AgConfigure.cpp +++ b/src/AgConfigure.cpp @@ -628,7 +628,6 @@ bool Configuration::parse(String data, bool isLocal) { saveConfig(); printConfig(); } else { - logInfo("Update ignored due to local unofficial changes"); if (ledBarTestRequested || co2CalibrationRequested) { udpated = true; }