Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Standardize result of /measures/current #83

Merged
merged 1 commit into from Mar 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
66 changes: 54 additions & 12 deletions examples/ONE/ONE.ino
Expand Up @@ -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 */
Expand Down Expand Up @@ -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
*
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand All @@ -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);
}

Expand Down