Compare commits

...

26 Commits

Author SHA1 Message Date
280ea5e997 Prepared to release 3.1.14 2024-12-04 10:38:13 +07:00
566f8a63b4 Prepare 3.1.13 release 2024-11-27 13:35:26 +07:00
9e4d52454b Merge pull request #266 from airgradienthq/fix/openmetrics
Fix measurements value in prometheus metrics endpoints
2024-11-27 03:38:57 +07:00
5f5e985309 Fix openmetrics esp8266 based 2024-11-27 00:43:03 +07:00
d638573ca7 Fix open metrics for OneOpenAir 2024-11-27 00:15:32 +07:00
79fbd901bd Merge branch 'develop' 2024-11-19 18:45:31 +07:00
3644dc43fe Prepared to release 3.1.12 2024-11-19 18:44:23 +07:00
03fa62d8f0 Merge pull request #263 from airgradienthq/fix/correction
Fix EPA compensated on top of SLR correction
2024-11-19 02:20:51 +07:00
902a768f28 Handle parsing invalid json string 2024-11-19 01:45:50 +07:00
1de9344f43 Fix typo on docs 2024-11-18 22:50:36 +07:00
46f6309b77 Fix use the right function 2024-11-18 22:42:43 +07:00
a6b48acb41 CO2 led bar indicator sync fix 2024-11-18 21:24:47 +07:00
1b4d89e1a1 fix correction on top of compensation 2024-11-18 19:53:28 +07:00
0d2b0fb657 Fix typo on local-server.md
Fix curl correction command example typos
2024-11-17 11:18:39 +07:00
9f08af44b0 Prepared to release 3.1.11 2024-11-11 20:04:47 +07:00
6b661cdeb7 Merge pull request #261 from airgradienthq/feat/allavg
Values on display and led bar using measurement average values
2024-11-11 12:40:48 +07:00
dc299c4b54 Fix pm2.5 not using getAverage for ledbar 2024-11-10 19:20:09 +07:00
2f595b4e41 Update local server docs correction examples 2024-11-10 04:26:54 +07:00
a30535f75f Use avg value for display and led bar 2024-11-10 04:13:58 +07:00
a513943cba New agvalue member to get avg values 2024-11-09 23:27:29 +07:00
96bb6952fb correction function return raw if algorithm is none 2024-11-09 21:28:33 +07:00
10653bfe26 Fix pms5003 correction default value 2024-11-09 20:55:41 +07:00
c7f89fa7b7 Decrease period length moving average to 80% 2024-11-09 20:53:52 +07:00
b11c461b60 Merge pull request #260 from airgradienthq/fix/led-flicker
Fix flicker on led bar led state change
2024-11-09 20:42:01 +07:00
404c14aad2 Fix typo and comment 2024-11-07 22:08:36 +07:00
bfbae680fd Fix led bar flicker when state change
clear only neccessary led
2024-11-07 22:03:01 +07:00
14 changed files with 356 additions and 184 deletions

View File

@ -156,13 +156,13 @@ If the monitor is set up on the AirGradient dashboard, it will also receive the
| `tvocLearningOffset` | Set VOC learning gain offset. | Number | 0-720 (default 12) | `{"tvocLearningOffset": 12}` | | `tvocLearningOffset` | Set VOC learning gain offset. | Number | 0-720 (default 12) | `{"tvocLearningOffset": 12}` |
| `offlineMode` | Set monitor to run without WiFi. | Boolean | `false`: Disabled (default) <br> `true`: Enabled | `{"offlineMode": true}` | | `offlineMode` | Set monitor to run without WiFi. | Boolean | `false`: Disabled (default) <br> `true`: Enabled | `{"offlineMode": true}` |
| `monitorDisplayCompensatedValues` | Set the display show the PM value with/without compensate value (only on [3.1.9]()) | Boolean | `false`: Without compensate (default) <br> `true`: with compensate | `{"monitorDisplayCompensatedValues": false }` | | `monitorDisplayCompensatedValues` | Set the display show the PM value with/without compensate value (only on [3.1.9]()) | Boolean | `false`: Without compensate (default) <br> `true`: with compensate | `{"monitorDisplayCompensatedValues": false }` |
| `corrections` | Sets correction options to display and measurement values on local server response. | Object | _see corretions section_ | _see corretions section_ | | `corrections` | Sets correction options to display and measurement values on local server response. (version >= [3.1.11]()) | Object | _see corrections section_ | _see corrections section_ |
#### Corrections #### Corrections
The `corrections` object allows configuring PM2.5 correction algorithms and parameters. This affects both the display and local server response values. The `corrections` object allows configuring PM2.5 correction algorithms and parameters locally. This affects both the display and local server response values.
Example correction configuration: Example correction configuration:
@ -189,13 +189,28 @@ Example correction configuration:
| PMS5003_20231218 | `"slr_PMS5003_20231218"` | Correction for PMS5003 sensor batch 20231218| Yes | | PMS5003_20231218 | `"slr_PMS5003_20231218"` | Correction for PMS5003 sensor batch 20231218| Yes |
| PMS5003_20231030 | `"slr_PMS5003_20231030"` | Correction for PMS5003 sensor batch 20231030| Yes | | PMS5003_20231030 | `"slr_PMS5003_20231030"` | Correction for PMS5003 sensor batch 20231030| Yes |
**Notes**: **NOTES**:
- Set `useEpa2021` to true if want to apply EPA 2021 correction factors on top of SLR correction value. - Set `useEpa2021` to `true` if want to apply EPA 2021 correction factors on top of SLR correction value, otherwise `false`
- `intercept` and `scalingFactor` values can be obtained from [this article](https://www.airgradient.com/blog/low-readings-from-pms5003/) - `intercept` and `scalingFactor` values can be obtained from [this article](https://www.airgradient.com/blog/low-readings-from-pms5003/)
- If `configurationControl` is set to `local` (eg. when using Home Assistant), correction need to be set manually, see examples below
**Example**: **Examples**:
- PMS5003_20231030
```bash ```bash
curl --location -X PUT 'http://airgradient_84fce612eff4.local/config' --header 'Content-Type: application/json' --data '{"corrections":{"pm02":{"correctionAlgorithm":"slr_PMS5003_20231030","slr":{"intercept":0,"scalingFactor":0.02838,"useEpa2021":false}}}}' curl --location -X PUT 'http://airgradient_84fce612eff4.local/config' --header 'Content-Type: application/json' --data '{"corrections":{"pm02":{"correctionAlgorithm":"slr_PMS5003_20231030","slr":{"intercept":0,"scalingFactor":0.02838,"useEpa2021":true}}}}'
``` ```
- PMS5003_20231218
```bash
curl --location -X PUT 'http://airgradient_84fce612eff4.local/config' --header 'Content-Type: application/json' --data '{"corrections":{"pm02":{"correctionAlgorithm":"slr_PMS5003_20231218","slr":{"intercept":0,"scalingFactor":0.03525,"useEpa2021":true}}}}'
```
- PMS5003_20240104
```bash
curl --location -X PUT 'http://airgradient_84fce612eff4.local/config' --header 'Content-Type: application/json' --data '{"corrections":{"pm02":{"correctionAlgorithm":"slr_PMS5003_20240104","slr":{"intercept":0,"scalingFactor":0.02896,"useEpa2021":true}}}}'
```

View File

@ -57,26 +57,20 @@ String OpenMetrics::getPayload(void) {
"gauge", "dbm"); "gauge", "dbm");
add_metric_point("", String(wifiConnector.RSSI())); add_metric_point("", String(wifiConnector.RSSI()));
if (config.hasSensorS8 && measure.CO2 >= 0) { // Initialize default invalid value for each measurements
add_metric("co2",
"Carbon dioxide concentration as measured by the AirGradient S8 "
"sensor, in parts per million",
"gauge", "ppm");
add_metric_point("", String(measure.CO2));
}
float _temp = utils::getInvalidTemperature(); float _temp = utils::getInvalidTemperature();
float _hum = utils::getInvalidHumidity(); float _hum = utils::getInvalidHumidity();
int pm01 = utils::getInvalidPmValue(); int pm01 = utils::getInvalidPmValue();
int pm25 = utils::getInvalidPmValue(); int pm25 = utils::getInvalidPmValue();
int pm10 = utils::getInvalidPmValue(); int pm10 = utils::getInvalidPmValue();
int pm03PCount = utils::getInvalidPmValue(); int pm03PCount = utils::getInvalidPmValue();
int co2 = utils::getInvalidCO2();
int atmpCompensated = utils::getInvalidTemperature(); int atmpCompensated = utils::getInvalidTemperature();
int ahumCompensated = utils::getInvalidHumidity(); int ahumCompensated = utils::getInvalidHumidity();
int tvoc = utils::getInvalidVOC(); int tvoc = utils::getInvalidVOC();
int tvoc_raw = utils::getInvalidVOC(); int tvocRaw = utils::getInvalidVOC();
int nox = utils::getInvalidNOx(); int nox = utils::getInvalidNOx();
int nox_raw = utils::getInvalidNOx(); int noxRaw = utils::getInvalidNOx();
if (config.hasSensorSHT) { if (config.hasSensorSHT) {
_temp = measure.getFloat(Measurements::Temperature); _temp = measure.getFloat(Measurements::Temperature);
@ -94,9 +88,13 @@ String OpenMetrics::getPayload(void) {
if (config.hasSensorSGP) { if (config.hasSensorSGP) {
tvoc = measure.get(Measurements::TVOC); tvoc = measure.get(Measurements::TVOC);
tvoc_raw = measure.get(Measurements::TVOCRaw); tvocRaw = measure.get(Measurements::TVOCRaw);
nox = measure.get(Measurements::NOx); nox = measure.get(Measurements::NOx);
nox_raw = measure.get(Measurements::NOxRaw); noxRaw = measure.get(Measurements::NOxRaw);
}
if (config.hasSensorS8) {
co2 = measure.get(Measurements::CO2);
} }
if (config.hasSensorPMS1) { if (config.hasSensorPMS1) {
@ -138,12 +136,12 @@ String OpenMetrics::getPayload(void) {
"gauge"); "gauge");
add_metric_point("", String(tvoc)); add_metric_point("", String(tvoc));
} }
if (utils::isValidVOC(tvoc_raw)) { if (utils::isValidVOC(tvocRaw)) {
add_metric("tvoc_raw", add_metric("tvoc_raw",
"The raw input value to the Total Volatile Organic Compounds " "The raw input value to the Total Volatile Organic Compounds "
"(TVOC) index as measured by the AirGradient SGP sensor", "(TVOC) index as measured by the AirGradient SGP sensor",
"gauge"); "gauge");
add_metric_point("", String(tvoc_raw)); add_metric_point("", String(tvocRaw));
} }
if (utils::isValidNOx(nox)) { if (utils::isValidNOx(nox)) {
add_metric("nox_index", add_metric("nox_index",
@ -152,15 +150,23 @@ String OpenMetrics::getPayload(void) {
"gauge"); "gauge");
add_metric_point("", String(nox)); add_metric_point("", String(nox));
} }
if (utils::isValidNOx(nox_raw)) { if (utils::isValidNOx(noxRaw)) {
add_metric("nox_raw", add_metric("nox_raw",
"The raw input value to the Nitrous Oxide (NOx) index as " "The raw input value to the Nitrous Oxide (NOx) index as "
"measured by the AirGradient SGP sensor", "measured by the AirGradient SGP sensor",
"gauge"); "gauge");
add_metric_point("", String(nox_raw)); add_metric_point("", String(noxRaw));
} }
} }
if (utils::isValidCO2(co2)) {
add_metric("co2",
"Carbon dioxide concentration as measured by the AirGradient S8 "
"sensor, in parts per million",
"gauge", "ppm");
add_metric_point("", String(co2));
}
if (utils::isValidTemperature(_temp)) { if (utils::isValidTemperature(_temp)) {
add_metric( add_metric(
"temperature", "temperature",

View File

@ -57,26 +57,20 @@ String OpenMetrics::getPayload(void) {
"gauge", "dbm"); "gauge", "dbm");
add_metric_point("", String(wifiConnector.RSSI())); add_metric_point("", String(wifiConnector.RSSI()));
if (config.hasSensorS8 && measure.CO2 >= 0) { // Initialize default invalid value for each measurements
add_metric("co2",
"Carbon dioxide concentration as measured by the AirGradient S8 "
"sensor, in parts per million",
"gauge", "ppm");
add_metric_point("", String(measure.CO2));
}
float _temp = utils::getInvalidTemperature(); float _temp = utils::getInvalidTemperature();
float _hum = utils::getInvalidHumidity(); float _hum = utils::getInvalidHumidity();
int pm01 = utils::getInvalidPmValue(); int pm01 = utils::getInvalidPmValue();
int pm25 = utils::getInvalidPmValue(); int pm25 = utils::getInvalidPmValue();
int pm10 = utils::getInvalidPmValue(); int pm10 = utils::getInvalidPmValue();
int pm03PCount = utils::getInvalidPmValue(); int pm03PCount = utils::getInvalidPmValue();
int co2 = utils::getInvalidCO2();
int atmpCompensated = utils::getInvalidTemperature(); int atmpCompensated = utils::getInvalidTemperature();
int ahumCompensated = utils::getInvalidHumidity(); int ahumCompensated = utils::getInvalidHumidity();
int tvoc = utils::getInvalidVOC(); int tvoc = utils::getInvalidVOC();
int tvoc_raw = utils::getInvalidVOC(); int tvocRaw = utils::getInvalidVOC();
int nox = utils::getInvalidNOx(); int nox = utils::getInvalidNOx();
int nox_raw = utils::getInvalidNOx(); int noxRaw = utils::getInvalidNOx();
if (config.hasSensorSHT) { if (config.hasSensorSHT) {
_temp = measure.getFloat(Measurements::Temperature); _temp = measure.getFloat(Measurements::Temperature);
@ -94,9 +88,13 @@ String OpenMetrics::getPayload(void) {
if (config.hasSensorSGP) { if (config.hasSensorSGP) {
tvoc = measure.get(Measurements::TVOC); tvoc = measure.get(Measurements::TVOC);
tvoc_raw = measure.get(Measurements::TVOCRaw); tvocRaw = measure.get(Measurements::TVOCRaw);
nox = measure.get(Measurements::NOx); nox = measure.get(Measurements::NOx);
nox_raw = measure.get(Measurements::NOxRaw); noxRaw = measure.get(Measurements::NOxRaw);
}
if (config.hasSensorS8) {
co2 = measure.get(Measurements::CO2);
} }
if (config.hasSensorPMS1) { if (config.hasSensorPMS1) {
@ -138,12 +136,13 @@ String OpenMetrics::getPayload(void) {
"gauge"); "gauge");
add_metric_point("", String(tvoc)); add_metric_point("", String(tvoc));
} }
if (utils::isValidVOC(tvoc_raw)) {
if (utils::isValidVOC(tvocRaw)) {
add_metric("tvoc_raw", add_metric("tvoc_raw",
"The raw input value to the Total Volatile Organic Compounds " "The raw input value to the Total Volatile Organic Compounds "
"(TVOC) index as measured by the AirGradient SGP sensor", "(TVOC) index as measured by the AirGradient SGP sensor",
"gauge"); "gauge");
add_metric_point("", String(tvoc_raw)); add_metric_point("", String(tvocRaw));
} }
if (utils::isValidNOx(nox)) { if (utils::isValidNOx(nox)) {
add_metric("nox_index", add_metric("nox_index",
@ -152,15 +151,23 @@ String OpenMetrics::getPayload(void) {
"gauge"); "gauge");
add_metric_point("", String(nox)); add_metric_point("", String(nox));
} }
if (utils::isValidNOx(nox_raw)) { if (utils::isValidNOx(noxRaw)) {
add_metric("nox_raw", add_metric("nox_raw",
"The raw input value to the Nitrous Oxide (NOx) index as " "The raw input value to the Nitrous Oxide (NOx) index as "
"measured by the AirGradient SGP sensor", "measured by the AirGradient SGP sensor",
"gauge"); "gauge");
add_metric_point("", String(nox_raw)); add_metric_point("", String(noxRaw));
} }
} }
if (utils::isValidCO2(co2)) {
add_metric("co2",
"Carbon dioxide concentration as measured by the AirGradient S8 "
"sensor, in parts per million",
"gauge", "ppm");
add_metric_point("", String(co2));
}
if (utils::isValidTemperature(_temp)) { if (utils::isValidTemperature(_temp)) {
add_metric( add_metric(
"temperature", "temperature",

View File

@ -57,26 +57,20 @@ String OpenMetrics::getPayload(void) {
"gauge", "dbm"); "gauge", "dbm");
add_metric_point("", String(wifiConnector.RSSI())); add_metric_point("", String(wifiConnector.RSSI()));
if (config.hasSensorS8 && measure.CO2 >= 0) { // Initialize default invalid value for each measurements
add_metric("co2",
"Carbon dioxide concentration as measured by the AirGradient S8 "
"sensor, in parts per million",
"gauge", "ppm");
add_metric_point("", String(measure.CO2));
}
float _temp = utils::getInvalidTemperature(); float _temp = utils::getInvalidTemperature();
float _hum = utils::getInvalidHumidity(); float _hum = utils::getInvalidHumidity();
int pm01 = utils::getInvalidPmValue(); int pm01 = utils::getInvalidPmValue();
int pm25 = utils::getInvalidPmValue(); int pm25 = utils::getInvalidPmValue();
int pm10 = utils::getInvalidPmValue(); int pm10 = utils::getInvalidPmValue();
int pm03PCount = utils::getInvalidPmValue(); int pm03PCount = utils::getInvalidPmValue();
int co2 = utils::getInvalidCO2();
int atmpCompensated = utils::getInvalidTemperature(); int atmpCompensated = utils::getInvalidTemperature();
int ahumCompensated = utils::getInvalidHumidity(); int ahumCompensated = utils::getInvalidHumidity();
int tvoc = utils::getInvalidVOC(); int tvoc = utils::getInvalidVOC();
int tvoc_raw = utils::getInvalidVOC(); int tvocRaw = utils::getInvalidVOC();
int nox = utils::getInvalidNOx(); int nox = utils::getInvalidNOx();
int nox_raw = utils::getInvalidNOx(); int noxRaw = utils::getInvalidNOx();
if (config.hasSensorSHT) { if (config.hasSensorSHT) {
_temp = measure.getFloat(Measurements::Temperature); _temp = measure.getFloat(Measurements::Temperature);
@ -94,9 +88,13 @@ String OpenMetrics::getPayload(void) {
if (config.hasSensorSGP) { if (config.hasSensorSGP) {
tvoc = measure.get(Measurements::TVOC); tvoc = measure.get(Measurements::TVOC);
tvoc_raw = measure.get(Measurements::TVOCRaw); tvocRaw = measure.get(Measurements::TVOCRaw);
nox = measure.get(Measurements::NOx); nox = measure.get(Measurements::NOx);
nox_raw = measure.get(Measurements::NOxRaw); noxRaw = measure.get(Measurements::NOxRaw);
}
if (config.hasSensorS8) {
co2 = measure.get(Measurements::CO2);
} }
if (config.hasSensorPMS1) { if (config.hasSensorPMS1) {
@ -138,12 +136,12 @@ String OpenMetrics::getPayload(void) {
"gauge"); "gauge");
add_metric_point("", String(tvoc)); add_metric_point("", String(tvoc));
} }
if (utils::isValidVOC(tvoc_raw)) { if (utils::isValidVOC(tvocRaw)) {
add_metric("tvoc_raw", add_metric("tvoc_raw",
"The raw input value to the Total Volatile Organic Compounds " "The raw input value to the Total Volatile Organic Compounds "
"(TVOC) index as measured by the AirGradient SGP sensor", "(TVOC) index as measured by the AirGradient SGP sensor",
"gauge"); "gauge");
add_metric_point("", String(tvoc_raw)); add_metric_point("", String(tvocRaw));
} }
if (utils::isValidNOx(nox)) { if (utils::isValidNOx(nox)) {
add_metric("nox_index", add_metric("nox_index",
@ -152,15 +150,23 @@ String OpenMetrics::getPayload(void) {
"gauge"); "gauge");
add_metric_point("", String(nox)); add_metric_point("", String(nox));
} }
if (utils::isValidNOx(nox_raw)) { if (utils::isValidNOx(noxRaw)) {
add_metric("nox_raw", add_metric("nox_raw",
"The raw input value to the Nitrous Oxide (NOx) index as " "The raw input value to the Nitrous Oxide (NOx) index as "
"measured by the AirGradient SGP sensor", "measured by the AirGradient SGP sensor",
"gauge"); "gauge");
add_metric_point("", String(nox_raw)); add_metric_point("", String(noxRaw));
} }
} }
if (utils::isValidCO2(co2)) {
add_metric("co2",
"Carbon dioxide concentration as measured by the AirGradient S8 "
"sensor, in parts per million",
"gauge", "ppm");
add_metric_point("", String(co2));
}
if (utils::isValidTemperature(_temp)) { if (utils::isValidTemperature(_temp)) {
add_metric( add_metric(
"temperature", "temperature",

View File

@ -168,7 +168,7 @@ void setup() {
boardInit(); boardInit();
setMeasurementMaxPeriod(); setMeasurementMaxPeriod();
// Uncomment below line to print every measurements reading update // Comment below line to disable debug measurement readings
measurements.setDebug(true); measurements.setDebug(true);
/** Connecting wifi */ /** Connecting wifi */
@ -1216,6 +1216,6 @@ void setMeasurementMaxPeriod() {
} }
int calculateMaxPeriod(int updateInterval) { int calculateMaxPeriod(int updateInterval) {
// 0.5 is 50% reduced interval for max period // 0.8 is 80% reduced interval for max period
return (SERVER_SYNC_INTERVAL - (SERVER_SYNC_INTERVAL * 0.5)) / updateInterval; return (SERVER_SYNC_INTERVAL - (SERVER_SYNC_INTERVAL * 0.8)) / updateInterval;
} }

View File

@ -57,22 +57,22 @@ String OpenMetrics::getPayload(void) {
"gauge", "dbm"); "gauge", "dbm");
add_metric_point("", String(wifiConnector.RSSI())); add_metric_point("", String(wifiConnector.RSSI()));
if (config.hasSensorS8 && measure.CO2 >= 0) { // Initialize default invalid value for each measurements
add_metric("co2",
"Carbon dioxide concentration as measured by the AirGradient S8 "
"sensor, in parts per million",
"gauge", "ppm");
add_metric_point("", String(measure.CO2));
}
float _temp = utils::getInvalidTemperature(); float _temp = utils::getInvalidTemperature();
float _hum = utils::getInvalidHumidity(); float _hum = utils::getInvalidHumidity();
int pm01 = utils::getInvalidPmValue(); int pm01 = utils::getInvalidPmValue();
int pm25 = utils::getInvalidPmValue(); int pm25 = utils::getInvalidPmValue();
int pm10 = utils::getInvalidPmValue(); int pm10 = utils::getInvalidPmValue();
int pm03PCount = utils::getInvalidPmValue(); int pm03PCount = utils::getInvalidPmValue();
int co2 = utils::getInvalidCO2();
int atmpCompensated = utils::getInvalidTemperature(); int atmpCompensated = utils::getInvalidTemperature();
int ahumCompensated = utils::getInvalidHumidity(); int ahumCompensated = utils::getInvalidHumidity();
int tvoc = utils::getInvalidVOC();
int tvocRaw = utils::getInvalidVOC();
int nox = utils::getInvalidNOx();
int noxRaw = utils::getInvalidNOx();
// Get values
if (config.hasSensorPMS1 && config.hasSensorPMS2) { if (config.hasSensorPMS1 && config.hasSensorPMS2) {
_temp = (measure.getFloat(Measurements::Temperature, 1) + _temp = (measure.getFloat(Measurements::Temperature, 1) +
measure.getFloat(Measurements::Temperature, 2)) / measure.getFloat(Measurements::Temperature, 2)) /
@ -118,6 +118,17 @@ String OpenMetrics::getPayload(void) {
} }
} }
if (config.hasSensorSGP) {
tvoc = measure.get(Measurements::TVOC);
tvocRaw = measure.get(Measurements::TVOCRaw);
nox = measure.get(Measurements::NOx);
noxRaw = measure.get(Measurements::NOxRaw);
}
if (config.hasSensorS8) {
co2 = measure.get(Measurements::CO2);
}
/** Get temperature and humidity compensated */ /** Get temperature and humidity compensated */
if (ag->isOne()) { if (ag->isOne()) {
atmpCompensated = _temp; atmpCompensated = _temp;
@ -127,6 +138,7 @@ String OpenMetrics::getPayload(void) {
ahumCompensated = ag->pms5003t_1.compensateHum(_hum); ahumCompensated = ag->pms5003t_1.compensateHum(_hum);
} }
// Add measurements that valid to the metrics
if (config.hasSensorPMS1 || config.hasSensorPMS2) { if (config.hasSensorPMS1 || config.hasSensorPMS2) {
if (utils::isValidPm(pm01)) { if (utils::isValidPm(pm01)) {
add_metric("pm1", add_metric("pm1",
@ -159,36 +171,44 @@ String OpenMetrics::getPayload(void) {
} }
if (config.hasSensorSGP) { if (config.hasSensorSGP) {
if (utils::isValidVOC(measure.TVOC)) { if (utils::isValidVOC(tvoc)) {
add_metric("tvoc_index", add_metric("tvoc_index",
"The processed Total Volatile Organic Compounds (TVOC) index " "The processed Total Volatile Organic Compounds (TVOC) index "
"as measured by the AirGradient SGP sensor", "as measured by the AirGradient SGP sensor",
"gauge"); "gauge");
add_metric_point("", String(measure.TVOC)); add_metric_point("", String(tvoc));
} }
if (utils::isValidVOC(measure.TVOCRaw)) { if (utils::isValidVOC(tvocRaw)) {
add_metric("tvoc_raw", add_metric("tvoc_raw",
"The raw input value to the Total Volatile Organic Compounds " "The raw input value to the Total Volatile Organic Compounds "
"(TVOC) index as measured by the AirGradient SGP sensor", "(TVOC) index as measured by the AirGradient SGP sensor",
"gauge"); "gauge");
add_metric_point("", String(measure.TVOCRaw)); add_metric_point("", String(tvocRaw));
} }
if (utils::isValidNOx(measure.NOx)) { if (utils::isValidNOx(nox)) {
add_metric("nox_index", add_metric("nox_index",
"The processed Nitrous Oxide (NOx) index as measured by the " "The processed Nitrous Oxide (NOx) index as measured by the "
"AirGradient SGP sensor", "AirGradient SGP sensor",
"gauge"); "gauge");
add_metric_point("", String(measure.NOx)); add_metric_point("", String(nox));
} }
if (utils::isValidNOx(measure.NOxRaw)) { if (utils::isValidNOx(noxRaw)) {
add_metric("nox_raw", add_metric("nox_raw",
"The raw input value to the Nitrous Oxide (NOx) index as " "The raw input value to the Nitrous Oxide (NOx) index as "
"measured by the AirGradient SGP sensor", "measured by the AirGradient SGP sensor",
"gauge"); "gauge");
add_metric_point("", String(measure.NOxRaw)); add_metric_point("", String(noxRaw));
} }
} }
if (utils::isValidCO2(co2)) {
add_metric("co2",
"Carbon dioxide concentration as measured by the AirGradient S8 "
"sensor, in parts per million",
"gauge", "ppm");
add_metric_point("", String(co2));
}
if (utils::isValidTemperature(_temp)) { if (utils::isValidTemperature(_temp)) {
add_metric("temperature", add_metric("temperature",
"The ambient temperature as measured by the AirGradient SHT / PMS " "The ambient temperature as measured by the AirGradient SHT / PMS "
@ -197,25 +217,21 @@ String OpenMetrics::getPayload(void) {
add_metric_point("", String(_temp)); add_metric_point("", String(_temp));
} }
if (utils::isValidTemperature(atmpCompensated)) { if (utils::isValidTemperature(atmpCompensated)) {
add_metric( add_metric("temperature_compensated",
"temperature_compensated", "The compensated ambient temperature as measured by the AirGradient SHT / PMS "
"The compensated ambient temperature as measured by the AirGradient SHT / PMS " "sensor, in degrees Celsius",
"sensor, in degrees Celsius", "gauge", "celsius");
"gauge", "celsius");
add_metric_point("", String(atmpCompensated)); add_metric_point("", String(atmpCompensated));
} }
if (utils::isValidHumidity(_hum)) { if (utils::isValidHumidity(_hum)) {
add_metric( add_metric("humidity", "The relative humidity as measured by the AirGradient SHT sensor",
"humidity", "gauge", "percent");
"The relative humidity as measured by the AirGradient SHT sensor",
"gauge", "percent");
add_metric_point("", String(_hum)); add_metric_point("", String(_hum));
} }
if (utils::isValidHumidity(ahumCompensated)) { if (utils::isValidHumidity(ahumCompensated)) {
add_metric( add_metric("humidity_compensated",
"humidity_compensated", "The compensated relative humidity as measured by the AirGradient SHT / PMS sensor",
"The compensated relative humidity as measured by the AirGradient SHT / PMS sensor", "gauge", "percent");
"gauge", "percent");
add_metric_point("", String(ahumCompensated)); add_metric_point("", String(ahumCompensated));
} }

View File

@ -1,5 +1,5 @@
name=AirGradient Air Quality Sensor name=AirGradient Air Quality Sensor
version=3.1.10 version=3.1.14
author=AirGradient <support@airgradient.com> author=AirGradient <support@airgradient.com>
maintainer=AirGradient <support@airgradient.com> maintainer=AirGradient <support@airgradient.com>
sentence=ESP32-C3 / ESP8266 library for air quality monitor measuring PM, CO2, Temperature, TVOC and Humidity with OLED display. sentence=ESP32-C3 / ESP8266 library for air quality monitor measuring PM, CO2, Temperature, TVOC and Humidity with OLED display.

View File

@ -292,8 +292,8 @@ void Configuration::defaultConfig(void) {
// PM2.5 correction // PM2.5 correction
pmCorrection.algorithm = None; pmCorrection.algorithm = None;
pmCorrection.changed = false; pmCorrection.changed = false;
pmCorrection.intercept = -1; pmCorrection.intercept = 0;
pmCorrection.scalingFactor = -1; pmCorrection.scalingFactor = 1;
pmCorrection.useEPA = false; pmCorrection.useEPA = false;
saveConfig(); saveConfig();
@ -354,16 +354,16 @@ bool Configuration::begin(void) {
* @return false Failure * @return false Failure
*/ */
bool Configuration::parse(String data, bool isLocal) { bool Configuration::parse(String data, bool isLocal) {
logInfo("Parse configure: " + data); logInfo("Parsing configuration: " + data);
JSONVar root = JSON.parse(data); JSONVar root = JSON.parse(data);
failedMessage = ""; failedMessage = "";
if (root == undefined) { if (root == undefined || JSONVar::typeof_(root) != "object") {
logError("Parse configuration failed, JSON invalid (" + JSONVar::typeof_(root) + ")");
failedMessage = "JSON invalid"; failedMessage = "JSON invalid";
logError(failedMessage);
return false; return false;
} }
logInfo("Parse configure success"); logInfo("Parse configuration success");
/** Is configuration changed */ /** Is configuration changed */
bool changed = false; bool changed = false;
@ -1369,7 +1369,12 @@ bool Configuration::isPMCorrectionChanged(void) {
*/ */
bool Configuration::isPMCorrectionEnabled(void) { bool Configuration::isPMCorrectionEnabled(void) {
PMCorrection pmCorrection = getPMCorrection(); PMCorrection pmCorrection = getPMCorrection();
return pmCorrection.algorithm != PMCorrectionAlgorithm::None; if (pmCorrection.algorithm == PMCorrectionAlgorithm::None ||
pmCorrection.algorithm == PMCorrectionAlgorithm::Unknown) {
return false;
}
return true;
} }
Configuration::PMCorrection Configuration::getPMCorrection(void) { Configuration::PMCorrection Configuration::getPMCorrection(void) {

View File

@ -12,7 +12,7 @@
*/ */
void OledDisplay::showTempHum(bool hasStatus, char *buf, int buf_size) { void OledDisplay::showTempHum(bool hasStatus, char *buf, int buf_size) {
/** Temperature */ /** Temperature */
float temp = value.getFloat(Measurements::Temperature); float temp = value.getAverage(Measurements::Temperature);
if (utils::isValidTemperature(temp)) { if (utils::isValidTemperature(temp)) {
float t = 0.0f; float t = 0.0f;
if (config.isTemperatureUnitInF()) { if (config.isTemperatureUnitInF()) {
@ -44,7 +44,7 @@ void OledDisplay::showTempHum(bool hasStatus, char *buf, int buf_size) {
DISP()->drawUTF8(1, 10, buf); DISP()->drawUTF8(1, 10, buf);
/** Show humidity */ /** Show humidity */
int rhum = (int)value.getFloat(Measurements::Humidity); int rhum = round(value.getAverage(Measurements::Humidity));
if (utils::isValidHumidity(rhum)) { if (utils::isValidHumidity(rhum)) {
snprintf(buf, buf_size, "%d%%", rhum); snprintf(buf, buf_size, "%d%%", rhum);
} else { } else {
@ -292,7 +292,7 @@ void OledDisplay::showDashboard(const char *status) {
DISP()->drawUTF8(1, 27, "CO2"); DISP()->drawUTF8(1, 27, "CO2");
DISP()->setFont(u8g2_font_t0_22b_tf); DISP()->setFont(u8g2_font_t0_22b_tf);
int co2 = value.get(Measurements::CO2); int co2 = round(value.getAverage(Measurements::CO2));
if (utils::isValidCO2(co2)) { if (utils::isValidCO2(co2)) {
sprintf(strBuf, "%d", co2); sprintf(strBuf, "%d", co2);
} else { } else {
@ -313,11 +313,10 @@ void OledDisplay::showDashboard(const char *status) {
DISP()->drawStr(55, 27, "PM2.5"); DISP()->drawStr(55, 27, "PM2.5");
/** Draw PM2.5 value */ /** Draw PM2.5 value */
int pm25 = round(value.getAverage(Measurements::PM25));
int pm25 = value.get(Measurements::PM25);
if (utils::isValidPm(pm25)) { if (utils::isValidPm(pm25)) {
if (config.hasSensorSHT && config.isPMCorrectionEnabled()) { if (config.hasSensorSHT && config.isPMCorrectionEnabled()) {
pm25 = (int)value.getCorrectedPM25(*ag, config); pm25 = round(value.getCorrectedPM25(*ag, config, true));
} }
if (config.isPmStandardInUSAQI()) { if (config.isPmStandardInUSAQI()) {
sprintf(strBuf, "%d", ag->pms5003.convertPm25ToUsAqi(pm25)); sprintf(strBuf, "%d", ag->pms5003.convertPm25ToUsAqi(pm25));
@ -343,7 +342,7 @@ void OledDisplay::showDashboard(const char *status) {
DISP()->drawStr(100, 27, "VOC:"); DISP()->drawStr(100, 27, "VOC:");
/** Draw tvocIndexvalue */ /** Draw tvocIndexvalue */
int tvoc = value.get(Measurements::TVOC); int tvoc = round(value.getAverage(Measurements::TVOC));
if (utils::isValidVOC(tvoc)) { if (utils::isValidVOC(tvoc)) {
sprintf(strBuf, "%d", tvoc); sprintf(strBuf, "%d", tvoc);
} else { } else {
@ -352,7 +351,7 @@ void OledDisplay::showDashboard(const char *status) {
DISP()->drawStr(100, 39, strBuf); DISP()->drawStr(100, 39, strBuf);
/** Draw NOx label */ /** Draw NOx label */
int nox = value.get(Measurements::NOx); int nox = round(value.getAverage(Measurements::NOx));
DISP()->drawStr(100, 53, "NOx:"); DISP()->drawStr(100, 53, "NOx:");
if (utils::isValidNOx(nox)) { if (utils::isValidNOx(nox)) {
sprintf(strBuf, "%d", nox); sprintf(strBuf, "%d", nox);
@ -365,7 +364,7 @@ void OledDisplay::showDashboard(const char *status) {
ag->display.clear(); ag->display.clear();
/** Set CO2 */ /** Set CO2 */
int co2 = value.get(Measurements::CO2); int co2 = round(value.getAverage(Measurements::CO2));
if (utils::isValidCO2(co2)) { if (utils::isValidCO2(co2)) {
snprintf(strBuf, sizeof(strBuf), "CO2:%d", co2); snprintf(strBuf, sizeof(strBuf), "CO2:%d", co2);
} else { } else {
@ -376,9 +375,9 @@ void OledDisplay::showDashboard(const char *status) {
ag->display.setText(strBuf); ag->display.setText(strBuf);
/** Set PM */ /** Set PM */
int pm25 = value.get(Measurements::PM25); int pm25 = round(value.getAverage(Measurements::PM25));
if (config.hasSensorSHT && config.isPMCorrectionEnabled()) { if (config.hasSensorSHT && config.isPMCorrectionEnabled()) {
pm25 = (int)value.getCorrectedPM25(*ag, config); pm25 = round(value.getCorrectedPM25(*ag, config, true));
} }
ag->display.setCursor(0, 12); ag->display.setCursor(0, 12);
@ -390,7 +389,7 @@ void OledDisplay::showDashboard(const char *status) {
ag->display.setText(strBuf); ag->display.setText(strBuf);
/** Set temperature and humidity */ /** Set temperature and humidity */
float temp = value.getFloat(Measurements::Temperature); float temp = value.getAverage(Measurements::Temperature);
if (utils::isValidTemperature(temp)) { if (utils::isValidTemperature(temp)) {
if (config.isTemperatureUnitInF()) { if (config.isTemperatureUnitInF()) {
snprintf(strBuf, sizeof(strBuf), "T:%0.1f F", utils::degreeC_To_F(temp)); snprintf(strBuf, sizeof(strBuf), "T:%0.1f F", utils::degreeC_To_F(temp));
@ -408,7 +407,7 @@ void OledDisplay::showDashboard(const char *status) {
ag->display.setCursor(0, 24); ag->display.setCursor(0, 24);
ag->display.setText(strBuf); ag->display.setText(strBuf);
int rhum = (int)value.getFloat(Measurements::Humidity); int rhum = round(value.getAverage(Measurements::Humidity));
if (utils::isValidHumidity(rhum)) { if (utils::isValidHumidity(rhum)) {
snprintf(strBuf, sizeof(strBuf), "H:%d %%", rhum); snprintf(strBuf, sizeof(strBuf), "H:%d %%", rhum);
} else { } else {

View File

@ -13,6 +13,7 @@
#define RGB_COLOR_Y 255, 150, 0 /** Yellow */ #define RGB_COLOR_Y 255, 150, 0 /** Yellow */
#define RGB_COLOR_O 255, 40, 0 /** Orange */ #define RGB_COLOR_O 255, 40, 0 /** Orange */
#define RGB_COLOR_P 180, 0, 255 /** Purple */ #define RGB_COLOR_P 180, 0, 255 /** Purple */
#define RGB_COLOR_CLEAR 0, 0, 0 /** No color */
/** /**
* @brief Animation LED bar with color * @brief Animation LED bar with color
@ -47,55 +48,76 @@ void StateMachine::ledStatusBlinkDelay(uint32_t ms) {
} }
/** /**
* @brief Led bar show led color status * @brief Led bar show PM or CO2 led color status
* *
* @return true if all led bar are used, false othwerwise
*/ */
void StateMachine::sensorhandleLeds(void) { bool StateMachine::sensorhandleLeds(void) {
int totalLedUsed = 0;
switch (config.getLedBarMode()) { switch (config.getLedBarMode()) {
case LedBarMode::LedBarModeCO2: case LedBarMode::LedBarModeCO2:
co2handleLeds(); totalLedUsed = co2handleLeds();
break; break;
case LedBarMode::LedBarModePm: case LedBarMode::LedBarModePm:
pm25handleLeds(); totalLedUsed = pm25handleLeds();
break; break;
default: default:
ag->ledBar.clear(); ag->ledBar.clear();
break; break;
} }
if (totalLedUsed == ag->ledBar.getNumberOfLeds()) {
return true;
}
// Clear the rest of unused led
int startIndex = totalLedUsed + 1;
for (int i = startIndex; i <= ag->ledBar.getNumberOfLeds(); i++) {
ag->ledBar.setColor(RGB_COLOR_CLEAR, ag->ledBar.getNumberOfLeds() - i);
}
return false;
} }
/** /**
* @brief Show CO2 LED status * @brief Show CO2 LED status
* *
* @return return total number of led that are used on the monitor
*/ */
void StateMachine::co2handleLeds(void) { int StateMachine::co2handleLeds(void) {
int co2Value = value.get(Measurements::CO2); int totalUsed = ag->ledBar.getNumberOfLeds();
if (co2Value <= 700) { int co2Value = round(value.getAverage(Measurements::CO2));
if (co2Value <= 600) {
/** G; 1 */ /** G; 1 */
ag->ledBar.setColor(RGB_COLOR_G, ag->ledBar.getNumberOfLeds() - 1); ag->ledBar.setColor(RGB_COLOR_G, ag->ledBar.getNumberOfLeds() - 1);
} else if (co2Value <= 1000) { totalUsed = 1;
} else if (co2Value <= 800) {
/** GG; 2 */ /** GG; 2 */
ag->ledBar.setColor(RGB_COLOR_G, ag->ledBar.getNumberOfLeds() - 1); ag->ledBar.setColor(RGB_COLOR_G, ag->ledBar.getNumberOfLeds() - 1);
ag->ledBar.setColor(RGB_COLOR_G, ag->ledBar.getNumberOfLeds() - 2); ag->ledBar.setColor(RGB_COLOR_G, ag->ledBar.getNumberOfLeds() - 2);
} else if (co2Value <= 1333) { totalUsed = 2;
} else if (co2Value <= 1000) {
/** YYY; 3 */ /** YYY; 3 */
ag->ledBar.setColor(RGB_COLOR_Y, ag->ledBar.getNumberOfLeds() - 1); ag->ledBar.setColor(RGB_COLOR_Y, ag->ledBar.getNumberOfLeds() - 1);
ag->ledBar.setColor(RGB_COLOR_Y, ag->ledBar.getNumberOfLeds() - 2); ag->ledBar.setColor(RGB_COLOR_Y, ag->ledBar.getNumberOfLeds() - 2);
ag->ledBar.setColor(RGB_COLOR_Y, ag->ledBar.getNumberOfLeds() - 3); ag->ledBar.setColor(RGB_COLOR_Y, ag->ledBar.getNumberOfLeds() - 3);
} else if (co2Value <= 1666) { totalUsed = 3;
} else if (co2Value <= 1250) {
/** OOOO; 4 */ /** OOOO; 4 */
ag->ledBar.setColor(RGB_COLOR_Y, ag->ledBar.getNumberOfLeds() - 1); ag->ledBar.setColor(RGB_COLOR_O, ag->ledBar.getNumberOfLeds() - 1);
ag->ledBar.setColor(RGB_COLOR_Y, ag->ledBar.getNumberOfLeds() - 2); ag->ledBar.setColor(RGB_COLOR_O, ag->ledBar.getNumberOfLeds() - 2);
ag->ledBar.setColor(RGB_COLOR_Y, ag->ledBar.getNumberOfLeds() - 3); ag->ledBar.setColor(RGB_COLOR_O, ag->ledBar.getNumberOfLeds() - 3);
ag->ledBar.setColor(RGB_COLOR_Y, ag->ledBar.getNumberOfLeds() - 4); ag->ledBar.setColor(RGB_COLOR_O, ag->ledBar.getNumberOfLeds() - 4);
} else if (co2Value <= 2000) { totalUsed = 4;
} else if (co2Value <= 1500) {
/** OOOOO; 5 */ /** OOOOO; 5 */
ag->ledBar.setColor(RGB_COLOR_Y, ag->ledBar.getNumberOfLeds() - 1); ag->ledBar.setColor(RGB_COLOR_O, ag->ledBar.getNumberOfLeds() - 1);
ag->ledBar.setColor(RGB_COLOR_Y, ag->ledBar.getNumberOfLeds() - 2); ag->ledBar.setColor(RGB_COLOR_O, ag->ledBar.getNumberOfLeds() - 2);
ag->ledBar.setColor(RGB_COLOR_Y, ag->ledBar.getNumberOfLeds() - 3); ag->ledBar.setColor(RGB_COLOR_O, ag->ledBar.getNumberOfLeds() - 3);
ag->ledBar.setColor(RGB_COLOR_Y, ag->ledBar.getNumberOfLeds() - 4); ag->ledBar.setColor(RGB_COLOR_O, ag->ledBar.getNumberOfLeds() - 4);
ag->ledBar.setColor(RGB_COLOR_Y, ag->ledBar.getNumberOfLeds() - 5); ag->ledBar.setColor(RGB_COLOR_O, ag->ledBar.getNumberOfLeds() - 5);
} else if (co2Value <= 2666) { totalUsed = 5;
} else if (co2Value <= 1750) {
/** RRRRRR; 6 */ /** RRRRRR; 6 */
ag->ledBar.setColor(RGB_COLOR_R, ag->ledBar.getNumberOfLeds() - 1); ag->ledBar.setColor(RGB_COLOR_R, ag->ledBar.getNumberOfLeds() - 1);
ag->ledBar.setColor(RGB_COLOR_R, ag->ledBar.getNumberOfLeds() - 2); ag->ledBar.setColor(RGB_COLOR_R, ag->ledBar.getNumberOfLeds() - 2);
@ -103,7 +125,8 @@ void StateMachine::co2handleLeds(void) {
ag->ledBar.setColor(RGB_COLOR_R, ag->ledBar.getNumberOfLeds() - 4); ag->ledBar.setColor(RGB_COLOR_R, ag->ledBar.getNumberOfLeds() - 4);
ag->ledBar.setColor(RGB_COLOR_R, ag->ledBar.getNumberOfLeds() - 5); ag->ledBar.setColor(RGB_COLOR_R, ag->ledBar.getNumberOfLeds() - 5);
ag->ledBar.setColor(RGB_COLOR_R, ag->ledBar.getNumberOfLeds() - 6); ag->ledBar.setColor(RGB_COLOR_R, ag->ledBar.getNumberOfLeds() - 6);
} else if (co2Value <= 3333) { totalUsed = 6;
} else if (co2Value <= 2000) {
/** RRRRRRR; 7 */ /** RRRRRRR; 7 */
ag->ledBar.setColor(RGB_COLOR_R, ag->ledBar.getNumberOfLeds() - 1); ag->ledBar.setColor(RGB_COLOR_R, ag->ledBar.getNumberOfLeds() - 1);
ag->ledBar.setColor(RGB_COLOR_R, ag->ledBar.getNumberOfLeds() - 2); ag->ledBar.setColor(RGB_COLOR_R, ag->ledBar.getNumberOfLeds() - 2);
@ -112,17 +135,19 @@ void StateMachine::co2handleLeds(void) {
ag->ledBar.setColor(RGB_COLOR_R, ag->ledBar.getNumberOfLeds() - 5); ag->ledBar.setColor(RGB_COLOR_R, ag->ledBar.getNumberOfLeds() - 5);
ag->ledBar.setColor(RGB_COLOR_R, ag->ledBar.getNumberOfLeds() - 6); ag->ledBar.setColor(RGB_COLOR_R, ag->ledBar.getNumberOfLeds() - 6);
ag->ledBar.setColor(RGB_COLOR_R, ag->ledBar.getNumberOfLeds() - 7); ag->ledBar.setColor(RGB_COLOR_R, ag->ledBar.getNumberOfLeds() - 7);
} else if (co2Value <= 4000) { totalUsed = 7;
/** RRRRRRRR; 8 */ } else if (co2Value <= 3000) {
ag->ledBar.setColor(RGB_COLOR_R, ag->ledBar.getNumberOfLeds() - 1); /** PPPPPPPP; 8 */
ag->ledBar.setColor(RGB_COLOR_R, ag->ledBar.getNumberOfLeds() - 2); ag->ledBar.setColor(RGB_COLOR_P, ag->ledBar.getNumberOfLeds() - 1);
ag->ledBar.setColor(RGB_COLOR_R, ag->ledBar.getNumberOfLeds() - 3); ag->ledBar.setColor(RGB_COLOR_P, ag->ledBar.getNumberOfLeds() - 2);
ag->ledBar.setColor(RGB_COLOR_R, ag->ledBar.getNumberOfLeds() - 4); ag->ledBar.setColor(RGB_COLOR_P, ag->ledBar.getNumberOfLeds() - 3);
ag->ledBar.setColor(RGB_COLOR_R, ag->ledBar.getNumberOfLeds() - 5); ag->ledBar.setColor(RGB_COLOR_P, ag->ledBar.getNumberOfLeds() - 4);
ag->ledBar.setColor(RGB_COLOR_R, ag->ledBar.getNumberOfLeds() - 6); ag->ledBar.setColor(RGB_COLOR_P, ag->ledBar.getNumberOfLeds() - 5);
ag->ledBar.setColor(RGB_COLOR_R, ag->ledBar.getNumberOfLeds() - 7); ag->ledBar.setColor(RGB_COLOR_P, ag->ledBar.getNumberOfLeds() - 6);
ag->ledBar.setColor(RGB_COLOR_R, ag->ledBar.getNumberOfLeds() - 8); ag->ledBar.setColor(RGB_COLOR_P, ag->ledBar.getNumberOfLeds() - 7);
} else { /** > 4000 */ ag->ledBar.setColor(RGB_COLOR_P, ag->ledBar.getNumberOfLeds() - 8);
totalUsed = 8;
} else { /** > 3000 */
/* PRPRPRPRP; 9 */ /* PRPRPRPRP; 9 */
ag->ledBar.setColor(RGB_COLOR_P, ag->ledBar.getNumberOfLeds() - 1); ag->ledBar.setColor(RGB_COLOR_P, ag->ledBar.getNumberOfLeds() - 1);
ag->ledBar.setColor(RGB_COLOR_R, ag->ledBar.getNumberOfLeds() - 2); ag->ledBar.setColor(RGB_COLOR_R, ag->ledBar.getNumberOfLeds() - 2);
@ -133,37 +158,47 @@ void StateMachine::co2handleLeds(void) {
ag->ledBar.setColor(RGB_COLOR_P, ag->ledBar.getNumberOfLeds() - 7); ag->ledBar.setColor(RGB_COLOR_P, ag->ledBar.getNumberOfLeds() - 7);
ag->ledBar.setColor(RGB_COLOR_R, ag->ledBar.getNumberOfLeds() - 8); ag->ledBar.setColor(RGB_COLOR_R, ag->ledBar.getNumberOfLeds() - 8);
ag->ledBar.setColor(RGB_COLOR_P, ag->ledBar.getNumberOfLeds() - 9); ag->ledBar.setColor(RGB_COLOR_P, ag->ledBar.getNumberOfLeds() - 9);
totalUsed = 9;
} }
return totalUsed;
} }
/** /**
* @brief Show PM2.5 LED status * @brief Show PM2.5 LED status
* *
* @return return total number of led that are used on the monitor
*/ */
void StateMachine::pm25handleLeds(void) { int StateMachine::pm25handleLeds(void) {
int pm25Value = value.get(Measurements::PM25); int totalUsed = ag->ledBar.getNumberOfLeds();
int pm25Value = round(value.getAverage(Measurements::PM25));
if (config.hasSensorSHT && config.isPMCorrectionEnabled()) { if (config.hasSensorSHT && config.isPMCorrectionEnabled()) {
pm25Value = (int)value.getCorrectedPM25(*ag, config); pm25Value = round(value.getCorrectedPM25(*ag, config, true));
} }
if (pm25Value <= 5) { if (pm25Value <= 5) {
/** G; 1 */ /** G; 1 */
ag->ledBar.setColor(RGB_COLOR_G, ag->ledBar.getNumberOfLeds() - 1); ag->ledBar.setColor(RGB_COLOR_G, ag->ledBar.getNumberOfLeds() - 1);
totalUsed = 1;
} else if (pm25Value <= 9) { } else if (pm25Value <= 9) {
/** GG; 2 */ /** GG; 2 */
ag->ledBar.setColor(RGB_COLOR_G, ag->ledBar.getNumberOfLeds() - 1); ag->ledBar.setColor(RGB_COLOR_G, ag->ledBar.getNumberOfLeds() - 1);
ag->ledBar.setColor(RGB_COLOR_G, ag->ledBar.getNumberOfLeds() - 2); ag->ledBar.setColor(RGB_COLOR_G, ag->ledBar.getNumberOfLeds() - 2);
totalUsed = 2;
} else if (pm25Value <= 20) { } else if (pm25Value <= 20) {
/** YYY; 3 */ /** YYY; 3 */
ag->ledBar.setColor(RGB_COLOR_Y, ag->ledBar.getNumberOfLeds() - 1); ag->ledBar.setColor(RGB_COLOR_Y, ag->ledBar.getNumberOfLeds() - 1);
ag->ledBar.setColor(RGB_COLOR_Y, ag->ledBar.getNumberOfLeds() - 2); ag->ledBar.setColor(RGB_COLOR_Y, ag->ledBar.getNumberOfLeds() - 2);
ag->ledBar.setColor(RGB_COLOR_Y, ag->ledBar.getNumberOfLeds() - 3); ag->ledBar.setColor(RGB_COLOR_Y, ag->ledBar.getNumberOfLeds() - 3);
totalUsed = 3;
} else if (pm25Value <= 35) { } else if (pm25Value <= 35) {
/** YYYY; 4 */ /** YYYY; 4 */
ag->ledBar.setColor(RGB_COLOR_Y, ag->ledBar.getNumberOfLeds() - 1); ag->ledBar.setColor(RGB_COLOR_Y, ag->ledBar.getNumberOfLeds() - 1);
ag->ledBar.setColor(RGB_COLOR_Y, ag->ledBar.getNumberOfLeds() - 2); ag->ledBar.setColor(RGB_COLOR_Y, ag->ledBar.getNumberOfLeds() - 2);
ag->ledBar.setColor(RGB_COLOR_Y, ag->ledBar.getNumberOfLeds() - 3); ag->ledBar.setColor(RGB_COLOR_Y, ag->ledBar.getNumberOfLeds() - 3);
ag->ledBar.setColor(RGB_COLOR_Y, ag->ledBar.getNumberOfLeds() - 4); ag->ledBar.setColor(RGB_COLOR_Y, ag->ledBar.getNumberOfLeds() - 4);
totalUsed = 4;
} else if (pm25Value <= 45) { } else if (pm25Value <= 45) {
/** OOOOO; 5 */ /** OOOOO; 5 */
ag->ledBar.setColor(RGB_COLOR_O, ag->ledBar.getNumberOfLeds() - 1); ag->ledBar.setColor(RGB_COLOR_O, ag->ledBar.getNumberOfLeds() - 1);
@ -171,6 +206,7 @@ void StateMachine::pm25handleLeds(void) {
ag->ledBar.setColor(RGB_COLOR_O, ag->ledBar.getNumberOfLeds() - 3); ag->ledBar.setColor(RGB_COLOR_O, ag->ledBar.getNumberOfLeds() - 3);
ag->ledBar.setColor(RGB_COLOR_O, ag->ledBar.getNumberOfLeds() - 4); ag->ledBar.setColor(RGB_COLOR_O, ag->ledBar.getNumberOfLeds() - 4);
ag->ledBar.setColor(RGB_COLOR_O, ag->ledBar.getNumberOfLeds() - 5); ag->ledBar.setColor(RGB_COLOR_O, ag->ledBar.getNumberOfLeds() - 5);
totalUsed = 5;
} else if (pm25Value <= 55) { } else if (pm25Value <= 55) {
/** OOOOOO; 6 */ /** OOOOOO; 6 */
ag->ledBar.setColor(RGB_COLOR_O, ag->ledBar.getNumberOfLeds() - 1); ag->ledBar.setColor(RGB_COLOR_O, ag->ledBar.getNumberOfLeds() - 1);
@ -179,6 +215,7 @@ void StateMachine::pm25handleLeds(void) {
ag->ledBar.setColor(RGB_COLOR_O, ag->ledBar.getNumberOfLeds() - 4); ag->ledBar.setColor(RGB_COLOR_O, ag->ledBar.getNumberOfLeds() - 4);
ag->ledBar.setColor(RGB_COLOR_O, ag->ledBar.getNumberOfLeds() - 5); ag->ledBar.setColor(RGB_COLOR_O, ag->ledBar.getNumberOfLeds() - 5);
ag->ledBar.setColor(RGB_COLOR_O, ag->ledBar.getNumberOfLeds() - 6); ag->ledBar.setColor(RGB_COLOR_O, ag->ledBar.getNumberOfLeds() - 6);
totalUsed = 6;
} else if (pm25Value <= 100) { } else if (pm25Value <= 100) {
/** RRRRRRR; 7 */ /** RRRRRRR; 7 */
ag->ledBar.setColor(RGB_COLOR_R, ag->ledBar.getNumberOfLeds() - 1); ag->ledBar.setColor(RGB_COLOR_R, ag->ledBar.getNumberOfLeds() - 1);
@ -188,6 +225,7 @@ void StateMachine::pm25handleLeds(void) {
ag->ledBar.setColor(RGB_COLOR_R, ag->ledBar.getNumberOfLeds() - 5); ag->ledBar.setColor(RGB_COLOR_R, ag->ledBar.getNumberOfLeds() - 5);
ag->ledBar.setColor(RGB_COLOR_R, ag->ledBar.getNumberOfLeds() - 6); ag->ledBar.setColor(RGB_COLOR_R, ag->ledBar.getNumberOfLeds() - 6);
ag->ledBar.setColor(RGB_COLOR_R, ag->ledBar.getNumberOfLeds() - 7); ag->ledBar.setColor(RGB_COLOR_R, ag->ledBar.getNumberOfLeds() - 7);
totalUsed = 7;
} else if (pm25Value <= 125) { } else if (pm25Value <= 125) {
/** RRRRRRRR; 8 */ /** RRRRRRRR; 8 */
ag->ledBar.setColor(RGB_COLOR_R, ag->ledBar.getNumberOfLeds() - 1); ag->ledBar.setColor(RGB_COLOR_R, ag->ledBar.getNumberOfLeds() - 1);
@ -198,6 +236,7 @@ void StateMachine::pm25handleLeds(void) {
ag->ledBar.setColor(RGB_COLOR_R, ag->ledBar.getNumberOfLeds() - 6); ag->ledBar.setColor(RGB_COLOR_R, ag->ledBar.getNumberOfLeds() - 6);
ag->ledBar.setColor(RGB_COLOR_R, ag->ledBar.getNumberOfLeds() - 7); ag->ledBar.setColor(RGB_COLOR_R, ag->ledBar.getNumberOfLeds() - 7);
ag->ledBar.setColor(RGB_COLOR_R, ag->ledBar.getNumberOfLeds() - 8); ag->ledBar.setColor(RGB_COLOR_R, ag->ledBar.getNumberOfLeds() - 8);
totalUsed = 8;
} else if (pm25Value <= 225) { } else if (pm25Value <= 225) {
/** PPPPPPPPP; 9 */ /** PPPPPPPPP; 9 */
ag->ledBar.setColor(RGB_COLOR_P, ag->ledBar.getNumberOfLeds() - 1); ag->ledBar.setColor(RGB_COLOR_P, ag->ledBar.getNumberOfLeds() - 1);
@ -209,6 +248,7 @@ void StateMachine::pm25handleLeds(void) {
ag->ledBar.setColor(RGB_COLOR_P, ag->ledBar.getNumberOfLeds() - 7); ag->ledBar.setColor(RGB_COLOR_P, ag->ledBar.getNumberOfLeds() - 7);
ag->ledBar.setColor(RGB_COLOR_P, ag->ledBar.getNumberOfLeds() - 8); ag->ledBar.setColor(RGB_COLOR_P, ag->ledBar.getNumberOfLeds() - 8);
ag->ledBar.setColor(RGB_COLOR_P, ag->ledBar.getNumberOfLeds() - 9); ag->ledBar.setColor(RGB_COLOR_P, ag->ledBar.getNumberOfLeds() - 9);
totalUsed = 9;
} else { /** > 225 */ } else { /** > 225 */
/* PRPRPRPRP; 9 */ /* PRPRPRPRP; 9 */
ag->ledBar.setColor(RGB_COLOR_P, ag->ledBar.getNumberOfLeds() - 1); ag->ledBar.setColor(RGB_COLOR_P, ag->ledBar.getNumberOfLeds() - 1);
@ -220,7 +260,10 @@ void StateMachine::pm25handleLeds(void) {
ag->ledBar.setColor(RGB_COLOR_P, ag->ledBar.getNumberOfLeds() - 7); ag->ledBar.setColor(RGB_COLOR_P, ag->ledBar.getNumberOfLeds() - 7);
ag->ledBar.setColor(RGB_COLOR_R, ag->ledBar.getNumberOfLeds() - 8); ag->ledBar.setColor(RGB_COLOR_R, ag->ledBar.getNumberOfLeds() - 8);
ag->ledBar.setColor(RGB_COLOR_P, ag->ledBar.getNumberOfLeds() - 9); ag->ledBar.setColor(RGB_COLOR_P, ag->ledBar.getNumberOfLeds() - 9);
totalUsed = 9;
} }
return totalUsed;
} }
void StateMachine::co2Calibration(void) { void StateMachine::co2Calibration(void) {
@ -311,6 +354,7 @@ void StateMachine::co2Calibration(void) {
void StateMachine::ledBarTest(void) { void StateMachine::ledBarTest(void) {
if (config.isLedBarTestRequested()) { if (config.isLedBarTestRequested()) {
if (ag->isOne()) { if (ag->isOne()) {
ag->ledBar.clear();
if (config.getCountry() == "TH") { if (config.getCountry() == "TH") {
uint32_t tstart = millis(); uint32_t tstart = millis();
logInfo("Start run LED test for 2 min"); logInfo("Start run LED test for 2 min");
@ -332,7 +376,12 @@ void StateMachine::ledBarTest(void) {
} }
} }
void StateMachine::ledBarPowerUpTest(void) { ledBarRunTest(); } void StateMachine::ledBarPowerUpTest(void) {
if (ag->isOne()) {
ag->ledBar.clear();
}
ledBarRunTest();
}
void StateMachine::ledBarRunTest(void) { void StateMachine::ledBarRunTest(void) {
if (ag->isOne()) { if (ag->isOne()) {
@ -585,15 +634,13 @@ void StateMachine::handleLeds(AgStateMachineState state) {
} }
ledState = state; ledState = state;
if (ag->isOne()) {
ag->ledBar.clear(); // Set all LED OFF
}
switch (state) { switch (state) {
case AgStateMachineWiFiManagerMode: { case AgStateMachineWiFiManagerMode: {
/** In WiFi Manager Mode */ /** In WiFi Manager Mode */
/** Turn LED OFF */ /** Turn LED OFF */
/** Turn middle LED Color */ /** Turn middle LED Color */
if (ag->isOne()) { if (ag->isOne()) {
ag->ledBar.clear();
ag->ledBar.setColor(0, 0, 255, ag->ledBar.getNumberOfLeds() / 2); ag->ledBar.setColor(0, 0, 255, ag->ledBar.getNumberOfLeds() / 2);
} else { } else {
ag->statusLed.setToggle(); ag->statusLed.setToggle();
@ -603,6 +650,7 @@ void StateMachine::handleLeds(AgStateMachineState state) {
case AgStateMachineWiFiManagerPortalActive: { case AgStateMachineWiFiManagerPortalActive: {
/** WiFi Manager has connected to mobile phone */ /** WiFi Manager has connected to mobile phone */
if (ag->isOne()) { if (ag->isOne()) {
ag->ledBar.clear();
ag->ledBar.setColor(0, 0, 255); ag->ledBar.setColor(0, 0, 255);
} else { } else {
ag->statusLed.setOn(); ag->statusLed.setOn();
@ -613,6 +661,7 @@ void StateMachine::handleLeds(AgStateMachineState state) {
/** after SSID and PW entered and OK clicked, connection to WiFI network is /** after SSID and PW entered and OK clicked, connection to WiFI network is
* attempted */ * attempted */
if (ag->isOne()) { if (ag->isOne()) {
ag->ledBar.clear();
ledBarSingleLedAnimation(255, 255, 255); ledBarSingleLedAnimation(255, 255, 255);
} else { } else {
ag->statusLed.setOff(); ag->statusLed.setOff();
@ -622,6 +671,7 @@ void StateMachine::handleLeds(AgStateMachineState state) {
case AgStateMachineWiFiManagerStaConnected: { case AgStateMachineWiFiManagerStaConnected: {
/** Connecting to WiFi worked */ /** Connecting to WiFi worked */
if (ag->isOne()) { if (ag->isOne()) {
ag->ledBar.clear();
ag->ledBar.setColor(255, 255, 255); ag->ledBar.setColor(255, 255, 255);
} else { } else {
ag->statusLed.setOff(); ag->statusLed.setOff();
@ -631,6 +681,7 @@ void StateMachine::handleLeds(AgStateMachineState state) {
case AgStateMachineWiFiOkServerConnecting: { case AgStateMachineWiFiOkServerConnecting: {
/** once connected to WiFi an attempt to reach the server is performed */ /** once connected to WiFi an attempt to reach the server is performed */
if (ag->isOne()) { if (ag->isOne()) {
ag->ledBar.clear();
ledBarSingleLedAnimation(0, 255, 0); ledBarSingleLedAnimation(0, 255, 0);
} else { } else {
ag->statusLed.setOff(); ag->statusLed.setOff();
@ -640,6 +691,7 @@ void StateMachine::handleLeds(AgStateMachineState state) {
case AgStateMachineWiFiOkServerConnected: { case AgStateMachineWiFiOkServerConnected: {
/** Server is reachable, all fine */ /** Server is reachable, all fine */
if (ag->isOne()) { if (ag->isOne()) {
ag->ledBar.clear();
ag->ledBar.setColor(0, 255, 0); ag->ledBar.setColor(0, 255, 0);
} else { } else {
ag->statusLed.setOff(); ag->statusLed.setOff();
@ -656,6 +708,7 @@ void StateMachine::handleLeds(AgStateMachineState state) {
case AgStateMachineWiFiManagerConnectFailed: { case AgStateMachineWiFiManagerConnectFailed: {
/** Cannot connect to WiFi (e.g. wrong password, WPA Enterprise etc.) */ /** Cannot connect to WiFi (e.g. wrong password, WPA Enterprise etc.) */
if (ag->isOne()) { if (ag->isOne()) {
ag->ledBar.clear();
ag->ledBar.setColor(255, 0, 0); ag->ledBar.setColor(255, 0, 0);
} else { } else {
ag->statusLed.setOff(); ag->statusLed.setOff();
@ -674,6 +727,7 @@ void StateMachine::handleLeds(AgStateMachineState state) {
/** Connected to WiFi but server not reachable, e.g. firewall block/ /** Connected to WiFi but server not reachable, e.g. firewall block/
* whitelisting needed etc. */ * whitelisting needed etc. */
if (ag->isOne()) { if (ag->isOne()) {
ag->ledBar.clear();
ag->ledBar.setColor(233, 183, 54); /** orange */ ag->ledBar.setColor(233, 183, 54); /** orange */
} else { } else {
ag->statusLed.setOff(); ag->statusLed.setOff();
@ -690,6 +744,7 @@ void StateMachine::handleLeds(AgStateMachineState state) {
case AgStateMachineWiFiOkServerOkSensorConfigFailed: { case AgStateMachineWiFiOkServerOkSensorConfigFailed: {
/** Server reachable but sensor not configured correctly */ /** Server reachable but sensor not configured correctly */
if (ag->isOne()) { if (ag->isOne()) {
ag->ledBar.clear();
ag->ledBar.setColor(139, 24, 248); /** violet */ ag->ledBar.setColor(139, 24, 248); /** violet */
} else { } else {
ag->statusLed.setOff(); ag->statusLed.setOff();
@ -707,11 +762,10 @@ void StateMachine::handleLeds(AgStateMachineState state) {
/** Connection to WiFi network failed credentials incorrect encryption not /** Connection to WiFi network failed credentials incorrect encryption not
* supported etc. */ * supported etc. */
if (ag->isOne()) { if (ag->isOne()) {
/** WIFI failed status LED color */ bool allUsed = sensorhandleLeds();
ag->ledBar.setColor(255, 0, 0, 0); if (allUsed == false) {
/** Show CO2 or PM color status */ ag->ledBar.setColor(255, 0, 0, 0);
// sensorLedColorHandler(); }
sensorhandleLeds();
} else { } else {
ag->statusLed.setOff(); ag->statusLed.setOff();
} }
@ -721,11 +775,10 @@ void StateMachine::handleLeds(AgStateMachineState state) {
/** Connected to WiFi network but the server cannot be reached through the /** Connected to WiFi network but the server cannot be reached through the
* internet, e.g. blocked by firewall */ * internet, e.g. blocked by firewall */
if (ag->isOne()) { if (ag->isOne()) {
ag->ledBar.setColor(233, 183, 54, 0); bool allUsed = sensorhandleLeds();
if (allUsed == false) {
/** Show CO2 or PM color status */ ag->ledBar.setColor(233, 183, 54, 0);
sensorhandleLeds(); }
// sensorLedColorHandler();
} else { } else {
ag->statusLed.setOff(); ag->statusLed.setOff();
} }
@ -735,10 +788,10 @@ void StateMachine::handleLeds(AgStateMachineState state) {
/** Server is reachable but there is some configuration issue to be fixed on /** Server is reachable but there is some configuration issue to be fixed on
* the server side */ * the server side */
if (ag->isOne()) { if (ag->isOne()) {
ag->ledBar.setColor(139, 24, 248, 0); bool allUsed = sensorhandleLeds();
if (allUsed == false) {
/** Show CO2 or PM color status */ ag->ledBar.setColor(139, 24, 248, 0);
sensorhandleLeds(); }
} else { } else {
ag->statusLed.setOff(); ag->statusLed.setOff();
} }

View File

@ -24,9 +24,9 @@ private:
void ledBarSingleLedAnimation(uint8_t r, uint8_t g, uint8_t b); void ledBarSingleLedAnimation(uint8_t r, uint8_t g, uint8_t b);
void ledStatusBlinkDelay(uint32_t delay); void ledStatusBlinkDelay(uint32_t delay);
void sensorhandleLeds(void); bool sensorhandleLeds(void);
void co2handleLeds(void); int co2handleLeds(void);
void pm25handleLeds(void); int pm25handleLeds(void);
void co2Calibration(void); void co2Calibration(void);
void ledBarTest(void); void ledBarTest(void);
void ledBarPowerUpTest(void); void ledBarPowerUpTest(void);

View File

@ -396,6 +396,52 @@ float Measurements::getFloat(MeasurementType type, int ch) {
return temporary->listValues.back(); return temporary->listValues.back();
} }
float Measurements::getAverage(MeasurementType type, int ch) {
// Sanity check to validate channel, assert if invalid
validateChannel(ch);
// Follow array indexing just for get address of the value type
ch = ch - 1;
// Define data point source. Data type doesn't matter because only to get the average value
FloatValue *temporary = nullptr;
Update update;
float measurementAverage;
switch (type) {
case CO2:
measurementAverage = _co2.update.avg;
break;
case TVOC:
measurementAverage = _tvoc.update.avg;
break;
case NOx:
measurementAverage = _nox.update.avg;
break;
case PM25:
measurementAverage = _pm_25[ch].update.avg;
break;
case Temperature:
measurementAverage = _temperature[ch].update.avg;
break;
case Humidity:
measurementAverage = _humidity[ch].update.avg;
break;
default:
// Invalidate, measurements type not handled
measurementAverage = -1000;
break;
};
// Sanity check if measurement type is not defined
if (measurementAverage == -1000) {
Serial.printf("ERROR! %s is not defined on get average value function\n", measurementTypeStr(type));
delay(1000);
assert(0);
}
return measurementAverage;
}
String Measurements::pms5003FirmwareVersion(int fwCode) { String Measurements::pms5003FirmwareVersion(int fwCode) {
return pms5003FirmwareVersionBase("PMS5003x", fwCode); return pms5003FirmwareVersionBase("PMS5003x", fwCode);
} }
@ -485,11 +531,12 @@ void Measurements::validateChannel(int ch) {
float Measurements::getCorrectedPM25(AirGradient &ag, Configuration &config, bool useAvg, int ch) { float Measurements::getCorrectedPM25(AirGradient &ag, Configuration &config, bool useAvg, int ch) {
float pm25; float pm25;
float corrected;
float humidity; float humidity;
float pm003Count; float pm003Count;
int channel = ch - 1; // Array index
if (useAvg) { if (useAvg) {
// Directly call from the index // Directly call from the index
int channel = ch - 1; // Array index
pm25 = _pm_25[channel].update.avg; pm25 = _pm_25[channel].update.avg;
humidity = _humidity[channel].update.avg; humidity = _humidity[channel].update.avg;
pm003Count = _pm_03_pc[channel].update.avg; pm003Count = _pm_03_pc[channel].update.avg;
@ -500,19 +547,27 @@ float Measurements::getCorrectedPM25(AirGradient &ag, Configuration &config, boo
} }
Configuration::PMCorrection pmCorrection = config.getPMCorrection(); Configuration::PMCorrection pmCorrection = config.getPMCorrection();
if (pmCorrection.algorithm == PMCorrectionAlgorithm::EPA_2021) { switch (pmCorrection.algorithm) {
// EPA correction directly applied case PMCorrectionAlgorithm::Unknown:
pm25 = ag.pms5003.compensate(pm25, humidity); case PMCorrectionAlgorithm::None:
} else { // If correction is Unknown, then default is None
// SLR correction, this is assumes before calling this function, correction algorithm is not None corrected = pm25;
pm25 = ag.pms5003.slrCorrection(pm25, pm003Count, pmCorrection.scalingFactor, pmCorrection.intercept); break;
case PMCorrectionAlgorithm::EPA_2021:
corrected = ag.pms5003.compensate(pm25, humidity);
break;
default: {
// All SLR correction using the same flow, hence default condition
corrected = ag.pms5003.slrCorrection(pm25, pm003Count, pmCorrection.scalingFactor,
pmCorrection.intercept);
if (pmCorrection.useEPA) { if (pmCorrection.useEPA) {
// Add EPA compensation on top of SLR // Add EPA compensation on top of SLR
pm25 = ag.pms5003.compensate(pm25, humidity); corrected = ag.pms5003.compensate(corrected, humidity);
} }
} }
}
return pm25; return corrected;
} }
String Measurements::toString(bool localServer, AgFirmwareMode fwMode, int rssi, AirGradient &ag, String Measurements::toString(bool localServer, AgFirmwareMode fwMode, int rssi, AirGradient &ag,
@ -841,10 +896,10 @@ JSONVar Measurements::buildPMS(AirGradient &ag, int ch, bool allCh, bool withTem
pms[json_prop_pm03Count] = ag.round2(avg); pms[json_prop_pm03Count] = ag.round2(avg);
pms["channels"]["1"][json_prop_pm03Count] = ag.round2(_pm_03_pc[0].update.avg); pms["channels"]["1"][json_prop_pm03Count] = ag.round2(_pm_03_pc[0].update.avg);
pms["channels"]["2"][json_prop_pm03Count] = ag.round2(_pm_03_pc[1].update.avg); pms["channels"]["2"][json_prop_pm03Count] = ag.round2(_pm_03_pc[1].update.avg);
} else if (utils::isValidPm(_pm_03_pc[0].update.avg)) { } else if (utils::isValidPm03Count(_pm_03_pc[0].update.avg)) {
pms[json_prop_pm03Count] = ag.round2(_pm_03_pc[0].update.avg); pms[json_prop_pm03Count] = ag.round2(_pm_03_pc[0].update.avg);
pms["channels"]["1"][json_prop_pm03Count] = ag.round2(_pm_03_pc[0].update.avg); pms["channels"]["1"][json_prop_pm03Count] = ag.round2(_pm_03_pc[0].update.avg);
} else if (utils::isValidPm(_pm_03_pc[1].update.avg)) { } else if (utils::isValidPm03Count(_pm_03_pc[1].update.avg)) {
pms[json_prop_pm03Count] = ag.round2(_pm_03_pc[1].update.avg); pms[json_prop_pm03Count] = ag.round2(_pm_03_pc[1].update.avg);
pms["channels"]["2"][json_prop_pm03Count] = ag.round2(_pm_03_pc[1].update.avg); pms["channels"]["2"][json_prop_pm03Count] = ag.round2(_pm_03_pc[1].update.avg);
} }
@ -856,10 +911,10 @@ JSONVar Measurements::buildPMS(AirGradient &ag, int ch, bool allCh, bool withTem
pms[json_prop_pm05Count] = ag.round2(avg); pms[json_prop_pm05Count] = ag.round2(avg);
pms["channels"]["1"][json_prop_pm05Count] = ag.round2(_pm_05_pc[0].update.avg); pms["channels"]["1"][json_prop_pm05Count] = ag.round2(_pm_05_pc[0].update.avg);
pms["channels"]["2"][json_prop_pm05Count] = ag.round2(_pm_05_pc[1].update.avg); pms["channels"]["2"][json_prop_pm05Count] = ag.round2(_pm_05_pc[1].update.avg);
} else if (utils::isValidPm(_pm_05_pc[0].update.avg)) { } else if (utils::isValidPm03Count(_pm_05_pc[0].update.avg)) {
pms[json_prop_pm05Count] = ag.round2(_pm_05_pc[0].update.avg); pms[json_prop_pm05Count] = ag.round2(_pm_05_pc[0].update.avg);
pms["channels"]["1"][json_prop_pm05Count] = ag.round2(_pm_05_pc[0].update.avg); pms["channels"]["1"][json_prop_pm05Count] = ag.round2(_pm_05_pc[0].update.avg);
} else if (utils::isValidPm(_pm_05_pc[1].update.avg)) { } else if (utils::isValidPm03Count(_pm_05_pc[1].update.avg)) {
pms[json_prop_pm05Count] = ag.round2(_pm_05_pc[1].update.avg); pms[json_prop_pm05Count] = ag.round2(_pm_05_pc[1].update.avg);
pms["channels"]["2"][json_prop_pm05Count] = ag.round2(_pm_05_pc[1].update.avg); pms["channels"]["2"][json_prop_pm05Count] = ag.round2(_pm_05_pc[1].update.avg);
} }
@ -870,10 +925,10 @@ JSONVar Measurements::buildPMS(AirGradient &ag, int ch, bool allCh, bool withTem
pms[json_prop_pm1Count] = ag.round2(avg); pms[json_prop_pm1Count] = ag.round2(avg);
pms["channels"]["1"][json_prop_pm1Count] = ag.round2(_pm_01_pc[0].update.avg); pms["channels"]["1"][json_prop_pm1Count] = ag.round2(_pm_01_pc[0].update.avg);
pms["channels"]["2"][json_prop_pm1Count] = ag.round2(_pm_01_pc[1].update.avg); pms["channels"]["2"][json_prop_pm1Count] = ag.round2(_pm_01_pc[1].update.avg);
} else if (utils::isValidPm(_pm_01_pc[0].update.avg)) { } else if (utils::isValidPm03Count(_pm_01_pc[0].update.avg)) {
pms[json_prop_pm1Count] = ag.round2(_pm_01_pc[0].update.avg); pms[json_prop_pm1Count] = ag.round2(_pm_01_pc[0].update.avg);
pms["channels"]["1"][json_prop_pm1Count] = ag.round2(_pm_01_pc[0].update.avg); pms["channels"]["1"][json_prop_pm1Count] = ag.round2(_pm_01_pc[0].update.avg);
} else if (utils::isValidPm(_pm_01_pc[1].update.avg)) { } else if (utils::isValidPm03Count(_pm_01_pc[1].update.avg)) {
pms[json_prop_pm1Count] = ag.round2(_pm_01_pc[1].update.avg); pms[json_prop_pm1Count] = ag.round2(_pm_01_pc[1].update.avg);
pms["channels"]["2"][json_prop_pm1Count] = ag.round2(_pm_01_pc[1].update.avg); pms["channels"]["2"][json_prop_pm1Count] = ag.round2(_pm_01_pc[1].update.avg);
} }
@ -885,10 +940,10 @@ JSONVar Measurements::buildPMS(AirGradient &ag, int ch, bool allCh, bool withTem
pms[json_prop_pm25Count] = ag.round2(avg); pms[json_prop_pm25Count] = ag.round2(avg);
pms["channels"]["1"][json_prop_pm25Count] = ag.round2(_pm_25_pc[0].update.avg); pms["channels"]["1"][json_prop_pm25Count] = ag.round2(_pm_25_pc[0].update.avg);
pms["channels"]["2"][json_prop_pm25Count] = ag.round2(_pm_25_pc[1].update.avg); pms["channels"]["2"][json_prop_pm25Count] = ag.round2(_pm_25_pc[1].update.avg);
} else if (utils::isValidPm(_pm_25_pc[0].update.avg)) { } else if (utils::isValidPm03Count(_pm_25_pc[0].update.avg)) {
pms[json_prop_pm25Count] = ag.round2(_pm_25_pc[0].update.avg); pms[json_prop_pm25Count] = ag.round2(_pm_25_pc[0].update.avg);
pms["channels"]["1"][json_prop_pm25Count] = ag.round2(_pm_25_pc[0].update.avg); pms["channels"]["1"][json_prop_pm25Count] = ag.round2(_pm_25_pc[0].update.avg);
} else if (utils::isValidPm(_pm_25_pc[1].update.avg)) { } else if (utils::isValidPm03Count(_pm_25_pc[1].update.avg)) {
pms[json_prop_pm25Count] = ag.round2(_pm_25_pc[1].update.avg); pms[json_prop_pm25Count] = ag.round2(_pm_25_pc[1].update.avg);
pms["channels"]["2"][json_prop_pm25Count] = ag.round2(_pm_25_pc[1].update.avg); pms["channels"]["2"][json_prop_pm25Count] = ag.round2(_pm_25_pc[1].update.avg);
} }

View File

@ -114,9 +114,19 @@ public:
*/ */
float getFloat(MeasurementType type, int ch = 1); float getFloat(MeasurementType type, int ch = 1);
/**
* @brief Get the target measurement average value
*
* @param type measurement type that will be retrieve
* @param ch target type value channel
* @return moving average value of target measurements type
*/
float getAverage(MeasurementType type, int ch = 1);
/** /**
* @brief Get the Corrected PM25 object based on the correction algorithm from configuration * @brief Get the Corrected PM25 object based on the correction algorithm from configuration
*
* If correction is not enabled, then will return the raw value (either average or last value)
* *
* @param ag AirGradient instance * @param ag AirGradient instance
* @param config Configuration instance * @param config Configuration instance

View File

@ -15,7 +15,7 @@
#include "Main/utils.h" #include "Main/utils.h"
#ifndef GIT_VERSION #ifndef GIT_VERSION
#define GIT_VERSION "3.1.10-snap" #define GIT_VERSION "3.1.14-snap"
#endif #endif
/** /**