From 154f3ecf8a853ea95429343c155567d4c0435723 Mon Sep 17 00:00:00 2001 From: samuelbles07 Date: Sat, 1 Feb 2025 13:52:12 +0700 Subject: [PATCH 1/5] Fix display 0 measurements on boot --- examples/OneOpenAir/OneOpenAir.ino | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/examples/OneOpenAir/OneOpenAir.ino b/examples/OneOpenAir/OneOpenAir.ino index ee4b680..9030ee8 100644 --- a/examples/OneOpenAir/OneOpenAir.ino +++ b/examples/OneOpenAir/OneOpenAir.ino @@ -268,15 +268,17 @@ void setup() { oledDisplay.setBrightness(configuration.getDisplayBrightness()); } - // Update display and led bar after finishing setup to show dashboard - updateDisplayAndLedBar(); + // Reset display and post schedulers to make sure measurements value already available + dispLedSchedule.update(); + agApiPostSchedule.update(); } void loop() { - /** Handle schedule */ + /** Run schedulers */ dispLedSchedule.run(); configSchedule.run(); agApiPostSchedule.run(); + watchdogFeedSchedule.run(); if (configuration.hasSensorS8) { co2Schedule.run(); @@ -310,15 +312,13 @@ void loop() { } } - watchdogFeedSchedule.run(); - /** Check for handle WiFi reconnect */ wifiConnector.handle(); /** factory reset handle */ factoryConfigReset(); - /** check that local configura changed then do some action */ + /** check that local configuration changed then do some action */ configUpdateHandle(); /** Firmware check for update handle */ From 1839664137502146d0229565fc8b94089fb19dac Mon Sep 17 00:00:00 2001 From: samuelbles07 Date: Sat, 1 Feb 2025 14:20:54 +0700 Subject: [PATCH 2/5] Extend connect to server timeout Default 5s from HTTPClient --- src/AgApiClient.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/AgApiClient.cpp b/src/AgApiClient.cpp index 8de2596..b2dbf1f 100644 --- a/src/AgApiClient.cpp +++ b/src/AgApiClient.cpp @@ -59,6 +59,7 @@ bool AgApiClient::fetchServerConfiguration(void) { #else HTTPClient client; client.setTimeout(timeoutMs); + client.setConnectTimeout(timeoutMs); if (apiRootChanged) { // If apiRoot is changed, assume not using https if (client.begin(uri) == false) { @@ -134,6 +135,7 @@ bool AgApiClient::postToServer(String data) { #else HTTPClient client; client.setTimeout(timeoutMs); + client.setConnectTimeout(timeoutMs); if (apiRootChanged) { // If apiRoot is changed, assume not using https if (client.begin(uri) == false) { From d2ee3a5d244b13ce08cdebc4044bed59a90765bd Mon Sep 17 00:00:00 2001 From: samuelbles07 Date: Mon, 3 Feb 2025 01:28:42 +0700 Subject: [PATCH 3/5] Set default value for each measurements value to invalid --- examples/OneOpenAir/OneOpenAir.ino | 3 +-- src/AgValue.cpp | 39 ++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/examples/OneOpenAir/OneOpenAir.ino b/examples/OneOpenAir/OneOpenAir.ino index 9030ee8..47be2ff 100644 --- a/examples/OneOpenAir/OneOpenAir.ino +++ b/examples/OneOpenAir/OneOpenAir.ino @@ -268,8 +268,7 @@ void setup() { oledDisplay.setBrightness(configuration.getDisplayBrightness()); } - // Reset display and post schedulers to make sure measurements value already available - dispLedSchedule.update(); + // Reset post schedulers to make sure measurements value already available agApiPostSchedule.update(); } diff --git a/src/AgValue.cpp b/src/AgValue.cpp index 1a46ece..544744c 100644 --- a/src/AgValue.cpp +++ b/src/AgValue.cpp @@ -31,6 +31,45 @@ Measurements::Measurements() { #ifndef ESP8266 _resetReason = (int)ESP_RST_UNKNOWN; #endif + + /* Set invalid value for each measurements as default value when initialized*/ + _temperature[0].update.avg = utils::getInvalidTemperature(); + _temperature[1].update.avg = utils::getInvalidTemperature(); + _humidity[0].update.avg = utils::getInvalidHumidity(); + _humidity[1].update.avg = utils::getInvalidHumidity(); + _co2.update.avg = utils::getInvalidCO2(); + _tvoc.update.avg = utils::getInvalidVOC(); + _tvoc_raw.update.avg = utils::getInvalidVOC(); + _nox.update.avg = utils::getInvalidNOx(); + _nox_raw.update.avg = utils::getInvalidNOx(); + + _pm_03_pc[0].update.avg = utils::getInvalidPmValue(); + _pm_03_pc[1].update.avg = utils::getInvalidPmValue(); + _pm_05_pc[0].update.avg = utils::getInvalidPmValue(); + _pm_05_pc[1].update.avg = utils::getInvalidPmValue(); + _pm_5_pc[0].update.avg = utils::getInvalidPmValue(); + _pm_5_pc[1].update.avg = utils::getInvalidPmValue(); + + _pm_01[0].update.avg = utils::getInvalidPmValue(); + _pm_01_sp[0].update.avg = utils::getInvalidPmValue(); + _pm_01_pc[0].update.avg = utils::getInvalidPmValue(); + _pm_01[1].update.avg = utils::getInvalidPmValue(); + _pm_01_sp[1].update.avg = utils::getInvalidPmValue(); + _pm_01_pc[1].update.avg = utils::getInvalidPmValue(); + + _pm_25[0].update.avg = utils::getInvalidPmValue(); + _pm_25_sp[0].update.avg = utils::getInvalidPmValue(); + _pm_25_pc[0].update.avg = utils::getInvalidPmValue(); + _pm_25[1].update.avg = utils::getInvalidPmValue(); + _pm_25_sp[1].update.avg = utils::getInvalidPmValue(); + _pm_25_pc[1].update.avg = utils::getInvalidPmValue(); + + _pm_10[0].update.avg = utils::getInvalidPmValue(); + _pm_10_sp[0].update.avg = utils::getInvalidPmValue(); + _pm_10_pc[0].update.avg = utils::getInvalidPmValue(); + _pm_10[1].update.avg = utils::getInvalidPmValue(); + _pm_10_sp[1].update.avg = utils::getInvalidPmValue(); + _pm_10_pc[1].update.avg = utils::getInvalidPmValue(); } void Measurements::maxPeriod(MeasurementType type, int max) { From 85ba13de129207ac65616eec5445b826b82e636b Mon Sep 17 00:00:00 2001 From: samuelbles07 Date: Wed, 5 Feb 2025 01:18:46 +0700 Subject: [PATCH 4/5] Set default ag client timeout to 15s --- src/AgApiClient.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/AgApiClient.h b/src/AgApiClient.h index 9f39ceb..8e52e76 100644 --- a/src/AgApiClient.h +++ b/src/AgApiClient.h @@ -31,7 +31,7 @@ private: bool getConfigFailed; bool postToServerFailed; bool notAvailableOnDashboard = false; // Device not setup on Airgradient cloud dashboard. - uint16_t timeoutMs = 10000; // Default set to 10s + uint16_t timeoutMs = 15000; // Default set to 15s public: AgApiClient(Stream &stream, Configuration &config); From 03f1b969c24f7d2ab762f52dbcdbddff4d6d935a Mon Sep 17 00:00:00 2001 From: samuelbles07 Date: Wed, 5 Feb 2025 01:24:59 +0700 Subject: [PATCH 5/5] Add comment describe two timeout functions call --- src/AgApiClient.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/AgApiClient.cpp b/src/AgApiClient.cpp index b2dbf1f..6eedcc9 100644 --- a/src/AgApiClient.cpp +++ b/src/AgApiClient.cpp @@ -58,8 +58,8 @@ bool AgApiClient::fetchServerConfiguration(void) { } #else HTTPClient client; - client.setTimeout(timeoutMs); - client.setConnectTimeout(timeoutMs); + client.setConnectTimeout(timeoutMs); // Set timeout when establishing connection to server + client.setTimeout(timeoutMs); // Timeout when waiting for response from AG server if (apiRootChanged) { // If apiRoot is changed, assume not using https if (client.begin(uri) == false) { @@ -134,8 +134,8 @@ bool AgApiClient::postToServer(String data) { } #else HTTPClient client; - client.setTimeout(timeoutMs); - client.setConnectTimeout(timeoutMs); + client.setConnectTimeout(timeoutMs); // Set timeout when establishing connection to server + client.setTimeout(timeoutMs); // Timeout when waiting for response from AG server if (apiRootChanged) { // If apiRoot is changed, assume not using https if (client.begin(uri) == false) {