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
|
|
|
|
2024-08-15 08:04:30 +07:00
|
|
|
#define json_prop_pmFirmware "firmware"
|
2024-08-07 08:50:43 +07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief Get PMS5003 firmware version string
|
|
|
|
|
*
|
|
|
|
|
* @param fwCode
|
|
|
|
|
* @return String
|
|
|
|
|
*/
|
|
|
|
|
String Measurements::pms5003FirmwareVersion(int fwCode) {
|
2024-08-16 06:42:43 +07:00
|
|
|
return pms5003FirmwareVersionBase("PMS5003x", fwCode);
|
2024-08-07 08:50:43 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief Get PMS5003T firmware version string
|
|
|
|
|
*
|
|
|
|
|
* @param fwCode
|
|
|
|
|
* @return String
|
|
|
|
|
*/
|
|
|
|
|
String Measurements::pms5003TFirmwareVersion(int fwCode) {
|
2024-08-16 06:42:43 +07:00
|
|
|
return pms5003FirmwareVersionBase("PMS5003x", fwCode);
|
2024-08-07 08:50:43 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief Get firmware version string
|
|
|
|
|
*
|
|
|
|
|
* @param prefix Prefix firmware string
|
|
|
|
|
* @param fwCode Version code
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
String Measurements::pms5003FirmwareVersionBase(String prefix, int fwCode) {
|
|
|
|
|
return prefix + String("-") + String(fwCode);
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-11 20:54:05 +07:00
|
|
|
String Measurements::agValueTypeStr(AgValueType type) {
|
|
|
|
|
String str;
|
|
|
|
|
switch (type) {
|
|
|
|
|
case AgValueType::Temperature:
|
|
|
|
|
str = "Temperature";
|
|
|
|
|
break;
|
|
|
|
|
case AgValueType::Humidity:
|
|
|
|
|
str = "Humidity";
|
|
|
|
|
break;
|
|
|
|
|
case AgValueType::CO2:
|
|
|
|
|
str = "CO2";
|
|
|
|
|
break;
|
|
|
|
|
case AgValueType::TVOC:
|
|
|
|
|
str = "TVOC";
|
|
|
|
|
break;
|
|
|
|
|
case AgValueType::TVOCRaw:
|
|
|
|
|
str = "TVOCRaw";
|
|
|
|
|
break;
|
|
|
|
|
case AgValueType::NOx:
|
|
|
|
|
str = "NOx";
|
|
|
|
|
break;
|
|
|
|
|
case AgValueType::NOxRaw:
|
|
|
|
|
str = "NOxRaw";
|
|
|
|
|
break;
|
|
|
|
|
case AgValueType::PM25:
|
|
|
|
|
str = "PM25";
|
|
|
|
|
break;
|
|
|
|
|
case AgValueType::PM01:
|
|
|
|
|
str = "PM01";
|
|
|
|
|
break;
|
|
|
|
|
case AgValueType::PM10:
|
|
|
|
|
str = "PM10";
|
|
|
|
|
break;
|
|
|
|
|
case AgValueType::PM03:
|
|
|
|
|
str = "PM03";
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return str;
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-11 22:05:03 +07:00
|
|
|
bool Measurements::updateValue(AgValueType type, int val) {
|
2024-10-11 20:54:05 +07:00
|
|
|
// Define data point source
|
|
|
|
|
IntegerValue *temporary = nullptr;
|
|
|
|
|
float invalidValue = 0;
|
|
|
|
|
switch (type) {
|
|
|
|
|
case AgValueType::CO2:
|
|
|
|
|
temporary = &_co2;
|
|
|
|
|
invalidValue = utils::getInvalidCO2();
|
|
|
|
|
break;
|
|
|
|
|
case AgValueType::TVOC:
|
|
|
|
|
temporary = &_tvoc;
|
|
|
|
|
invalidValue = utils::getInvalidVOC();
|
|
|
|
|
break;
|
|
|
|
|
case AgValueType::TVOCRaw:
|
|
|
|
|
temporary = &_tvoc_raw;
|
|
|
|
|
invalidValue = utils::getInvalidVOC();
|
|
|
|
|
break;
|
|
|
|
|
case AgValueType::NOx:
|
|
|
|
|
temporary = &_nox;
|
|
|
|
|
invalidValue = utils::getInvalidNOx();
|
|
|
|
|
break;
|
|
|
|
|
case AgValueType::NOxRaw:
|
|
|
|
|
temporary = &_nox_raw;
|
|
|
|
|
invalidValue = utils::getInvalidNOx();
|
|
|
|
|
break;
|
|
|
|
|
case AgValueType::PM25:
|
|
|
|
|
temporary = &_pm_25;
|
|
|
|
|
invalidValue = utils::getInvalidPmValue();
|
|
|
|
|
break;
|
|
|
|
|
case AgValueType::PM01:
|
|
|
|
|
temporary = &_pm_01;
|
|
|
|
|
invalidValue = utils::getInvalidPmValue();
|
|
|
|
|
break;
|
|
|
|
|
case AgValueType::PM10:
|
|
|
|
|
temporary = &_pm_10;
|
|
|
|
|
invalidValue = utils::getInvalidPmValue();
|
|
|
|
|
break;
|
|
|
|
|
case AgValueType::PM03:
|
|
|
|
|
temporary = &_pm_03_pc;
|
|
|
|
|
invalidValue = utils::getInvalidPmValue();
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Sanity check if agvaluetype is defined for integer data type or not
|
|
|
|
|
if (temporary == nullptr) {
|
|
|
|
|
Serial.printf("%s is not defined for integer data type\n", agValueTypeStr(type));
|
|
|
|
|
// TODO: Just assert?
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Update new value when value provided is not the invalid one
|
|
|
|
|
if (val != invalidValue) {
|
|
|
|
|
temporary->lastValue = val;
|
|
|
|
|
temporary->sumValues = temporary->sumValues + val;
|
2024-10-11 22:05:03 +07:00
|
|
|
temporary->update.success = temporary->update.success + 1;
|
2024-10-11 20:54:05 +07:00
|
|
|
}
|
|
|
|
|
|
2024-10-11 22:05:03 +07:00
|
|
|
// Increment update.counter
|
|
|
|
|
temporary->update.counter = temporary->update.counter + 1;
|
2024-10-11 20:54:05 +07:00
|
|
|
|
|
|
|
|
// Calculate value average when maximum set is reached
|
2024-10-11 22:05:03 +07:00
|
|
|
if (temporary->update.counter >= temporary->update.max) {
|
2024-10-11 20:54:05 +07:00
|
|
|
// Calculate the average
|
2024-10-11 22:05:03 +07:00
|
|
|
temporary->avg = temporary->sumValues / temporary->update.success;
|
2024-10-11 20:54:05 +07:00
|
|
|
|
|
|
|
|
// This is just for notifying
|
2024-10-11 22:05:03 +07:00
|
|
|
int miss = temporary->update.max - temporary->update.success;
|
2024-10-11 20:54:05 +07:00
|
|
|
if (miss != 0) {
|
2024-10-11 22:05:03 +07:00
|
|
|
Serial.printf("%s update.ng miss %d out of %d update\n", agValueTypeStr(type), miss,
|
|
|
|
|
temporary->update.max);
|
2024-10-11 20:54:05 +07:00
|
|
|
}
|
|
|
|
|
|
2024-10-11 22:05:03 +07:00
|
|
|
// Resets average related variable calculation
|
2024-10-11 20:54:05 +07:00
|
|
|
temporary->sumValues = 0;
|
2024-10-11 22:05:03 +07:00
|
|
|
temporary->update.counter = 0;
|
|
|
|
|
temporary->update.success = 0;
|
|
|
|
|
return true;
|
2024-10-11 20:54:05 +07:00
|
|
|
}
|
2024-10-11 22:05:03 +07:00
|
|
|
|
|
|
|
|
return false;
|
2024-10-11 20:54:05 +07:00
|
|
|
}
|
|
|
|
|
|
2024-10-11 22:05:03 +07:00
|
|
|
bool Measurements::updateValue(AgValueType type, float val) {
|
2024-10-11 20:54:05 +07:00
|
|
|
// Define data point source
|
|
|
|
|
FloatValue *temporary = nullptr;
|
|
|
|
|
float invalidValue = 0;
|
|
|
|
|
switch (type) {
|
|
|
|
|
case AgValueType::Temperature:
|
|
|
|
|
temporary = &_temperature;
|
|
|
|
|
invalidValue = utils::getInvalidTemperature();
|
|
|
|
|
break;
|
|
|
|
|
case AgValueType::Humidity:
|
|
|
|
|
temporary = &_humidity;
|
|
|
|
|
invalidValue = utils::getInvalidHumidity();
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Sanity check if agvaluetype is defined for float data type or not
|
|
|
|
|
if (temporary == nullptr) {
|
|
|
|
|
Serial.printf("%s is not defined for float data type\n", agValueTypeStr(type));
|
|
|
|
|
// TODO: Just assert?
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Update new value when value provided is not the invalid one
|
|
|
|
|
if (val != invalidValue) {
|
|
|
|
|
temporary->lastValue = val;
|
|
|
|
|
temporary->sumValues = temporary->sumValues + val;
|
2024-10-11 22:05:03 +07:00
|
|
|
temporary->update.success = temporary->update.success + 1;
|
2024-10-11 20:54:05 +07:00
|
|
|
}
|
|
|
|
|
|
2024-10-11 22:05:03 +07:00
|
|
|
// Increment update.counter
|
|
|
|
|
temporary->update.counter = temporary->update.counter + 1;
|
2024-10-11 20:54:05 +07:00
|
|
|
|
|
|
|
|
// Calculate value average when maximum set is reached
|
2024-10-11 22:05:03 +07:00
|
|
|
if (temporary->update.counter >= temporary->update.max) {
|
2024-10-11 20:54:05 +07:00
|
|
|
// Calculate the average
|
2024-10-11 22:05:03 +07:00
|
|
|
temporary->avg = temporary->sumValues / temporary->update.success;
|
2024-10-11 20:54:05 +07:00
|
|
|
|
|
|
|
|
// This is just for notifying
|
2024-10-11 22:05:03 +07:00
|
|
|
int miss = temporary->update.max - temporary->update.success;
|
2024-10-11 20:54:05 +07:00
|
|
|
if (miss != 0) {
|
2024-10-11 22:05:03 +07:00
|
|
|
Serial.printf("%s update.ng miss %d out of %d update\n", agValueTypeStr(type), miss,
|
|
|
|
|
temporary->update.max);
|
2024-10-11 20:54:05 +07:00
|
|
|
}
|
|
|
|
|
|
2024-10-11 22:05:03 +07:00
|
|
|
// Resets average related variable calculation
|
2024-10-11 20:54:05 +07:00
|
|
|
temporary->sumValues = 0;
|
2024-10-11 22:05:03 +07:00
|
|
|
temporary->update.counter = 0;
|
|
|
|
|
temporary->update.success = 0;
|
|
|
|
|
return true;
|
2024-10-11 20:54:05 +07:00
|
|
|
}
|
2024-10-11 22:05:03 +07:00
|
|
|
|
|
|
|
|
return false;
|
2024-10-11 20:54:05 +07:00
|
|
|
}
|
|
|
|
|
|
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();
|
|
|
|
|
}
|
2024-07-24 09:05:57 +07:00
|
|
|
|
|
|
|
|
if (config->hasSensorS8 && utils::isValidCO2(this->CO2)) {
|
|
|
|
|
root["rco2"] = this->CO2;
|
2024-04-07 16:39:01 +07:00
|
|
|
}
|
|
|
|
|
|
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-08-30 19:07:31 +07:00
|
|
|
if (utils::isValidPm(this->pm01_1)) {
|
2024-04-07 16:39:01 +07:00
|
|
|
root["pm01"] = this->pm01_1;
|
|
|
|
|
}
|
2024-08-30 19:07:31 +07:00
|
|
|
if (utils::isValidPm(this->pm25_1)) {
|
2024-04-07 16:39:01 +07:00
|
|
|
root["pm02"] = this->pm25_1;
|
|
|
|
|
}
|
2024-08-30 19:07:31 +07:00
|
|
|
if (utils::isValidPm(this->pm10_1)) {
|
2024-04-07 16:39:01 +07:00
|
|
|
root["pm10"] = this->pm10_1;
|
|
|
|
|
}
|
2024-08-30 19:07:31 +07:00
|
|
|
if (utils::isValidPm03Count(this->pm03PCount_1)) {
|
2024-04-14 22:15:37 +07:00
|
|
|
root["pm003Count"] = this->pm03PCount_1;
|
2024-04-07 16:39:01 +07:00
|
|
|
}
|
2024-08-07 08:50:43 +07:00
|
|
|
if (!localServer) {
|
|
|
|
|
|
2024-08-15 08:04:30 +07:00
|
|
|
root[json_prop_pmFirmware] =
|
2024-08-07 08:50:43 +07:00
|
|
|
this->pms5003FirmwareVersion(ag->pms5003.getFirmwareVersion());
|
|
|
|
|
}
|
2024-04-07 16:39:01 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (config->hasSensorSHT) {
|
2024-07-24 09:05:57 +07:00
|
|
|
if (utils::isValidTemperature(this->Temperature)) {
|
2024-04-07 16:39:01 +07:00
|
|
|
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
|
|
|
}
|
2024-07-24 09:05:57 +07:00
|
|
|
if (utils::isValidHumidity(this->Humidity)) {
|
2024-04-07 16:39:01 +07:00
|
|
|
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
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-21 07:13:34 +07:00
|
|
|
if (config->hasSensorSHT && config->hasSensorPMS1) {
|
2024-08-26 11:56:01 +07:00
|
|
|
int pm25 = ag->pms5003.compensate(this->pm25_1, this->Humidity);
|
2024-07-21 07:13:34 +07:00
|
|
|
if (pm25 >= 0) {
|
|
|
|
|
root["pm02Compensated"] = pm25;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-07 16:39:01 +07:00
|
|
|
} else {
|
|
|
|
|
if (config->hasSensorPMS1 && config->hasSensorPMS2) {
|
2024-08-30 19:07:31 +07:00
|
|
|
if (utils::isValidPm(this->pm01_1) && utils::isValidPm(this->pm01_2)) {
|
2024-07-24 09:05:57 +07:00
|
|
|
root["pm01"] = ag->round2((this->pm01_1 + this->pm01_2) / 2.0f);
|
|
|
|
|
}
|
2024-08-30 19:07:31 +07:00
|
|
|
if (utils::isValidPm(this->pm25_1) && utils::isValidPm(this->pm25_2)) {
|
2024-07-24 09:05:57 +07:00
|
|
|
root["pm02"] = ag->round2((this->pm25_1 + this->pm25_2) / 2.0f);
|
|
|
|
|
}
|
2024-08-30 19:07:31 +07:00
|
|
|
if (utils::isValidPm(this->pm10_1) && utils::isValidPm(this->pm10_2)) {
|
2024-07-24 09:05:57 +07:00
|
|
|
root["pm10"] = ag->round2((this->pm10_1 + this->pm10_2) / 2.0f);
|
|
|
|
|
}
|
2024-08-30 19:07:31 +07:00
|
|
|
if (utils::isValidPm(this->pm03PCount_1) && utils::isValidPm(this->pm03PCount_2)) {
|
2024-07-24 09:05:57 +07:00
|
|
|
root["pm003Count"] = ag->round2((this->pm03PCount_1 + this->pm03PCount_2) / 2.0f);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
float val;
|
|
|
|
|
if (utils::isValidTemperature(this->temp_1) && utils::isValidTemperature(this->temp_1)) {
|
|
|
|
|
root["atmp"] = ag->round2((this->temp_1 + this->temp_2) / 2.0f);
|
|
|
|
|
if (localServer) {
|
2024-08-30 19:17:58 +07:00
|
|
|
val = ag->pms5003t_2.compensateTemp((this->temp_1 + this->temp_2) / 2.0f);
|
2024-07-24 09:05:57 +07:00
|
|
|
if (utils::isValidTemperature(val)) {
|
|
|
|
|
root["atmpCompensated"] = ag->round2(val);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (utils::isValidHumidity(this->hum_1) && utils::isValidHumidity(this->hum_1)) {
|
|
|
|
|
root["rhum"] = ag->round2((this->hum_1 + this->hum_2) / 2.0f);
|
|
|
|
|
if (localServer) {
|
2024-08-30 19:17:58 +07:00
|
|
|
val = ag->pms5003t_2.compensateHum((this->hum_1 + this->hum_2) / 2.0f);
|
2024-07-24 09:05:57 +07:00
|
|
|
if (utils::isValidHumidity(val)) {
|
|
|
|
|
root["rhumCompensated"] = (int)val;
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-04-21 05:46:20 +07:00
|
|
|
}
|
2024-07-21 07:13:34 +07:00
|
|
|
|
2024-09-16 14:52:04 +07:00
|
|
|
int pm25 = (ag->pms5003t_1.compensate(this->pm25_1, this->hum_1) +
|
|
|
|
|
ag->pms5003t_2.compensate(this->pm25_2, this->hum_2)) /
|
2024-07-21 07:13:34 +07:00
|
|
|
2;
|
|
|
|
|
root["pm02Compensated"] = pm25;
|
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-07-24 09:05:57 +07:00
|
|
|
float val;
|
2024-04-07 16:39:01 +07:00
|
|
|
if (config->hasSensorPMS1) {
|
2024-08-30 19:07:31 +07:00
|
|
|
if (utils::isValidPm(this->pm01_1)) {
|
2024-07-24 09:05:57 +07:00
|
|
|
root["pm01"] = this->pm01_1;
|
|
|
|
|
}
|
2024-08-30 19:07:31 +07:00
|
|
|
if (utils::isValidPm(this->pm25_1)) {
|
2024-07-24 09:05:57 +07:00
|
|
|
root["pm02"] = this->pm25_1;
|
|
|
|
|
}
|
2024-08-30 19:07:31 +07:00
|
|
|
if (utils::isValidPm(this->pm10_1)) {
|
2024-07-24 09:05:57 +07:00
|
|
|
root["pm10"] = this->pm10_1;
|
|
|
|
|
}
|
2024-08-30 19:07:31 +07:00
|
|
|
if (utils::isValidPm03Count(this->pm03PCount_1)) {
|
2024-07-24 09:05:57 +07:00
|
|
|
root["pm003Count"] = this->pm03PCount_1;
|
|
|
|
|
}
|
|
|
|
|
if (utils::isValidTemperature(this->temp_1)) {
|
|
|
|
|
root["atmp"] = ag->round2(this->temp_1);
|
|
|
|
|
|
|
|
|
|
if (localServer) {
|
2024-08-30 19:17:58 +07:00
|
|
|
val = ag->pms5003t_1.compensateTemp(this->temp_1);
|
2024-07-24 09:05:57 +07:00
|
|
|
if (utils::isValidTemperature(val)) {
|
|
|
|
|
root["atmpCompensated"] = ag->round2(val);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (utils::isValidHumidity(this->hum_1)) {
|
|
|
|
|
root["rhum"] = this->hum_1;
|
|
|
|
|
|
|
|
|
|
if (localServer) {
|
2024-08-30 19:17:58 +07:00
|
|
|
val = ag->pms5003t_1.compensateHum(this->hum_1);
|
2024-07-24 09:05:57 +07:00
|
|
|
if (utils::isValidHumidity(val)) {
|
|
|
|
|
root["rhumCompensated"] = (int)val;
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-04-21 05:46:20 +07:00
|
|
|
}
|
2024-09-16 14:52:04 +07:00
|
|
|
root["pm02Compensated"] = ag->pms5003t_1.compensate(this->pm25_1, this->hum_1);
|
2024-07-29 13:20:07 +07:00
|
|
|
if (!localServer) {
|
2024-08-15 08:04:30 +07:00
|
|
|
root[json_prop_pmFirmware] =
|
2024-08-07 08:50:43 +07:00
|
|
|
pms5003TFirmwareVersion(ag->pms5003t_1.getFirmwareVersion());
|
2024-07-29 13:20:07 +07:00
|
|
|
}
|
2024-04-07 16:39:01 +07:00
|
|
|
}
|
|
|
|
|
if (config->hasSensorPMS2) {
|
2024-08-30 19:07:31 +07:00
|
|
|
if(utils::isValidPm(this->pm01_2)) {
|
2024-07-24 09:05:57 +07:00
|
|
|
root["pm01"] = this->pm01_2;
|
|
|
|
|
}
|
2024-08-30 19:07:31 +07:00
|
|
|
if(utils::isValidPm(this->pm25_2)) {
|
2024-07-24 09:05:57 +07:00
|
|
|
root["pm02"] = this->pm25_2;
|
|
|
|
|
}
|
2024-08-30 19:07:31 +07:00
|
|
|
if(utils::isValidPm(this->pm10_2)) {
|
2024-07-24 09:05:57 +07:00
|
|
|
root["pm10"] = this->pm10_2;
|
|
|
|
|
}
|
2024-08-30 19:07:31 +07:00
|
|
|
if(utils::isValidPm03Count(this->pm03PCount_2)) {
|
2024-07-24 09:05:57 +07:00
|
|
|
root["pm003Count"] = this->pm03PCount_2;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
float val;
|
|
|
|
|
if (utils::isValidTemperature(this->temp_2)) {
|
|
|
|
|
root["atmp"] = ag->round2(this->temp_2);
|
|
|
|
|
|
|
|
|
|
if (localServer) {
|
2024-08-30 19:17:58 +07:00
|
|
|
val = ag->pms5003t_2.compensateTemp(this->temp_2);
|
2024-07-24 09:05:57 +07:00
|
|
|
if (utils::isValidTemperature(val)) {
|
|
|
|
|
root["atmpCompensated"] = ag->round2(val);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if(utils::isValidHumidity(this->hum_2)) {
|
|
|
|
|
root["rhum"] = this->hum_2;
|
|
|
|
|
|
|
|
|
|
if (localServer) {
|
2024-08-30 19:17:58 +07:00
|
|
|
val = ag->pms5003t_2.compensateHum(this->hum_2);
|
2024-07-24 09:05:57 +07:00
|
|
|
if (utils::isValidHumidity(val)) {
|
|
|
|
|
root["rhumCompensated"] = (int)val;
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-04-21 05:46:20 +07:00
|
|
|
}
|
2024-09-16 14:52:04 +07:00
|
|
|
root["pm02Compensated"] = ag->pms5003t_2.compensate(this->pm25_2, this->hum_2);
|
2024-07-29 13:20:07 +07:00
|
|
|
if(!localServer) {
|
2024-08-15 08:04:30 +07:00
|
|
|
root[json_prop_pmFirmware] =
|
2024-08-07 08:50:43 +07:00
|
|
|
pms5003TFirmwareVersion(ag->pms5003t_1.getFirmwareVersion());
|
2024-07-29 13:20:07 +07:00
|
|
|
}
|
2024-04-07 16:39:01 +07:00
|
|
|
}
|
|
|
|
|
} else {
|
2024-04-13 21:07:20 +07:00
|
|
|
if (fwMode == FW_MODE_O_1P) {
|
2024-07-24 09:05:57 +07:00
|
|
|
float val;
|
2024-04-13 21:07:20 +07:00
|
|
|
if (config->hasSensorPMS1) {
|
2024-08-30 19:07:31 +07:00
|
|
|
if (utils::isValidPm(this->pm01_1)) {
|
2024-07-24 09:05:57 +07:00
|
|
|
root["pm01"] = this->pm01_1;
|
|
|
|
|
}
|
2024-08-30 19:07:31 +07:00
|
|
|
if (utils::isValidPm(this->pm25_1)) {
|
2024-07-24 09:05:57 +07:00
|
|
|
root["pm02"] = this->pm25_1;
|
|
|
|
|
}
|
2024-08-30 19:07:31 +07:00
|
|
|
if (utils::isValidPm(this->pm10_1)) {
|
2024-07-24 09:05:57 +07:00
|
|
|
root["pm10"] = this->pm10_1;
|
|
|
|
|
}
|
2024-08-30 19:07:31 +07:00
|
|
|
if (utils::isValidPm03Count(this->pm03PCount_1)) {
|
2024-07-24 09:05:57 +07:00
|
|
|
root["pm003Count"] = this->pm03PCount_1;
|
|
|
|
|
}
|
|
|
|
|
if (utils::isValidTemperature(this->temp_1)) {
|
|
|
|
|
root["atmp"] = ag->round2(this->temp_1);
|
|
|
|
|
|
|
|
|
|
if (localServer) {
|
2024-08-30 19:17:58 +07:00
|
|
|
val = ag->pms5003t_1.compensateTemp(this->temp_1);
|
2024-07-24 09:05:57 +07:00
|
|
|
if (utils::isValidTemperature(val)) {
|
|
|
|
|
root["atmpCompensated"] = ag->round2(val);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (utils::isValidHumidity(this->hum_1)) {
|
|
|
|
|
root["rhum"] = this->hum_1;
|
|
|
|
|
if(localServer) {
|
2024-08-30 19:17:58 +07:00
|
|
|
val = ag->pms5003t_1.compensateHum(this->hum_1);
|
2024-07-24 09:05:57 +07:00
|
|
|
if(utils::isValidHumidity(val)) {
|
|
|
|
|
root["rhumCompensated"] = (int)val;
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-04-21 05:46:20 +07:00
|
|
|
}
|
2024-09-16 14:52:04 +07:00
|
|
|
root["pm02Compensated"] = ag->pms5003t_1.compensate(this->pm25_1, this->hum_1);
|
2024-07-29 13:20:07 +07:00
|
|
|
if(!localServer) {
|
2024-08-15 08:04:30 +07:00
|
|
|
root[json_prop_pmFirmware] =
|
2024-08-07 08:50:43 +07:00
|
|
|
pms5003TFirmwareVersion(ag->pms5003t_1.getFirmwareVersion());
|
2024-07-29 13:20:07 +07:00
|
|
|
}
|
2024-04-13 21:07:20 +07:00
|
|
|
} else if (config->hasSensorPMS2) {
|
2024-08-30 19:07:31 +07:00
|
|
|
if(utils::isValidPm(this->pm01_2)) {
|
2024-07-24 09:05:57 +07:00
|
|
|
root["pm01"] = this->pm01_2;
|
|
|
|
|
}
|
2024-08-30 19:07:31 +07:00
|
|
|
if(utils::isValidPm(this->pm25_2)) {
|
2024-07-24 09:05:57 +07:00
|
|
|
root["pm02"] = this->pm25_2;
|
|
|
|
|
}
|
2024-08-30 19:07:31 +07:00
|
|
|
if(utils::isValidPm(this->pm10_2)) {
|
2024-07-24 09:05:57 +07:00
|
|
|
root["pm10"] = this->pm10_2;
|
|
|
|
|
}
|
2024-08-30 19:07:31 +07:00
|
|
|
if(utils::isValidPm03Count(this->pm03PCount_2)) {
|
2024-07-24 09:05:57 +07:00
|
|
|
root["pm003Count"] = this->pm03PCount_2;
|
|
|
|
|
}
|
|
|
|
|
if (utils::isValidTemperature(this->temp_2)) {
|
|
|
|
|
root["atmp"] = ag->round2(this->temp_2);
|
|
|
|
|
if (localServer) {
|
|
|
|
|
|
2024-08-30 19:17:58 +07:00
|
|
|
val = ag->pms5003t_1.compensateTemp(this->temp_2);
|
2024-07-24 09:05:57 +07:00
|
|
|
if (utils::isValidTemperature(val)) {
|
|
|
|
|
root["atmpCompensated"] = ag->round2(val);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (utils::isValidHumidity(this->hum_2)) {
|
|
|
|
|
root["rhum"] = this->hum_2;
|
|
|
|
|
|
|
|
|
|
if(localServer) {
|
2024-08-30 19:17:58 +07:00
|
|
|
val = ag->pms5003t_1.compensateHum(this->hum_2);
|
2024-07-24 09:05:57 +07:00
|
|
|
if(utils::isValidHumidity(val)) {
|
|
|
|
|
root["rhumCompensated"] = (int)val;
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-04-21 05:46:20 +07:00
|
|
|
}
|
2024-09-16 14:52:04 +07:00
|
|
|
root["pm02Compensated"] = ag->pms5003t_1.compensate(this->pm25_1, this->hum_1);
|
2024-07-29 13:20:07 +07:00
|
|
|
if(!localServer) {
|
2024-08-15 08:04:30 +07:00
|
|
|
root[json_prop_pmFirmware] =
|
2024-08-07 08:50:43 +07:00
|
|
|
pms5003TFirmwareVersion(ag->pms5003t_2.getFirmwareVersion());
|
2024-07-29 13:20:07 +07:00
|
|
|
}
|
2024-04-07 16:39:01 +07:00
|
|
|
}
|
2024-04-13 21:07:20 +07:00
|
|
|
} else {
|
2024-07-24 09:05:57 +07:00
|
|
|
float val;
|
2024-04-13 21:07:20 +07:00
|
|
|
if (config->hasSensorPMS1) {
|
2024-08-30 19:07:31 +07:00
|
|
|
if(utils::isValidPm(this->pm01_1)) {
|
2024-07-24 09:05:57 +07:00
|
|
|
root["channels"]["1"]["pm01"] = this->pm01_1;
|
|
|
|
|
}
|
2024-08-30 19:07:31 +07:00
|
|
|
if(utils::isValidPm(this->pm25_1)) {
|
2024-07-24 09:05:57 +07:00
|
|
|
root["channels"]["1"]["pm02"] = this->pm25_1;
|
|
|
|
|
}
|
2024-08-30 19:07:31 +07:00
|
|
|
if(utils::isValidPm(this->pm10_1)) {
|
2024-07-24 09:05:57 +07:00
|
|
|
root["channels"]["1"]["pm10"] = this->pm10_1;
|
|
|
|
|
}
|
2024-08-30 19:07:31 +07:00
|
|
|
if (utils::isValidPm03Count(this->pm03PCount_1)) {
|
2024-07-24 09:05:57 +07:00
|
|
|
root["channels"]["1"]["pm003Count"] = this->pm03PCount_1;
|
|
|
|
|
}
|
|
|
|
|
if(utils::isValidTemperature(this->temp_1)) {
|
|
|
|
|
root["channels"]["1"]["atmp"] = ag->round2(this->temp_1);
|
|
|
|
|
|
|
|
|
|
if (localServer) {
|
2024-08-30 19:17:58 +07:00
|
|
|
val = ag->pms5003t_1.compensateTemp(this->temp_1);
|
2024-07-24 09:05:57 +07:00
|
|
|
if (utils::isValidTemperature(val)) {
|
|
|
|
|
root["channels"]["1"]["atmpCompensated"] = ag->round2(val);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (utils::isValidHumidity(this->hum_1)) {
|
|
|
|
|
root["channels"]["1"]["rhum"] = this->hum_1;
|
|
|
|
|
|
|
|
|
|
if (localServer) {
|
2024-08-30 19:17:58 +07:00
|
|
|
val = ag->pms5003t_1.compensateHum(this->hum_1);
|
2024-07-24 09:05:57 +07:00
|
|
|
if (utils::isValidHumidity(val)) {
|
|
|
|
|
root["channels"]["1"]["rhumCompensated"] = (int)val;
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-04-21 05:46:20 +07:00
|
|
|
}
|
2024-09-16 14:52:04 +07:00
|
|
|
root["channels"]["1"]["pm02Compensated"] = ag->pms5003t_1.compensate(this->pm25_1, this->hum_1);
|
2024-07-29 13:20:07 +07:00
|
|
|
|
|
|
|
|
// PMS5003T version
|
|
|
|
|
if(!localServer) {
|
2024-08-15 08:04:30 +07:00
|
|
|
root["channels"]["1"][json_prop_pmFirmware] =
|
2024-08-07 08:50:43 +07:00
|
|
|
pms5003TFirmwareVersion(ag->pms5003t_1.getFirmwareVersion());
|
2024-07-29 13:20:07 +07:00
|
|
|
}
|
2024-05-13 18:25:03 +07:00
|
|
|
}
|
|
|
|
|
if (config->hasSensorPMS2) {
|
2024-07-24 09:05:57 +07:00
|
|
|
float val;
|
2024-08-30 19:07:31 +07:00
|
|
|
if (utils::isValidPm(this->pm01_2)) {
|
2024-07-24 09:05:57 +07:00
|
|
|
root["channels"]["2"]["pm01"] = this->pm01_2;
|
|
|
|
|
}
|
2024-08-30 19:07:31 +07:00
|
|
|
if (utils::isValidPm(this->pm25_2)) {
|
2024-07-24 09:05:57 +07:00
|
|
|
root["channels"]["2"]["pm02"] = this->pm25_2;
|
|
|
|
|
}
|
2024-08-30 19:07:31 +07:00
|
|
|
if (utils::isValidPm(this->pm10_2)) {
|
2024-07-24 09:05:57 +07:00
|
|
|
root["channels"]["2"]["pm10"] = this->pm10_2;
|
|
|
|
|
}
|
2024-08-30 19:07:31 +07:00
|
|
|
if (utils::isValidPm03Count(this->pm03PCount_2)) {
|
2024-07-24 09:05:57 +07:00
|
|
|
root["channels"]["2"]["pm003Count"] = this->pm03PCount_2;
|
|
|
|
|
}
|
|
|
|
|
if (utils::isValidTemperature(this->temp_2)) {
|
|
|
|
|
root["channels"]["2"]["atmp"] = ag->round2(this->temp_2);
|
|
|
|
|
|
|
|
|
|
if (localServer) {
|
2024-08-30 19:17:58 +07:00
|
|
|
val = ag->pms5003t_1.compensateTemp(this->temp_2);
|
2024-07-24 09:05:57 +07:00
|
|
|
if (utils::isValidTemperature(val)) {
|
|
|
|
|
root["channels"]["2"]["atmpCompensated"] = ag->round2(val);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (utils::isValidHumidity(this->hum_2)) {
|
|
|
|
|
root["channels"]["2"]["rhum"] = this->hum_2;
|
|
|
|
|
|
|
|
|
|
if (localServer) {
|
2024-08-30 19:17:58 +07:00
|
|
|
val = ag->pms5003t_1.compensateHum(this->hum_2);
|
2024-07-24 09:05:57 +07:00
|
|
|
if (utils::isValidHumidity(val)) {
|
|
|
|
|
root["channels"]["2"]["rhumCompensated"] = (int)val;
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-04-21 05:46:20 +07:00
|
|
|
}
|
2024-09-16 14:52:04 +07:00
|
|
|
root["channels"]["2"]["pm02Compensated"] = ag->pms5003t_2.compensate(this->pm25_2, this->hum_2);
|
2024-07-29 13:20:07 +07:00
|
|
|
// PMS5003T version
|
|
|
|
|
if(!localServer) {
|
2024-08-15 08:04:30 +07:00
|
|
|
root["channels"]["2"][json_prop_pmFirmware] =
|
2024-08-07 08:50:43 +07:00
|
|
|
pms5003TFirmwareVersion(ag->pms5003t_2.getFirmwareVersion());
|
2024-07-29 13:20:07 +07:00
|
|
|
}
|
2024-04-07 16:39:01 +07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (config->hasSensorSGP) {
|
2024-07-24 09:05:57 +07:00
|
|
|
if (utils::isValidVOC(this->TVOC)) {
|
2024-04-14 22:15:37 +07:00
|
|
|
root["tvocIndex"] = this->TVOC;
|
2024-04-07 16:39:01 +07:00
|
|
|
}
|
2024-07-24 09:05:57 +07:00
|
|
|
if (utils::isValidVOC(this->TVOCRaw)) {
|
2024-04-14 22:15:37 +07:00
|
|
|
root["tvocRaw"] = this->TVOCRaw;
|
2024-04-07 16:39:01 +07:00
|
|
|
}
|
2024-07-24 09:05:57 +07:00
|
|
|
if (utils::isValidNOx(this->NOx)) {
|
2024-04-14 22:15:37 +07:00
|
|
|
root["noxIndex"] = this->NOx;
|
2024-04-07 16:39:01 +07:00
|
|
|
}
|
2024-07-24 09:05:57 +07:00
|
|
|
if (utils::isValidNOx(this->NOxRaw)) {
|
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);
|
|
|
|
|
}
|