From ed1d45cea1d325d38d285c8dbc53f76d61f6a3e7 Mon Sep 17 00:00:00 2001 From: Etienne Dechamps Date: Sun, 10 Mar 2024 11:02:04 +0000 Subject: [PATCH 1/2] Fix OpenMetrics typo: celcius -> celsius See #78 --- examples/ONE/ONE.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/ONE/ONE.ino b/examples/ONE/ONE.ino index 8768adc3..391673fc 100644 --- a/examples/ONE/ONE.ino +++ b/examples/ONE/ONE.ino @@ -1065,7 +1065,7 @@ void webServerMetricsGet(void) { add_metric("temperature", "The ambient temperature as measured by the AirGradient SHT " "sensor, in degrees Celsius", - "gauge", "celcius"); + "gauge", "celsius"); add_metric_point("", String(temp)); } if (hum >= 0) { From 49c7877ec3d178dc0c88401e1c7f8b7d888663b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20Austvik?= Date: Fri, 15 Mar 2024 19:22:00 +0100 Subject: [PATCH 2/2] Standardize result of /measures/current Makes it easier for integrations which talks both to the cloud and to the Cloud API to support the same format for reading current measures. In practice this adds the firmware version and led mode to the output, and changes the writing of pm003Count, tvocIndex and noxIndex to use the same spelling as for the documented cloud API. --- examples/ONE/ONE.ino | 66 ++++++++++++++++++++++++++++++++++++-------- 1 file changed, 54 insertions(+), 12 deletions(-) diff --git a/examples/ONE/ONE.ino b/examples/ONE/ONE.ino index 8768adc3..c41c5082 100644 --- a/examples/ONE/ONE.ino +++ b/examples/ONE/ONE.ino @@ -243,15 +243,7 @@ public: uint8_t ledBarMode = UseLedBarOff; if (JSON.typeof_(root["ledBarMode"]) == "string") { String mode = root["ledBarMode"]; - if (mode == "co2") { - ledBarMode = UseLedBarCO2; - } else if (mode == "pm") { - ledBarMode = UseLedBarPM; - } else if (mode == "off") { - ledBarMode = UseLedBarOff; - } else { - ledBarMode = UseLedBarOff; - } + ledBarMode = parseLedBarMode(mode); } /** Get model */ @@ -446,6 +438,24 @@ public: */ UseLedBar getLedBarMode(void) { return (UseLedBar)config.useRGBLedBar; } + /** + * @brief Return the name of the led bare mode. + * + * @return String + */ + String getLedBarModeName(void) { + UseLedBar ledBarMode = getLedBarMode(); + if (ledBarMode == UseLedBarOff) { + return String("off"); + } else if (ledBarMode == UseLedBarPM) { + return String("pm"); + } else if (ledBarMode == UseLedBarCO2) { + return String("co2"); + } else { + return String("off"); + } + } + /** * @brief Get the Country * @@ -516,6 +526,21 @@ private: EEPROM.commit(); Serial.println("Save config"); } + + UseLedBar parseLedBarMode(String mode) { + UseLedBar ledBarMode = UseLedBarOff; + if (mode == "co2") { + ledBarMode = UseLedBarCO2; + } else if (mode == "pm") { + ledBarMode = UseLedBarPM; + } else if (mode == "off") { + ledBarMode = UseLedBarOff; + } else { + ledBarMode = UseLedBarOff; + } + + return ledBarMode; + } }; AgServer agServer; @@ -1135,18 +1160,30 @@ static String getServerSyncData(bool localServer) { root["pm10"] = pm10; } if (pm03PCount >= 0) { - root["pm003_count"] = pm03PCount; + if (localServer) { + root["pm003Count"] = pm03PCount; + } else { + root["pm003_count"] = pm03PCount; + } } } if (hasSensorSGP) { if (tvocIndex >= 0) { - root["tvoc_index"] = tvocIndex; + if (localServer) { + root["tvocIndex"] = tvocIndex; + } else { + root["tvoc_index"] = tvocIndex; + } } if (tvocRawIndex >= 0) { root["tvoc_raw"] = tvocRawIndex; } if (noxIndex >= 0) { - root["nox_index"] = noxIndex; + if (localServer) { + root["noxIndex"] = noxIndex; + } else { + root["nox_index"] = noxIndex; + } } if (noxRawIndex >= 0) { root["nox_raw"] = noxRawIndex; @@ -1162,6 +1199,11 @@ static String getServerSyncData(bool localServer) { } root["boot"] = bootCount; + if (localServer) { + root["ledMode"] = agServer.getLedBarModeName(); + root["firmwareVersion"] = ag.getVersion(); + } + return JSON.stringify(root); }