2024-04-07 16:39:01 +07:00
|
|
|
#include "AgValue.h"
|
|
|
|
#include "AgConfigure.h"
|
|
|
|
#include "AirGradient.h"
|
2024-04-11 09:29:29 +07:00
|
|
|
#include "Libraries/Arduino_JSON/src/Arduino_JSON.h"
|
2024-04-07 16:39:01 +07:00
|
|
|
|
|
|
|
String Measurements::toString(bool localServer, AgFirmwareMode fwMode, int rssi,
|
|
|
|
void *_ag, void *_config) {
|
|
|
|
AirGradient *ag = (AirGradient *)_ag;
|
|
|
|
Configuration *config = (Configuration *)_config;
|
|
|
|
|
|
|
|
JSONVar root;
|
|
|
|
root["wifi"] = rssi;
|
|
|
|
if (localServer) {
|
|
|
|
root["serialno"] = ag->deviceId();
|
|
|
|
}
|
|
|
|
if (config->hasSensorS8) {
|
|
|
|
if (this->CO2 >= 0) {
|
|
|
|
root["rco2"] = this->CO2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-06-25 16:43:50 +07:00
|
|
|
if (ag->isOne() || (ag->isPro4_2()) || ag->isPro3_3() || ag->isBasic()) {
|
2024-06-18 19:59:29 +07:00
|
|
|
if (config->hasSensorPMS1) {
|
2024-04-07 16:39:01 +07:00
|
|
|
if (this->pm01_1 >= 0) {
|
|
|
|
root["pm01"] = this->pm01_1;
|
|
|
|
}
|
|
|
|
if (this->pm25_1 >= 0) {
|
|
|
|
root["pm02"] = this->pm25_1;
|
|
|
|
}
|
|
|
|
if (this->pm10_1 >= 0) {
|
|
|
|
root["pm10"] = this->pm10_1;
|
|
|
|
}
|
|
|
|
if (this->pm03PCount_1 >= 0) {
|
2024-04-14 22:15:37 +07:00
|
|
|
root["pm003Count"] = this->pm03PCount_1;
|
2024-04-07 16:39:01 +07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (config->hasSensorSHT) {
|
|
|
|
if (this->Temperature > -1001) {
|
|
|
|
root["atmp"] = ag->round2(this->Temperature);
|
2024-04-21 05:46:20 +07:00
|
|
|
if (localServer) {
|
|
|
|
root["atmpCompensated"] = ag->round2(this->Temperature);
|
|
|
|
}
|
2024-04-07 16:39:01 +07:00
|
|
|
}
|
|
|
|
if (this->Humidity >= 0) {
|
|
|
|
root["rhum"] = this->Humidity;
|
2024-04-21 05:46:20 +07:00
|
|
|
if (localServer) {
|
|
|
|
root["rhumCompensated"] = this->Humidity;
|
|
|
|
}
|
2024-04-07 16:39:01 +07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
if (config->hasSensorPMS1 && config->hasSensorPMS2) {
|
|
|
|
root["pm01"] = ag->round2((this->pm01_1 + this->pm01_2) / 2.0);
|
|
|
|
root["pm02"] = ag->round2((this->pm25_1 + this->pm25_2) / 2.0);
|
|
|
|
root["pm10"] = ag->round2((this->pm10_1 + this->pm10_2) / 2.0);
|
2024-04-14 22:15:37 +07:00
|
|
|
root["pm003Count"] =
|
|
|
|
ag->round2((this->pm03PCount_1 + this->pm03PCount_2) / 2.0);
|
2024-04-13 20:39:05 +07:00
|
|
|
root["atmp"] = ag->round2((this->temp_1 + this->temp_2) / 2.0f);
|
|
|
|
root["rhum"] = ag->round2((this->hum_1 + this->hum_2) / 2.0f);
|
2024-04-21 05:46:20 +07:00
|
|
|
if (localServer) {
|
|
|
|
root["atmpCompensated"] =
|
|
|
|
ag->round2(ag->pms5003t_2.temperatureCompensated(
|
|
|
|
(this->temp_1 + this->temp_2) / 2.0f));
|
|
|
|
root["rhumCompensated"] = (int)ag->pms5003t_2.humidityCompensated(
|
|
|
|
(this->hum_1 + this->hum_2) / 2.0f);
|
|
|
|
}
|
2024-04-07 16:39:01 +07:00
|
|
|
}
|
|
|
|
|
2024-04-13 20:50:11 +07:00
|
|
|
if (fwMode == FW_MODE_O_1PS || fwMode == FW_MODE_O_1PST) {
|
2024-04-07 16:39:01 +07:00
|
|
|
if (config->hasSensorPMS1) {
|
|
|
|
root["pm01"] = this->pm01_1;
|
|
|
|
root["pm02"] = this->pm25_1;
|
|
|
|
root["pm10"] = this->pm10_1;
|
2024-04-14 22:15:37 +07:00
|
|
|
root["pm003Count"] = this->pm03PCount_1;
|
2024-04-07 16:39:01 +07:00
|
|
|
root["atmp"] = ag->round2(this->temp_1);
|
|
|
|
root["rhum"] = this->hum_1;
|
2024-04-21 05:46:20 +07:00
|
|
|
if (localServer) {
|
|
|
|
root["atmpCompensated"] =
|
|
|
|
ag->round2(ag->pms5003t_1.temperatureCompensated(this->temp_1));
|
|
|
|
root["rhumCompensated"] =
|
|
|
|
(int)ag->pms5003t_1.humidityCompensated(this->hum_1);
|
|
|
|
}
|
2024-04-07 16:39:01 +07:00
|
|
|
}
|
|
|
|
if (config->hasSensorPMS2) {
|
|
|
|
root["pm01"] = this->pm01_2;
|
|
|
|
root["pm02"] = this->pm25_2;
|
|
|
|
root["pm10"] = this->pm10_2;
|
2024-04-14 22:15:37 +07:00
|
|
|
root["pm003Count"] = this->pm03PCount_2;
|
2024-04-07 16:39:01 +07:00
|
|
|
root["atmp"] = ag->round2(this->temp_2);
|
|
|
|
root["rhum"] = this->hum_2;
|
2024-04-21 05:46:20 +07:00
|
|
|
if (localServer) {
|
|
|
|
root["atmpCompensated"] =
|
|
|
|
ag->round2(ag->pms5003t_2.temperatureCompensated(this->temp_2));
|
|
|
|
root["rhumCompensated"] =
|
|
|
|
(int)ag->pms5003t_2.humidityCompensated(this->hum_2);
|
|
|
|
}
|
2024-04-07 16:39:01 +07:00
|
|
|
}
|
|
|
|
} else {
|
2024-04-13 21:07:20 +07:00
|
|
|
if (fwMode == FW_MODE_O_1P) {
|
|
|
|
if (config->hasSensorPMS1) {
|
|
|
|
root["pm01"] = this->pm01_1;
|
|
|
|
root["pm02"] = this->pm25_1;
|
|
|
|
root["pm10"] = this->pm10_1;
|
2024-04-14 22:15:37 +07:00
|
|
|
root["pm003Count"] = this->pm03PCount_1;
|
2024-04-13 21:07:20 +07:00
|
|
|
root["atmp"] = ag->round2(this->temp_1);
|
|
|
|
root["rhum"] = this->hum_1;
|
2024-04-21 05:46:20 +07:00
|
|
|
if (localServer) {
|
|
|
|
root["atmpCompensated"] =
|
|
|
|
ag->round2(ag->pms5003t_1.temperatureCompensated(this->temp_1));
|
|
|
|
root["rhumCompensated"] =
|
|
|
|
(int)ag->pms5003t_1.humidityCompensated(this->hum_1);
|
|
|
|
}
|
2024-04-13 21:07:20 +07:00
|
|
|
} else if (config->hasSensorPMS2) {
|
|
|
|
root["pm01"] = this->pm01_2;
|
|
|
|
root["pm02"] = this->pm25_2;
|
|
|
|
root["pm10"] = this->pm10_2;
|
2024-04-14 22:15:37 +07:00
|
|
|
root["pm003Count"] = this->pm03PCount_2;
|
2024-04-13 21:07:20 +07:00
|
|
|
root["atmp"] = ag->round2(this->temp_2);
|
|
|
|
root["rhum"] = this->hum_2;
|
2024-04-21 05:46:20 +07:00
|
|
|
if (localServer) {
|
|
|
|
root["atmpCompensated"] =
|
|
|
|
ag->round2(ag->pms5003t_1.temperatureCompensated(this->temp_2));
|
|
|
|
root["rhumCompensated"] =
|
|
|
|
(int)ag->pms5003t_1.humidityCompensated(this->hum_2);
|
|
|
|
}
|
2024-04-07 16:39:01 +07:00
|
|
|
}
|
2024-04-13 21:07:20 +07:00
|
|
|
} else {
|
|
|
|
if (config->hasSensorPMS1) {
|
|
|
|
root["channels"]["1"]["pm01"] = this->pm01_1;
|
|
|
|
root["channels"]["1"]["pm02"] = this->pm25_1;
|
|
|
|
root["channels"]["1"]["pm10"] = this->pm10_1;
|
2024-04-14 22:15:37 +07:00
|
|
|
root["channels"]["1"]["pm003Count"] = this->pm03PCount_1;
|
2024-04-13 21:07:20 +07:00
|
|
|
root["channels"]["1"]["atmp"] = ag->round2(this->temp_1);
|
|
|
|
root["channels"]["1"]["rhum"] = this->hum_1;
|
2024-04-21 05:46:20 +07:00
|
|
|
if (localServer) {
|
|
|
|
root["channels"]["1"]["atmpCompensated"] =
|
|
|
|
ag->round2(ag->pms5003t_1.temperatureCompensated(this->temp_1));
|
|
|
|
root["channels"]["1"]["rhumCompensated"] =
|
|
|
|
(int)ag->pms5003t_1.humidityCompensated(this->hum_1);
|
|
|
|
}
|
2024-05-13 18:25:03 +07:00
|
|
|
}
|
|
|
|
if (config->hasSensorPMS2) {
|
2024-04-13 21:07:20 +07:00
|
|
|
root["channels"]["2"]["pm01"] = this->pm01_2;
|
|
|
|
root["channels"]["2"]["pm02"] = this->pm25_2;
|
|
|
|
root["channels"]["2"]["pm10"] = this->pm10_2;
|
2024-04-14 22:15:37 +07:00
|
|
|
root["channels"]["2"]["pm003Count"] = this->pm03PCount_2;
|
2024-04-13 21:07:20 +07:00
|
|
|
root["channels"]["2"]["atmp"] = ag->round2(this->temp_2);
|
|
|
|
root["channels"]["2"]["rhum"] = this->hum_2;
|
2024-04-21 05:46:20 +07:00
|
|
|
if (localServer) {
|
|
|
|
root["channels"]["2"]["atmpCompensated"] =
|
|
|
|
ag->round2(ag->pms5003t_1.temperatureCompensated(this->temp_2));
|
|
|
|
root["channels"]["2"]["rhumCompensated"] =
|
|
|
|
(int)ag->pms5003t_1.humidityCompensated(this->hum_2);
|
|
|
|
}
|
2024-04-07 16:39:01 +07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (config->hasSensorSGP) {
|
|
|
|
if (this->TVOC >= 0) {
|
2024-04-14 22:15:37 +07:00
|
|
|
root["tvocIndex"] = this->TVOC;
|
2024-04-07 16:39:01 +07:00
|
|
|
}
|
|
|
|
if (this->TVOCRaw >= 0) {
|
2024-04-14 22:15:37 +07:00
|
|
|
root["tvocRaw"] = this->TVOCRaw;
|
2024-04-07 16:39:01 +07:00
|
|
|
}
|
|
|
|
if (this->NOx >= 0) {
|
2024-04-14 22:15:37 +07:00
|
|
|
root["noxIndex"] = this->NOx;
|
2024-04-07 16:39:01 +07:00
|
|
|
}
|
|
|
|
if (this->NOxRaw >= 0) {
|
2024-04-14 22:15:37 +07:00
|
|
|
root["noxRaw"] = this->NOxRaw;
|
2024-04-07 16:39:01 +07:00
|
|
|
}
|
|
|
|
}
|
2024-05-18 21:19:40 -05:00
|
|
|
root["boot"] = bootCount;
|
2024-06-04 22:17:20 +07:00
|
|
|
root["bootCount"] = bootCount;
|
2024-04-07 16:39:01 +07:00
|
|
|
|
|
|
|
if (localServer) {
|
2024-06-24 18:34:24 +07:00
|
|
|
if (ag->isOne()) {
|
|
|
|
root["ledMode"] = config->getLedBarModeName();
|
|
|
|
}
|
2024-04-21 05:46:20 +07:00
|
|
|
root["firmware"] = ag->getVersion();
|
|
|
|
root["model"] = AgFirmwareModeName(fwMode);
|
2024-04-07 16:39:01 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
return JSON.stringify(root);
|
|
|
|
}
|