mirror of
https://github.com/airgradienthq/arduino.git
synced 2025-07-22 21:17:16 +02:00
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.
This commit is contained in:
@ -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);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user