Skip to content

Commit

Permalink
Update OpenMetrics with compensated values
Browse files Browse the repository at this point in the history
  • Loading branch information
pnt325 committed Apr 20, 2024
1 parent 71b45fc commit e61cd9b
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions examples/OneOpenAir/OpenMetrics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ String OpenMetrics::getPayload(void) {
int pm25 = -1;
int pm10 = -1;
int pm03PCount = -1;
int atmpCompensated = -1;
int ahumCompensated = -1;
if (config.hasSensorPMS1 && config.hasSensorPMS2) {
_temp = (measure.temp_1 + measure.temp_2) / 2.0f;
_hum = (measure.hum_1 + measure.hum_2) / 2.0f;
Expand Down Expand Up @@ -104,6 +106,15 @@ String OpenMetrics::getPayload(void) {
}
}

/** Get temperature and humidity compensated */
if (ag->isOne()) {
atmpCompensated = _temp;
ahumCompensated = _hum;
} else {
atmpCompensated = ag->pms5003t_1.temperatureCompensated(_temp);
ahumCompensated = ag->pms5003t_1.humidityCompensated(_hum);
}

if (config.hasSensorPMS1 || config.hasSensorPMS2) {
if (pm01 >= 0) {
add_metric("pm1",
Expand Down Expand Up @@ -173,13 +184,27 @@ String OpenMetrics::getPayload(void) {
"gauge", "celsius");
add_metric_point("", String(_temp));
}
if (atmpCompensated > -1001) {
add_metric(
"temperature_compensated",
"The ambient temperature as measured by the AirGradient SHT / PMS",
"gauge", "celsius");
add_metric_point("", String(atmpCompensated));
}
if (_hum >= 0) {
add_metric(
"humidity",
"The relative humidity as measured by the AirGradient SHT sensor",
"gauge", "percent");
add_metric_point("", String(_hum));
}
if (ahumCompensated >= 0) {
add_metric(
"humidity_compensated",
"The relative humidity as measured by the AirGradient SHT / PMS sensor",
"gauge", "percent");
add_metric_point("", String(ahumCompensated));
}

response += "# EOF\n";
return response;
Expand Down

0 comments on commit e61cd9b

Please sign in to comment.