ignore compensated value send to AG server. And udpate JSON properties

This commit is contained in:
Phat Nguyen
2024-04-21 05:46:20 +07:00
parent 4063536078
commit a2b30a5467

View File

@ -38,13 +38,17 @@ String Measurements::toString(bool localServer, AgFirmwareMode fwMode, int rssi,
if (config->hasSensorSHT) { if (config->hasSensorSHT) {
if (this->Temperature > -1001) { if (this->Temperature > -1001) {
root["atmp"] = ag->round2(this->Temperature); root["atmp"] = ag->round2(this->Temperature);
if (localServer) {
root["atmpCompensated"] = ag->round2(this->Temperature); root["atmpCompensated"] = ag->round2(this->Temperature);
} }
}
if (this->Humidity >= 0) { if (this->Humidity >= 0) {
root["rhum"] = this->Humidity; root["rhum"] = this->Humidity;
if (localServer) {
root["rhumCompensated"] = this->Humidity; root["rhumCompensated"] = this->Humidity;
} }
} }
}
} else { } else {
if (config->hasSensorPMS1 && config->hasSensorPMS2) { if (config->hasSensorPMS1 && config->hasSensorPMS2) {
@ -55,12 +59,14 @@ String Measurements::toString(bool localServer, AgFirmwareMode fwMode, int rssi,
ag->round2((this->pm03PCount_1 + this->pm03PCount_2) / 2.0); ag->round2((this->pm03PCount_1 + this->pm03PCount_2) / 2.0);
root["atmp"] = ag->round2((this->temp_1 + this->temp_2) / 2.0f); root["atmp"] = ag->round2((this->temp_1 + this->temp_2) / 2.0f);
root["rhum"] = ag->round2((this->hum_1 + this->hum_2) / 2.0f); root["rhum"] = ag->round2((this->hum_1 + this->hum_2) / 2.0f);
if (localServer) {
root["atmpCompensated"] = root["atmpCompensated"] =
ag->round2(ag->pms5003t_2.temperatureCompensated( ag->round2(ag->pms5003t_2.temperatureCompensated(
(this->temp_1 + this->temp_2) / 2.0f)); (this->temp_1 + this->temp_2) / 2.0f));
root["rhumCompensated"] = (int)ag->pms5003t_2.humidityCompensated( root["rhumCompensated"] = (int)ag->pms5003t_2.humidityCompensated(
(this->hum_1 + this->hum_2) / 2.0f); (this->hum_1 + this->hum_2) / 2.0f);
} }
}
if (fwMode == FW_MODE_O_1PS || fwMode == FW_MODE_O_1PST) { if (fwMode == FW_MODE_O_1PS || fwMode == FW_MODE_O_1PST) {
if (config->hasSensorPMS1) { if (config->hasSensorPMS1) {
@ -70,11 +76,13 @@ String Measurements::toString(bool localServer, AgFirmwareMode fwMode, int rssi,
root["pm003Count"] = this->pm03PCount_1; root["pm003Count"] = this->pm03PCount_1;
root["atmp"] = ag->round2(this->temp_1); root["atmp"] = ag->round2(this->temp_1);
root["rhum"] = this->hum_1; root["rhum"] = this->hum_1;
if (localServer) {
root["atmpCompensated"] = root["atmpCompensated"] =
ag->round2(ag->pms5003t_1.temperatureCompensated(this->temp_1)); ag->round2(ag->pms5003t_1.temperatureCompensated(this->temp_1));
root["rhumCompensated"] = root["rhumCompensated"] =
(int)ag->pms5003t_1.humidityCompensated(this->hum_1); (int)ag->pms5003t_1.humidityCompensated(this->hum_1);
} }
}
if (config->hasSensorPMS2) { if (config->hasSensorPMS2) {
root["pm01"] = this->pm01_2; root["pm01"] = this->pm01_2;
root["pm02"] = this->pm25_2; root["pm02"] = this->pm25_2;
@ -82,11 +90,13 @@ String Measurements::toString(bool localServer, AgFirmwareMode fwMode, int rssi,
root["pm003Count"] = this->pm03PCount_2; root["pm003Count"] = this->pm03PCount_2;
root["atmp"] = ag->round2(this->temp_2); root["atmp"] = ag->round2(this->temp_2);
root["rhum"] = this->hum_2; root["rhum"] = this->hum_2;
if (localServer) {
root["atmpCompensated"] = root["atmpCompensated"] =
ag->round2(ag->pms5003t_2.temperatureCompensated(this->temp_2)); ag->round2(ag->pms5003t_2.temperatureCompensated(this->temp_2));
root["rhumCompensated"] = root["rhumCompensated"] =
(int)ag->pms5003t_2.humidityCompensated(this->hum_2); (int)ag->pms5003t_2.humidityCompensated(this->hum_2);
} }
}
} else { } else {
if (fwMode == FW_MODE_O_1P) { if (fwMode == FW_MODE_O_1P) {
if (config->hasSensorPMS1) { if (config->hasSensorPMS1) {
@ -96,10 +106,12 @@ String Measurements::toString(bool localServer, AgFirmwareMode fwMode, int rssi,
root["pm003Count"] = this->pm03PCount_1; root["pm003Count"] = this->pm03PCount_1;
root["atmp"] = ag->round2(this->temp_1); root["atmp"] = ag->round2(this->temp_1);
root["rhum"] = this->hum_1; root["rhum"] = this->hum_1;
if (localServer) {
root["atmpCompensated"] = root["atmpCompensated"] =
ag->round2(ag->pms5003t_1.temperatureCompensated(this->temp_1)); ag->round2(ag->pms5003t_1.temperatureCompensated(this->temp_1));
root["rhumCompensated"] = root["rhumCompensated"] =
(int)ag->pms5003t_1.humidityCompensated(this->hum_1); (int)ag->pms5003t_1.humidityCompensated(this->hum_1);
}
} else if (config->hasSensorPMS2) { } else if (config->hasSensorPMS2) {
root["pm01"] = this->pm01_2; root["pm01"] = this->pm01_2;
root["pm02"] = this->pm25_2; root["pm02"] = this->pm25_2;
@ -107,11 +119,13 @@ String Measurements::toString(bool localServer, AgFirmwareMode fwMode, int rssi,
root["pm003Count"] = this->pm03PCount_2; root["pm003Count"] = this->pm03PCount_2;
root["atmp"] = ag->round2(this->temp_2); root["atmp"] = ag->round2(this->temp_2);
root["rhum"] = this->hum_2; root["rhum"] = this->hum_2;
if (localServer) {
root["atmpCompensated"] = root["atmpCompensated"] =
ag->round2(ag->pms5003t_1.temperatureCompensated(this->temp_2)); ag->round2(ag->pms5003t_1.temperatureCompensated(this->temp_2));
root["rhumCompensated"] = root["rhumCompensated"] =
(int)ag->pms5003t_1.humidityCompensated(this->hum_2); (int)ag->pms5003t_1.humidityCompensated(this->hum_2);
} }
}
} else { } else {
if (config->hasSensorPMS1) { if (config->hasSensorPMS1) {
root["channels"]["1"]["pm01"] = this->pm01_1; root["channels"]["1"]["pm01"] = this->pm01_1;
@ -120,10 +134,12 @@ String Measurements::toString(bool localServer, AgFirmwareMode fwMode, int rssi,
root["channels"]["1"]["pm003Count"] = this->pm03PCount_1; root["channels"]["1"]["pm003Count"] = this->pm03PCount_1;
root["channels"]["1"]["atmp"] = ag->round2(this->temp_1); root["channels"]["1"]["atmp"] = ag->round2(this->temp_1);
root["channels"]["1"]["rhum"] = this->hum_1; root["channels"]["1"]["rhum"] = this->hum_1;
if (localServer) {
root["channels"]["1"]["atmpCompensated"] = root["channels"]["1"]["atmpCompensated"] =
ag->round2(ag->pms5003t_1.temperatureCompensated(this->temp_1)); ag->round2(ag->pms5003t_1.temperatureCompensated(this->temp_1));
root["channels"]["1"]["rhumCompensated"] = root["channels"]["1"]["rhumCompensated"] =
(int)ag->pms5003t_1.humidityCompensated(this->hum_1); (int)ag->pms5003t_1.humidityCompensated(this->hum_1);
}
} else if (config->hasSensorPMS2) { } else if (config->hasSensorPMS2) {
root["channels"]["2"]["pm01"] = this->pm01_2; root["channels"]["2"]["pm01"] = this->pm01_2;
root["channels"]["2"]["pm02"] = this->pm25_2; root["channels"]["2"]["pm02"] = this->pm25_2;
@ -131,6 +147,7 @@ String Measurements::toString(bool localServer, AgFirmwareMode fwMode, int rssi,
root["channels"]["2"]["pm003Count"] = this->pm03PCount_2; root["channels"]["2"]["pm003Count"] = this->pm03PCount_2;
root["channels"]["2"]["atmp"] = ag->round2(this->temp_2); root["channels"]["2"]["atmp"] = ag->round2(this->temp_2);
root["channels"]["2"]["rhum"] = this->hum_2; root["channels"]["2"]["rhum"] = this->hum_2;
if (localServer) {
root["channels"]["2"]["atmpCompensated"] = root["channels"]["2"]["atmpCompensated"] =
ag->round2(ag->pms5003t_1.temperatureCompensated(this->temp_2)); ag->round2(ag->pms5003t_1.temperatureCompensated(this->temp_2));
root["channels"]["2"]["rhumCompensated"] = root["channels"]["2"]["rhumCompensated"] =
@ -139,6 +156,7 @@ String Measurements::toString(bool localServer, AgFirmwareMode fwMode, int rssi,
} }
} }
} }
}
if (config->hasSensorSGP) { if (config->hasSensorSGP) {
if (this->TVOC >= 0) { if (this->TVOC >= 0) {
@ -154,12 +172,12 @@ String Measurements::toString(bool localServer, AgFirmwareMode fwMode, int rssi,
root["noxRaw"] = this->NOxRaw; root["noxRaw"] = this->NOxRaw;
} }
} }
root["boot"] = bootCount; root["bootCount"] = bootCount;
if (localServer) { if (localServer) {
root["ledMode"] = config->getLedBarModeName(); root["ledMode"] = config->getLedBarModeName();
root["firmwareVersion"] = ag->getVersion(); root["firmware"] = ag->getVersion();
root["fwMode"] = AgFirmwareModeName(fwMode); root["model"] = AgFirmwareModeName(fwMode);
} }
return JSON.stringify(root); return JSON.stringify(root);