Merge pull request #224 from airgradienthq/hotfix/pms25-compensated-show-on-display

[Fix] PM2.5 compensated show on display
This commit is contained in:
AirGradient
2024-09-02 12:09:51 +07:00
committed by GitHub
14 changed files with 84 additions and 79 deletions

View File

@ -89,28 +89,28 @@ String OpenMetrics::getPayload(void) {
} }
if (config.hasSensorPMS1) { if (config.hasSensorPMS1) {
if (utils::isValidPMS(pm01)) { if (utils::isValidPm(pm01)) {
add_metric("pm1", add_metric("pm1",
"PM1.0 concentration as measured by the AirGradient PMS " "PM1.0 concentration as measured by the AirGradient PMS "
"sensor, in micrograms per cubic meter", "sensor, in micrograms per cubic meter",
"gauge", "ugm3"); "gauge", "ugm3");
add_metric_point("", String(pm01)); add_metric_point("", String(pm01));
} }
if (utils::isValidPMS(pm25)) { if (utils::isValidPm(pm25)) {
add_metric("pm2d5", add_metric("pm2d5",
"PM2.5 concentration as measured by the AirGradient PMS " "PM2.5 concentration as measured by the AirGradient PMS "
"sensor, in micrograms per cubic meter", "sensor, in micrograms per cubic meter",
"gauge", "ugm3"); "gauge", "ugm3");
add_metric_point("", String(pm25)); add_metric_point("", String(pm25));
} }
if (utils::isValidPMS(pm10)) { if (utils::isValidPm(pm10)) {
add_metric("pm10", add_metric("pm10",
"PM10 concentration as measured by the AirGradient PMS " "PM10 concentration as measured by the AirGradient PMS "
"sensor, in micrograms per cubic meter", "sensor, in micrograms per cubic meter",
"gauge", "ugm3"); "gauge", "ugm3");
add_metric_point("", String(pm10)); add_metric_point("", String(pm10));
} }
if (utils::isValidPMS03Count(pm03PCount)) { if (utils::isValidPm03Count(pm03PCount)) {
add_metric("pm0d3", add_metric("pm0d3",
"PM0.3 concentration as measured by the AirGradient PMS " "PM0.3 concentration as measured by the AirGradient PMS "
"sensor, in number of particules per 100 milliliters", "sensor, in number of particules per 100 milliliters",

View File

@ -89,28 +89,28 @@ String OpenMetrics::getPayload(void) {
} }
if (config.hasSensorPMS1) { if (config.hasSensorPMS1) {
if (utils::isValidPMS(pm01)) { if (utils::isValidPm(pm01)) {
add_metric("pm1", add_metric("pm1",
"PM1.0 concentration as measured by the AirGradient PMS " "PM1.0 concentration as measured by the AirGradient PMS "
"sensor, in micrograms per cubic meter", "sensor, in micrograms per cubic meter",
"gauge", "ugm3"); "gauge", "ugm3");
add_metric_point("", String(pm01)); add_metric_point("", String(pm01));
} }
if (utils::isValidPMS(pm25)) { if (utils::isValidPm(pm25)) {
add_metric("pm2d5", add_metric("pm2d5",
"PM2.5 concentration as measured by the AirGradient PMS " "PM2.5 concentration as measured by the AirGradient PMS "
"sensor, in micrograms per cubic meter", "sensor, in micrograms per cubic meter",
"gauge", "ugm3"); "gauge", "ugm3");
add_metric_point("", String(pm25)); add_metric_point("", String(pm25));
} }
if (utils::isValidPMS(pm10)) { if (utils::isValidPm(pm10)) {
add_metric("pm10", add_metric("pm10",
"PM10 concentration as measured by the AirGradient PMS " "PM10 concentration as measured by the AirGradient PMS "
"sensor, in micrograms per cubic meter", "sensor, in micrograms per cubic meter",
"gauge", "ugm3"); "gauge", "ugm3");
add_metric_point("", String(pm10)); add_metric_point("", String(pm10));
} }
if (utils::isValidPMS03Count(pm03PCount)) { if (utils::isValidPm03Count(pm03PCount)) {
add_metric("pm0d3", add_metric("pm0d3",
"PM0.3 concentration as measured by the AirGradient PMS " "PM0.3 concentration as measured by the AirGradient PMS "
"sensor, in number of particules per 100 milliliters", "sensor, in number of particules per 100 milliliters",

View File

@ -89,28 +89,28 @@ String OpenMetrics::getPayload(void) {
} }
if (config.hasSensorPMS1) { if (config.hasSensorPMS1) {
if (utils::isValidPMS(pm01)) { if (utils::isValidPm(pm01)) {
add_metric("pm1", add_metric("pm1",
"PM1.0 concentration as measured by the AirGradient PMS " "PM1.0 concentration as measured by the AirGradient PMS "
"sensor, in micrograms per cubic meter", "sensor, in micrograms per cubic meter",
"gauge", "ugm3"); "gauge", "ugm3");
add_metric_point("", String(pm01)); add_metric_point("", String(pm01));
} }
if (utils::isValidPMS(pm25)) { if (utils::isValidPm(pm25)) {
add_metric("pm2d5", add_metric("pm2d5",
"PM2.5 concentration as measured by the AirGradient PMS " "PM2.5 concentration as measured by the AirGradient PMS "
"sensor, in micrograms per cubic meter", "sensor, in micrograms per cubic meter",
"gauge", "ugm3"); "gauge", "ugm3");
add_metric_point("", String(pm25)); add_metric_point("", String(pm25));
} }
if (utils::isValidPMS(pm10)) { if (utils::isValidPm(pm10)) {
add_metric("pm10", add_metric("pm10",
"PM10 concentration as measured by the AirGradient PMS " "PM10 concentration as measured by the AirGradient PMS "
"sensor, in micrograms per cubic meter", "sensor, in micrograms per cubic meter",
"gauge", "ugm3"); "gauge", "ugm3");
add_metric_point("", String(pm10)); add_metric_point("", String(pm10));
} }
if (utils::isValidPMS03Count(pm03PCount)) { if (utils::isValidPm03Count(pm03PCount)) {
add_metric("pm0d3", add_metric("pm0d3",
"PM0.3 concentration as measured by the AirGradient PMS " "PM0.3 concentration as measured by the AirGradient PMS "
"sensor, in number of particules per 100 milliliters", "sensor, in number of particules per 100 milliliters",

View File

@ -123,28 +123,28 @@ String OpenMetrics::getPayload(void) {
} }
if (config.hasSensorPMS1 || config.hasSensorPMS2) { if (config.hasSensorPMS1 || config.hasSensorPMS2) {
if (utils::isValidPMS(pm01)) { if (utils::isValidPm(pm01)) {
add_metric("pm1", add_metric("pm1",
"PM1.0 concentration as measured by the AirGradient PMS " "PM1.0 concentration as measured by the AirGradient PMS "
"sensor, in micrograms per cubic meter", "sensor, in micrograms per cubic meter",
"gauge", "ugm3"); "gauge", "ugm3");
add_metric_point("", String(pm01)); add_metric_point("", String(pm01));
} }
if (utils::isValidPMS(pm25)) { if (utils::isValidPm(pm25)) {
add_metric("pm2d5", add_metric("pm2d5",
"PM2.5 concentration as measured by the AirGradient PMS " "PM2.5 concentration as measured by the AirGradient PMS "
"sensor, in micrograms per cubic meter", "sensor, in micrograms per cubic meter",
"gauge", "ugm3"); "gauge", "ugm3");
add_metric_point("", String(pm25)); add_metric_point("", String(pm25));
} }
if (utils::isValidPMS(pm10)) { if (utils::isValidPm(pm10)) {
add_metric("pm10", add_metric("pm10",
"PM10 concentration as measured by the AirGradient PMS " "PM10 concentration as measured by the AirGradient PMS "
"sensor, in micrograms per cubic meter", "sensor, in micrograms per cubic meter",
"gauge", "ugm3"); "gauge", "ugm3");
add_metric_point("", String(pm10)); add_metric_point("", String(pm10));
} }
if (utils::isValidPMS03Count(pm03PCount)) { if (utils::isValidPm03Count(pm03PCount)) {
add_metric("pm0d3", add_metric("pm0d3",
"PM0.3 concentration as measured by the AirGradient PMS " "PM0.3 concentration as measured by the AirGradient PMS "
"sensor, in number of particules per 100 milliliters", "sensor, in number of particules per 100 milliliters",

View File

@ -306,12 +306,13 @@ void OledDisplay::showDashboard(const char *status) {
/** Draw PM2.5 value */ /** Draw PM2.5 value */
int pm25 = value.pm25_1; int pm25 = value.pm25_1;
if (config.hasSensorSHT) { if (config.hasSensorSHT) {
pm25 = ag->pms5003.compensated(pm25, value.Humidity); pm25 = ag->pms5003.compensate(pm25, value.Humidity);
logInfo("PM2.5:" + String(value.pm25_1) + String("Compensated:") + String(pm25));
} }
DISP()->setFont(u8g2_font_t0_22b_tf); DISP()->setFont(u8g2_font_t0_22b_tf);
if (config.isPmStandardInUSAQI()) { if (config.isPmStandardInUSAQI()) {
if (utils::isValidPMS(value.pm25_1)) { if (utils::isValidPm(pm25)) {
sprintf(strBuf, "%d", ag->pms5003.convertPm25ToUsAqi(value.pm25_1)); sprintf(strBuf, "%d", ag->pms5003.convertPm25ToUsAqi(pm25));
} else { } else {
sprintf(strBuf, "%s", "-"); sprintf(strBuf, "%s", "-");
} }
@ -319,8 +320,8 @@ void OledDisplay::showDashboard(const char *status) {
DISP()->setFont(u8g2_font_t0_12_tf); DISP()->setFont(u8g2_font_t0_12_tf);
DISP()->drawUTF8(55, 61, "AQI"); DISP()->drawUTF8(55, 61, "AQI");
} else { } else {
if (utils::isValidPMS(value.pm25_1)) { if (utils::isValidPm(pm25)) {
sprintf(strBuf, "%d", value.pm25_1); sprintf(strBuf, "%d", pm25);
} else { } else {
sprintf(strBuf, "%s", "-"); sprintf(strBuf, "%s", "-");
} }
@ -366,11 +367,11 @@ void OledDisplay::showDashboard(const char *status) {
/** Set PM */ /** Set PM */
int pm25 = value.pm25_1; int pm25 = value.pm25_1;
if(config.hasSensorSHT) { if(config.hasSensorSHT) {
pm25 = (int)ag->pms5003.compensated(pm25, value.Humidity); pm25 = (int)ag->pms5003.compensate(pm25, value.Humidity);
} }
ag->display.setCursor(0, 12); ag->display.setCursor(0, 12);
if (utils::isValidPMS(value.pm25_1)) { if (utils::isValidPm(pm25)) {
snprintf(strBuf, sizeof(strBuf), "PM2.5:%d", value.pm25_1); snprintf(strBuf, sizeof(strBuf), "PM2.5:%d", pm25);
} else { } else {
snprintf(strBuf, sizeof(strBuf), "PM2.5:-"); snprintf(strBuf, sizeof(strBuf), "PM2.5:-");
} }

View File

@ -54,16 +54,16 @@ String Measurements::toString(bool localServer, AgFirmwareMode fwMode, int rssi,
if (ag->isOne() || (ag->isPro4_2()) || ag->isPro3_3() || ag->isBasic()) { if (ag->isOne() || (ag->isPro4_2()) || ag->isPro3_3() || ag->isBasic()) {
if (config->hasSensorPMS1) { if (config->hasSensorPMS1) {
if (utils::isValidPMS(this->pm01_1)) { if (utils::isValidPm(this->pm01_1)) {
root["pm01"] = this->pm01_1; root["pm01"] = this->pm01_1;
} }
if (utils::isValidPMS(this->pm25_1)) { if (utils::isValidPm(this->pm25_1)) {
root["pm02"] = this->pm25_1; root["pm02"] = this->pm25_1;
} }
if (utils::isValidPMS(this->pm10_1)) { if (utils::isValidPm(this->pm10_1)) {
root["pm10"] = this->pm10_1; root["pm10"] = this->pm10_1;
} }
if (utils::isValidPMS03Count(this->pm03PCount_1)) { if (utils::isValidPm03Count(this->pm03PCount_1)) {
root["pm003Count"] = this->pm03PCount_1; root["pm003Count"] = this->pm03PCount_1;
} }
if (!localServer) { if (!localServer) {
@ -89,7 +89,7 @@ String Measurements::toString(bool localServer, AgFirmwareMode fwMode, int rssi,
} }
if (config->hasSensorSHT && config->hasSensorPMS1) { if (config->hasSensorSHT && config->hasSensorPMS1) {
int pm25 = ag->pms5003.compensated(this->pm25_1, this->Humidity); int pm25 = ag->pms5003.compensate(this->pm25_1, this->Humidity);
if (pm25 >= 0) { if (pm25 >= 0) {
root["pm02Compensated"] = pm25; root["pm02Compensated"] = pm25;
} }
@ -97,16 +97,16 @@ String Measurements::toString(bool localServer, AgFirmwareMode fwMode, int rssi,
} else { } else {
if (config->hasSensorPMS1 && config->hasSensorPMS2) { if (config->hasSensorPMS1 && config->hasSensorPMS2) {
if (utils::isValidPMS(this->pm01_1) && utils::isValidPMS(this->pm01_2)) { if (utils::isValidPm(this->pm01_1) && utils::isValidPm(this->pm01_2)) {
root["pm01"] = ag->round2((this->pm01_1 + this->pm01_2) / 2.0f); root["pm01"] = ag->round2((this->pm01_1 + this->pm01_2) / 2.0f);
} }
if (utils::isValidPMS(this->pm25_1) && utils::isValidPMS(this->pm25_2)) { if (utils::isValidPm(this->pm25_1) && utils::isValidPm(this->pm25_2)) {
root["pm02"] = ag->round2((this->pm25_1 + this->pm25_2) / 2.0f); root["pm02"] = ag->round2((this->pm25_1 + this->pm25_2) / 2.0f);
} }
if (utils::isValidPMS(this->pm10_1) && utils::isValidPMS(this->pm10_2)) { if (utils::isValidPm(this->pm10_1) && utils::isValidPm(this->pm10_2)) {
root["pm10"] = ag->round2((this->pm10_1 + this->pm10_2) / 2.0f); root["pm10"] = ag->round2((this->pm10_1 + this->pm10_2) / 2.0f);
} }
if (utils::isValidPMS(this->pm03PCount_1) && utils::isValidPMS(this->pm03PCount_2)) { if (utils::isValidPm(this->pm03PCount_1) && utils::isValidPm(this->pm03PCount_2)) {
root["pm003Count"] = ag->round2((this->pm03PCount_1 + this->pm03PCount_2) / 2.0f); root["pm003Count"] = ag->round2((this->pm03PCount_1 + this->pm03PCount_2) / 2.0f);
} }
@ -130,8 +130,8 @@ String Measurements::toString(bool localServer, AgFirmwareMode fwMode, int rssi,
} }
} }
int pm25 = (ag->pms5003t_1.compensated(this->pm25_1, this->temp_1) + int pm25 = (ag->pms5003t_1.compensate(this->pm25_1, this->temp_1) +
ag->pms5003t_2.compensated(this->pm25_2, this->temp_2)) / ag->pms5003t_2.compensate(this->pm25_2, this->temp_2)) /
2; 2;
root["pm02Compensated"] = pm25; root["pm02Compensated"] = pm25;
} }
@ -139,16 +139,16 @@ String Measurements::toString(bool localServer, AgFirmwareMode fwMode, int rssi,
if (fwMode == FW_MODE_O_1PS || fwMode == FW_MODE_O_1PST) { if (fwMode == FW_MODE_O_1PS || fwMode == FW_MODE_O_1PST) {
float val; float val;
if (config->hasSensorPMS1) { if (config->hasSensorPMS1) {
if (utils::isValidPMS(this->pm01_1)) { if (utils::isValidPm(this->pm01_1)) {
root["pm01"] = this->pm01_1; root["pm01"] = this->pm01_1;
} }
if (utils::isValidPMS(this->pm25_1)) { if (utils::isValidPm(this->pm25_1)) {
root["pm02"] = this->pm25_1; root["pm02"] = this->pm25_1;
} }
if (utils::isValidPMS(this->pm10_1)) { if (utils::isValidPm(this->pm10_1)) {
root["pm10"] = this->pm10_1; root["pm10"] = this->pm10_1;
} }
if (utils::isValidPMS03Count(this->pm03PCount_1)) { if (utils::isValidPm03Count(this->pm03PCount_1)) {
root["pm003Count"] = this->pm03PCount_1; root["pm003Count"] = this->pm03PCount_1;
} }
if (utils::isValidTemperature(this->temp_1)) { if (utils::isValidTemperature(this->temp_1)) {
@ -171,23 +171,23 @@ String Measurements::toString(bool localServer, AgFirmwareMode fwMode, int rssi,
} }
} }
} }
root["pm02Compensated"] = ag->pms5003t_1.compensated(this->pm25_1, this->temp_1); root["pm02Compensated"] = ag->pms5003t_1.compensate(this->pm25_1, this->temp_1);
if (!localServer) { if (!localServer) {
root[json_prop_pmFirmware] = root[json_prop_pmFirmware] =
pms5003TFirmwareVersion(ag->pms5003t_1.getFirmwareVersion()); pms5003TFirmwareVersion(ag->pms5003t_1.getFirmwareVersion());
} }
} }
if (config->hasSensorPMS2) { if (config->hasSensorPMS2) {
if(utils::isValidPMS(this->pm01_2)) { if(utils::isValidPm(this->pm01_2)) {
root["pm01"] = this->pm01_2; root["pm01"] = this->pm01_2;
} }
if(utils::isValidPMS(this->pm25_2)) { if(utils::isValidPm(this->pm25_2)) {
root["pm02"] = this->pm25_2; root["pm02"] = this->pm25_2;
} }
if(utils::isValidPMS(this->pm10_2)) { if(utils::isValidPm(this->pm10_2)) {
root["pm10"] = this->pm10_2; root["pm10"] = this->pm10_2;
} }
if(utils::isValidPMS03Count(this->pm03PCount_2)) { if(utils::isValidPm03Count(this->pm03PCount_2)) {
root["pm003Count"] = this->pm03PCount_2; root["pm003Count"] = this->pm03PCount_2;
} }
@ -212,7 +212,7 @@ String Measurements::toString(bool localServer, AgFirmwareMode fwMode, int rssi,
} }
} }
} }
root["pm02Compensated"] = ag->pms5003t_2.compensated(this->pm25_2, this->temp_2); root["pm02Compensated"] = ag->pms5003t_2.compensate(this->pm25_2, this->temp_2);
if(!localServer) { if(!localServer) {
root[json_prop_pmFirmware] = root[json_prop_pmFirmware] =
pms5003TFirmwareVersion(ag->pms5003t_1.getFirmwareVersion()); pms5003TFirmwareVersion(ag->pms5003t_1.getFirmwareVersion());
@ -222,16 +222,16 @@ String Measurements::toString(bool localServer, AgFirmwareMode fwMode, int rssi,
if (fwMode == FW_MODE_O_1P) { if (fwMode == FW_MODE_O_1P) {
float val; float val;
if (config->hasSensorPMS1) { if (config->hasSensorPMS1) {
if (utils::isValidPMS(this->pm01_1)) { if (utils::isValidPm(this->pm01_1)) {
root["pm01"] = this->pm01_1; root["pm01"] = this->pm01_1;
} }
if (utils::isValidPMS(this->pm25_1)) { if (utils::isValidPm(this->pm25_1)) {
root["pm02"] = this->pm25_1; root["pm02"] = this->pm25_1;
} }
if (utils::isValidPMS(this->pm10_1)) { if (utils::isValidPm(this->pm10_1)) {
root["pm10"] = this->pm10_1; root["pm10"] = this->pm10_1;
} }
if (utils::isValidPMS03Count(this->pm03PCount_1)) { if (utils::isValidPm03Count(this->pm03PCount_1)) {
root["pm003Count"] = this->pm03PCount_1; root["pm003Count"] = this->pm03PCount_1;
} }
if (utils::isValidTemperature(this->temp_1)) { if (utils::isValidTemperature(this->temp_1)) {
@ -253,22 +253,22 @@ String Measurements::toString(bool localServer, AgFirmwareMode fwMode, int rssi,
} }
} }
} }
root["pm02Compensated"] = ag->pms5003t_1.compensated(this->pm25_1, this->temp_1); root["pm02Compensated"] = ag->pms5003t_1.compensate(this->pm25_1, this->temp_1);
if(!localServer) { if(!localServer) {
root[json_prop_pmFirmware] = root[json_prop_pmFirmware] =
pms5003TFirmwareVersion(ag->pms5003t_1.getFirmwareVersion()); pms5003TFirmwareVersion(ag->pms5003t_1.getFirmwareVersion());
} }
} else if (config->hasSensorPMS2) { } else if (config->hasSensorPMS2) {
if(utils::isValidPMS(this->pm01_2)) { if(utils::isValidPm(this->pm01_2)) {
root["pm01"] = this->pm01_2; root["pm01"] = this->pm01_2;
} }
if(utils::isValidPMS(this->pm25_2)) { if(utils::isValidPm(this->pm25_2)) {
root["pm02"] = this->pm25_2; root["pm02"] = this->pm25_2;
} }
if(utils::isValidPMS(this->pm10_2)) { if(utils::isValidPm(this->pm10_2)) {
root["pm10"] = this->pm10_2; root["pm10"] = this->pm10_2;
} }
if(utils::isValidPMS03Count(this->pm03PCount_2)) { if(utils::isValidPm03Count(this->pm03PCount_2)) {
root["pm003Count"] = this->pm03PCount_2; root["pm003Count"] = this->pm03PCount_2;
} }
if (utils::isValidTemperature(this->temp_2)) { if (utils::isValidTemperature(this->temp_2)) {
@ -291,7 +291,7 @@ String Measurements::toString(bool localServer, AgFirmwareMode fwMode, int rssi,
} }
} }
} }
root["pm02Compensated"] = ag->pms5003t_1.compensated(this->pm25_1, this->temp_1); root["pm02Compensated"] = ag->pms5003t_1.compensate(this->pm25_1, this->temp_1);
if(!localServer) { if(!localServer) {
root[json_prop_pmFirmware] = root[json_prop_pmFirmware] =
pms5003TFirmwareVersion(ag->pms5003t_2.getFirmwareVersion()); pms5003TFirmwareVersion(ag->pms5003t_2.getFirmwareVersion());
@ -300,16 +300,16 @@ String Measurements::toString(bool localServer, AgFirmwareMode fwMode, int rssi,
} else { } else {
float val; float val;
if (config->hasSensorPMS1) { if (config->hasSensorPMS1) {
if(utils::isValidPMS(this->pm01_1)) { if(utils::isValidPm(this->pm01_1)) {
root["channels"]["1"]["pm01"] = this->pm01_1; root["channels"]["1"]["pm01"] = this->pm01_1;
} }
if(utils::isValidPMS(this->pm25_1)) { if(utils::isValidPm(this->pm25_1)) {
root["channels"]["1"]["pm02"] = this->pm25_1; root["channels"]["1"]["pm02"] = this->pm25_1;
} }
if(utils::isValidPMS(this->pm10_1)) { if(utils::isValidPm(this->pm10_1)) {
root["channels"]["1"]["pm10"] = this->pm10_1; root["channels"]["1"]["pm10"] = this->pm10_1;
} }
if (utils::isValidPMS03Count(this->pm03PCount_1)) { if (utils::isValidPm03Count(this->pm03PCount_1)) {
root["channels"]["1"]["pm003Count"] = this->pm03PCount_1; root["channels"]["1"]["pm003Count"] = this->pm03PCount_1;
} }
if(utils::isValidTemperature(this->temp_1)) { if(utils::isValidTemperature(this->temp_1)) {
@ -332,7 +332,7 @@ String Measurements::toString(bool localServer, AgFirmwareMode fwMode, int rssi,
} }
} }
} }
root["channels"]["1"]["pm02Compensated"] = ag->pms5003t_1.compensated(this->pm25_1, this->temp_1); root["channels"]["1"]["pm02Compensated"] = ag->pms5003t_1.compensate(this->pm25_1, this->temp_1);
// PMS5003T version // PMS5003T version
if(!localServer) { if(!localServer) {
@ -342,16 +342,16 @@ String Measurements::toString(bool localServer, AgFirmwareMode fwMode, int rssi,
} }
if (config->hasSensorPMS2) { if (config->hasSensorPMS2) {
float val; float val;
if (utils::isValidPMS(this->pm01_2)) { if (utils::isValidPm(this->pm01_2)) {
root["channels"]["2"]["pm01"] = this->pm01_2; root["channels"]["2"]["pm01"] = this->pm01_2;
} }
if (utils::isValidPMS(this->pm25_2)) { if (utils::isValidPm(this->pm25_2)) {
root["channels"]["2"]["pm02"] = this->pm25_2; root["channels"]["2"]["pm02"] = this->pm25_2;
} }
if (utils::isValidPMS(this->pm10_2)) { if (utils::isValidPm(this->pm10_2)) {
root["channels"]["2"]["pm10"] = this->pm10_2; root["channels"]["2"]["pm10"] = this->pm10_2;
} }
if (utils::isValidPMS03Count(this->pm03PCount_2)) { if (utils::isValidPm03Count(this->pm03PCount_2)) {
root["channels"]["2"]["pm003Count"] = this->pm03PCount_2; root["channels"]["2"]["pm003Count"] = this->pm03PCount_2;
} }
if (utils::isValidTemperature(this->temp_2)) { if (utils::isValidTemperature(this->temp_2)) {
@ -374,7 +374,7 @@ String Measurements::toString(bool localServer, AgFirmwareMode fwMode, int rssi,
} }
} }
} }
root["channels"]["2"]["pm02Compensated"] = ag->pms5003t_2.compensated(this->pm25_2, this->temp_2); root["channels"]["2"]["pm02Compensated"] = ag->pms5003t_2.compensate(this->pm25_2, this->temp_2);
// PMS5003T version // PMS5003T version
if(!localServer) { if(!localServer) {
root["channels"]["2"][json_prop_pmFirmware] = root["channels"]["2"][json_prop_pmFirmware] =

View File

@ -48,14 +48,14 @@ bool utils::isValidCO2(int16_t value) {
return false; return false;
} }
bool utils::isValidPMS(int value) { bool utils::isValidPm(int value) {
if ((value >= VALID_PMS_MIN) && (value <= VALID_PMS_MAX)) { if ((value >= VALID_PMS_MIN) && (value <= VALID_PMS_MAX)) {
return true; return true;
} }
return false; return false;
} }
bool utils::isValidPMS03Count(int value) { bool utils::isValidPm03Count(int value) {
if (value >= VALID_PMS03COUNT_MIN) { if (value >= VALID_PMS03COUNT_MIN) {
return true; return true;
} }

View File

@ -14,8 +14,8 @@ public:
static bool isValidTemperature(float value); static bool isValidTemperature(float value);
static bool isValidHumidity(float value); static bool isValidHumidity(float value);
static bool isValidCO2(int16_t value); static bool isValidCO2(int16_t value);
static bool isValidPMS(int value); static bool isValidPm(int value);
static bool isValidPMS03Count(int value); static bool isValidPm03Count(int value);
static bool isValidNOx(int value); static bool isValidNOx(int value);
static bool isValidVOC(int value); static bool isValidVOC(int value);
static float getInvalidTemperature(void); static float getInvalidTemperature(void);

View File

@ -315,7 +315,7 @@ int PMSBase::pm25ToAQI(int pm02) {
* @param humidity Humidity value (%) * @param humidity Humidity value (%)
* @return int * @return int
*/ */
int PMSBase::compensated(int pm25, float humidity) { int PMSBase::compensate(int pm25, float humidity) {
float value; float value;
float fpm25 = pm25; float fpm25 = pm25;
if (humidity < 0) { if (humidity < 0) {

View File

@ -36,7 +36,7 @@ public:
uint8_t getErrorCode(void); uint8_t getErrorCode(void);
int pm25ToAQI(int pm02); int pm25ToAQI(int pm02);
int compensated(int pm25, float humidity); int compensate(int pm25, float humidity);
private: private:
Stream *stream; Stream *stream;

View File

@ -124,12 +124,14 @@ int PMS5003::convertPm25ToUsAqi(int pm25) { return pms.pm25ToAQI(pm25); }
/** /**
* @brief Correct PM2.5 * @brief Correct PM2.5
* *
* Reference formula: https://www.airgradient.com/documentation/correction-algorithms/
*
* @param pm25 PM2.5 raw value * @param pm25 PM2.5 raw value
* @param humidity Humidity value * @param humidity Humidity value
* @return float * @return int
*/ */
int PMS5003::compensated(int pm25, float humidity) { int PMS5003::compensate(int pm25, float humidity) {
return pms.compensated(pm25, humidity); return pms.compensate(pm25, humidity);
} }
/** /**

View File

@ -28,7 +28,7 @@ public:
int getPm10Ae(void); int getPm10Ae(void);
int getPm03ParticleCount(void); int getPm03ParticleCount(void);
int convertPm25ToUsAqi(int pm25); int convertPm25ToUsAqi(int pm25);
int compensated(int pm25, float humidity); int compensate(int pm25, float humidity);
int getFirmwareVersion(void); int getFirmwareVersion(void);
uint8_t getErrorCode(void); uint8_t getErrorCode(void);

View File

@ -167,12 +167,14 @@ float PMS5003T::getRelativeHumidity(void) {
/** /**
* @brief Correct PM2.5 * @brief Correct PM2.5
* *
* Reference formula: https://www.airgradient.com/documentation/correction-algorithms/
*
* @param pm25 PM2.5 raw value * @param pm25 PM2.5 raw value
* @param humidity Humidity value * @param humidity Humidity value
* @return float * @return int
*/ */
float PMS5003T::compensated(int pm25, float humidity) { int PMS5003T::compensate(int pm25, float humidity) {
return pms.compensated(pm25, humidity); return pms.compensate(pm25, humidity);
} }
/** /**

View File

@ -33,7 +33,7 @@ public:
int convertPm25ToUsAqi(int pm25); int convertPm25ToUsAqi(int pm25);
float getTemperature(void); float getTemperature(void);
float getRelativeHumidity(void); float getRelativeHumidity(void);
float compensated(int pm25, float humidity); int compensate(int pm25, float humidity);
int getFirmwareVersion(void); int getFirmwareVersion(void);
uint8_t getErrorCode(void); uint8_t getErrorCode(void);