Skip to content

Commit

Permalink
Merge pull request #229 from airgradienthq/develop
Browse files Browse the repository at this point in the history
Merge to Master to Release 3.1.6
  • Loading branch information
airgradienthq authored Sep 2, 2024
2 parents 7471d80 + 87cc3fc commit 29491e4
Show file tree
Hide file tree
Showing 25 changed files with 511 additions and 211 deletions.
22 changes: 13 additions & 9 deletions examples/BASIC/BASIC.ino
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ static LocalServer localServer(Serial, openMetrics, measurements, configuration,
wifiConnector);
static MqttClient mqttClient(Serial);

static int pmFailCount = 0;
static int getCO2FailCount = 0;
static AgFirmwareMode fwMode = FW_MODE_I_BASIC_40PS;

Expand Down Expand Up @@ -514,15 +513,20 @@ static void updatePm(void) {
Serial.printf("PM2.5 ug/m3: %d\r\n", measurements.pm25_1);
Serial.printf("PM10 ug/m3: %d\r\n", measurements.pm10_1);
Serial.printf("PM0.3 Count: %d\r\n", measurements.pm03PCount_1);
pmFailCount = 0;
ag.pms5003.resetFailCount();
} else {
pmFailCount++;
Serial.printf("PMS read failed: %d\r\n", pmFailCount);
if (pmFailCount >= 3) {
measurements.pm01_1 = utils::getInvalidPMS();
measurements.pm25_1 = utils::getInvalidPMS();
measurements.pm10_1 = utils::getInvalidPMS();
measurements.pm03PCount_1 = utils::getInvalidPMS();
ag.pms5003.updateFailCount();
Serial.printf("PMS read failed %d times\r\n", ag.pms5003.getFailCount());
if (ag.pms5003.getFailCount() >= PMS_FAIL_COUNT_SET_INVALID) {
measurements.pm01_1 = utils::getInvalidPmValue();
measurements.pm25_1 = utils::getInvalidPmValue();
measurements.pm10_1 = utils::getInvalidPmValue();
measurements.pm03PCount_1 = utils::getInvalidPmValue();
}

if(ag.pms5003.getFailCount() >= ag.pms5003.getFailCountMax()) {
Serial.printf("PMS failure count reach to max set %d, restarting...", ag.pms5003.getFailCountMax());
ESP.restart();
}
}
}
Expand Down
16 changes: 8 additions & 8 deletions examples/BASIC/OpenMetrics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@ String OpenMetrics::getPayload(void) {

float _temp = utils::getInvalidTemperature();
float _hum = utils::getInvalidHumidity();
int pm01 = utils::getInvalidPMS();
int pm25 = utils::getInvalidPMS();
int pm10 = utils::getInvalidPMS();
int pm03PCount = utils::getInvalidPMS();
int pm01 = utils::getInvalidPmValue();
int pm25 = utils::getInvalidPmValue();
int pm10 = utils::getInvalidPmValue();
int pm03PCount = utils::getInvalidPmValue();
int atmpCompensated = utils::getInvalidTemperature();
int ahumCompensated = utils::getInvalidHumidity();

Expand All @@ -89,28 +89,28 @@ String OpenMetrics::getPayload(void) {
}

if (config.hasSensorPMS1) {
if (utils::isValidPMS(pm01)) {
if (utils::isValidPm(pm01)) {
add_metric("pm1",
"PM1.0 concentration as measured by the AirGradient PMS "
"sensor, in micrograms per cubic meter",
"gauge", "ugm3");
add_metric_point("", String(pm01));
}
if (utils::isValidPMS(pm25)) {
if (utils::isValidPm(pm25)) {
add_metric("pm2d5",
"PM2.5 concentration as measured by the AirGradient PMS "
"sensor, in micrograms per cubic meter",
"gauge", "ugm3");
add_metric_point("", String(pm25));
}
if (utils::isValidPMS(pm10)) {
if (utils::isValidPm(pm10)) {
add_metric("pm10",
"PM10 concentration as measured by the AirGradient PMS "
"sensor, in micrograms per cubic meter",
"gauge", "ugm3");
add_metric_point("", String(pm10));
}
if (utils::isValidPMS03Count(pm03PCount)) {
if (utils::isValidPm03Count(pm03PCount)) {
add_metric("pm0d3",
"PM0.3 concentration as measured by the AirGradient PMS "
"sensor, in number of particules per 100 milliliters",
Expand Down
22 changes: 13 additions & 9 deletions examples/DiyProIndoorV3_3/DiyProIndoorV3_3.ino
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ static LocalServer localServer(Serial, openMetrics, measurements, configuration,
wifiConnector);
static MqttClient mqttClient(Serial);

static int pmFailCount = 0;
static int getCO2FailCount = 0;
static AgFirmwareMode fwMode = FW_MODE_I_33PS;

Expand Down Expand Up @@ -566,15 +565,20 @@ static void updatePm(void) {
Serial.printf("PM2.5 ug/m3: %d\r\n", measurements.pm25_1);
Serial.printf("PM10 ug/m3: %d\r\n", measurements.pm10_1);
Serial.printf("PM0.3 Count: %d\r\n", measurements.pm03PCount_1);
pmFailCount = 0;
ag.pms5003.resetFailCount();
} else {
pmFailCount++;
Serial.printf("PMS read failed: %d\r\n", pmFailCount);
if (pmFailCount >= 3) {
measurements.pm01_1 = utils::getInvalidPMS();
measurements.pm25_1 = utils::getInvalidPMS();
measurements.pm10_1 = utils::getInvalidPMS();
measurements.pm03PCount_1 = utils::getInvalidPMS();
ag.pms5003.updateFailCount();
Serial.printf("PMS read failed %d times\r\n", ag.pms5003.getFailCount());
if (ag.pms5003.getFailCount() >= PMS_FAIL_COUNT_SET_INVALID) {
measurements.pm01_1 = utils::getInvalidPmValue();
measurements.pm25_1 = utils::getInvalidPmValue();
measurements.pm10_1 = utils::getInvalidPmValue();
measurements.pm03PCount_1 = utils::getInvalidPmValue();
}

if(ag.pms5003.getFailCount() >= ag.pms5003.getFailCountMax()) {
Serial.printf("PMS failure count reach to max set %d, restarting...", ag.pms5003.getFailCountMax());
ESP.restart();
}
}
}
Expand Down
16 changes: 8 additions & 8 deletions examples/DiyProIndoorV3_3/OpenMetrics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@ String OpenMetrics::getPayload(void) {

float _temp = utils::getInvalidTemperature();
float _hum = utils::getInvalidHumidity();
int pm01 = utils::getInvalidPMS();
int pm25 = utils::getInvalidPMS();
int pm10 = utils::getInvalidPMS();
int pm03PCount = utils::getInvalidPMS();
int pm01 = utils::getInvalidPmValue();
int pm25 = utils::getInvalidPmValue();
int pm10 = utils::getInvalidPmValue();
int pm03PCount = utils::getInvalidPmValue();
int atmpCompensated = utils::getInvalidTemperature();
int ahumCompensated = utils::getInvalidHumidity();

Expand All @@ -89,28 +89,28 @@ String OpenMetrics::getPayload(void) {
}

if (config.hasSensorPMS1) {
if (utils::isValidPMS(pm01)) {
if (utils::isValidPm(pm01)) {
add_metric("pm1",
"PM1.0 concentration as measured by the AirGradient PMS "
"sensor, in micrograms per cubic meter",
"gauge", "ugm3");
add_metric_point("", String(pm01));
}
if (utils::isValidPMS(pm25)) {
if (utils::isValidPm(pm25)) {
add_metric("pm2d5",
"PM2.5 concentration as measured by the AirGradient PMS "
"sensor, in micrograms per cubic meter",
"gauge", "ugm3");
add_metric_point("", String(pm25));
}
if (utils::isValidPMS(pm10)) {
if (utils::isValidPm(pm10)) {
add_metric("pm10",
"PM10 concentration as measured by the AirGradient PMS "
"sensor, in micrograms per cubic meter",
"gauge", "ugm3");
add_metric_point("", String(pm10));
}
if (utils::isValidPMS03Count(pm03PCount)) {
if (utils::isValidPm03Count(pm03PCount)) {
add_metric("pm0d3",
"PM0.3 concentration as measured by the AirGradient PMS "
"sensor, in number of particules per 100 milliliters",
Expand Down
22 changes: 13 additions & 9 deletions examples/DiyProIndoorV4_2/DiyProIndoorV4_2.ino
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ static LocalServer localServer(Serial, openMetrics, measurements, configuration,
wifiConnector);
static MqttClient mqttClient(Serial);

static int pmFailCount = 0;
static uint32_t factoryBtnPressTime = 0;
static int getCO2FailCount = 0;
static AgFirmwareMode fwMode = FW_MODE_I_42PS;
Expand Down Expand Up @@ -609,15 +608,20 @@ static void updatePm(void) {
Serial.printf("PM2.5 ug/m3: %d\r\n", measurements.pm25_1);
Serial.printf("PM10 ug/m3: %d\r\n", measurements.pm10_1);
Serial.printf("PM0.3 Count: %d\r\n", measurements.pm03PCount_1);
pmFailCount = 0;
ag.pms5003.resetFailCount();
} else {
pmFailCount++;
Serial.printf("PMS read failed: %d\r\n", pmFailCount);
if (pmFailCount >= 3) {
measurements.pm01_1 = utils::getInvalidPMS();
measurements.pm25_1 = utils::getInvalidPMS();
measurements.pm10_1 = utils::getInvalidPMS();
measurements.pm03PCount_1 = utils::getInvalidPMS();
ag.pms5003.updateFailCount();
Serial.printf("PMS read failed %d times\r\n", ag.pms5003.getFailCount());
if (ag.pms5003.getFailCount() >= PMS_FAIL_COUNT_SET_INVALID) {
measurements.pm01_1 = utils::getInvalidPmValue();
measurements.pm25_1 = utils::getInvalidPmValue();
measurements.pm10_1 = utils::getInvalidPmValue();
measurements.pm03PCount_1 = utils::getInvalidPmValue();
}

if(ag.pms5003.getFailCount() >= ag.pms5003.getFailCountMax()) {
Serial.printf("PMS failure count reach to max set %d, restarting...", ag.pms5003.getFailCountMax());
ESP.restart();
}
}
}
Expand Down
16 changes: 8 additions & 8 deletions examples/DiyProIndoorV4_2/OpenMetrics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@ String OpenMetrics::getPayload(void) {

float _temp = utils::getInvalidTemperature();
float _hum = utils::getInvalidHumidity();
int pm01 = utils::getInvalidPMS();
int pm25 = utils::getInvalidPMS();
int pm10 = utils::getInvalidPMS();
int pm03PCount = utils::getInvalidPMS();
int pm01 = utils::getInvalidPmValue();
int pm25 = utils::getInvalidPmValue();
int pm10 = utils::getInvalidPmValue();
int pm03PCount = utils::getInvalidPmValue();
int atmpCompensated = utils::getInvalidTemperature();
int ahumCompensated = utils::getInvalidHumidity();

Expand All @@ -89,28 +89,28 @@ String OpenMetrics::getPayload(void) {
}

if (config.hasSensorPMS1) {
if (utils::isValidPMS(pm01)) {
if (utils::isValidPm(pm01)) {
add_metric("pm1",
"PM1.0 concentration as measured by the AirGradient PMS "
"sensor, in micrograms per cubic meter",
"gauge", "ugm3");
add_metric_point("", String(pm01));
}
if (utils::isValidPMS(pm25)) {
if (utils::isValidPm(pm25)) {
add_metric("pm2d5",
"PM2.5 concentration as measured by the AirGradient PMS "
"sensor, in micrograms per cubic meter",
"gauge", "ugm3");
add_metric_point("", String(pm25));
}
if (utils::isValidPMS(pm10)) {
if (utils::isValidPm(pm10)) {
add_metric("pm10",
"PM10 concentration as measured by the AirGradient PMS "
"sensor, in micrograms per cubic meter",
"gauge", "ugm3");
add_metric_point("", String(pm10));
}
if (utils::isValidPMS03Count(pm03PCount)) {
if (utils::isValidPm03Count(pm03PCount)) {
add_metric("pm0d3",
"PM0.3 concentration as measured by the AirGradient PMS "
"sensor, in number of particules per 100 milliliters",
Expand Down
92 changes: 65 additions & 27 deletions examples/OneOpenAir/OneOpenAir.ino
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ static OtaHandler otaHandler;
static LocalServer localServer(Serial, openMetrics, measurements, configuration,
wifiConnector);

static int pmFailCount = 0;
static uint32_t factoryBtnPressTime = 0;
static int getCO2FailCount = 0;
static AgFirmwareMode fwMode = FW_MODE_I_9PSL;
Expand Down Expand Up @@ -940,6 +939,9 @@ static void configUpdateHandle() {

stateMachine.executeLedBarTest();
}
else if(ag->isOpenAir()) {
stateMachine.executeLedBarTest();
}

appDispHandler();
appLedHandler();
Expand Down Expand Up @@ -1006,6 +1008,7 @@ static void updateTvoc(void) {
}

static void updatePm(void) {
bool restart = false;
if (ag->isOne()) {
if (ag->pms5003.isFailed() == false) {
measurements.pm01_1 = ag->pms5003.getPm01Ae();
Expand All @@ -1018,15 +1021,19 @@ static void updatePm(void) {
Serial.printf("PM2.5 ug/m3: %d\r\n", measurements.pm25_1);
Serial.printf("PM10 ug/m3: %d\r\n", measurements.pm10_1);
Serial.printf("PM0.3 Count: %d\r\n", measurements.pm03PCount_1);
pmFailCount = 0;
ag->pms5003.resetFailCount();
} else {
pmFailCount++;
Serial.printf("PMS read failed: %d\r\n", pmFailCount);
if (pmFailCount >= 3) {
measurements.pm01_1 = utils::getInvalidPMS();
measurements.pm25_1 = utils::getInvalidPMS();
measurements.pm10_1 = utils::getInvalidPMS();
measurements.pm03PCount_1 = utils::getInvalidPMS();
ag->pms5003.updateFailCount();
Serial.printf("PMS read faile %d times\r\n", ag->pms5003.getFailCount());
if (ag->pms5003.getFailCount() >= PMS_FAIL_COUNT_SET_INVALID) {
measurements.pm01_1 = utils::getInvalidPmValue();
measurements.pm25_1 = utils::getInvalidPmValue();
measurements.pm10_1 = utils::getInvalidPmValue();
measurements.pm03PCount_1 = utils::getInvalidPmValue();
}

if (ag->pms5003.getFailCount() >= ag->pms5003.getFailCountMax()) {
restart = true;
}
}
} else {
Expand All @@ -1050,16 +1057,29 @@ static void updatePm(void) {
Serial.printf("[1] Temperature in C: %0.2f\r\n", measurements.temp_1);
Serial.printf("[1] Relative Humidity: %d\r\n", measurements.hum_1);
Serial.printf("[1] Temperature compensated in C: %0.2f\r\n",
ag->pms5003t_1.temperatureCompensated(measurements.temp_1));
Serial.printf("[1] Relative Humidity compensated: %f\r\n",
ag->pms5003t_1.humidityCompensated(measurements.hum_1));
ag->pms5003t_1.compensateTemp(measurements.temp_1));
Serial.printf("[1] Relative Humidity compensated: %0.2f\r\n",
ag->pms5003t_1.compensateHum(measurements.hum_1));

ag->pms5003t_1.resetFailCount();
} else {
measurements.pm01_1 = utils::getInvalidPMS();
measurements.pm25_1 = utils::getInvalidPMS();
measurements.pm10_1 = utils::getInvalidPMS();
measurements.pm03PCount_1 = utils::getInvalidPMS();
measurements.temp_1 = utils::getInvalidTemperature();
measurements.hum_1 = utils::getInvalidHumidity();
if (configuration.hasSensorPMS1) {
ag->pms5003t_1.updateFailCount();
Serial.printf("[1] PMS read failed %d times\r\n", ag->pms5003t_1.getFailCount());

if (ag->pms5003t_1.getFailCount() >= PMS_FAIL_COUNT_SET_INVALID) {
measurements.pm01_1 = utils::getInvalidPmValue();
measurements.pm25_1 = utils::getInvalidPmValue();
measurements.pm10_1 = utils::getInvalidPmValue();
measurements.pm03PCount_1 = utils::getInvalidPmValue();
measurements.temp_1 = utils::getInvalidTemperature();
measurements.hum_1 = utils::getInvalidHumidity();
}

if (ag->pms5003t_1.getFailCount() >= ag->pms5003t_1.getFailCountMax()) {
restart = true;
}
}
}

if (configuration.hasSensorPMS2 && (ag->pms5003t_2.isFailed() == false)) {
Expand All @@ -1080,16 +1100,29 @@ static void updatePm(void) {
Serial.printf("[2] Temperature in C: %0.2f\r\n", measurements.temp_2);
Serial.printf("[2] Relative Humidity: %d\r\n", measurements.hum_2);
Serial.printf("[2] Temperature compensated in C: %0.2f\r\n",
ag->pms5003t_1.temperatureCompensated(measurements.temp_2));
Serial.printf("[2] Relative Humidity compensated: %d\r\n",
ag->pms5003t_1.humidityCompensated(measurements.hum_2));
ag->pms5003t_1.compensateTemp(measurements.temp_2));
Serial.printf("[2] Relative Humidity compensated: %0.2f\r\n",
ag->pms5003t_1.compensateHum(measurements.hum_2));

ag->pms5003t_2.resetFailCount();
} else {
measurements.pm01_2 = utils::getInvalidPMS();
measurements.pm25_2 = utils::getInvalidPMS();
measurements.pm10_2 = utils::getInvalidPMS();
measurements.pm03PCount_2 = utils::getInvalidPMS();
measurements.temp_2 = utils::getInvalidTemperature();
measurements.hum_2 = utils::getInvalidHumidity();
if (configuration.hasSensorPMS2) {
ag->pms5003t_2.updateFailCount();
Serial.printf("[2] PMS read failed %d times\r\n", ag->pms5003t_2.getFailCount());

if (ag->pms5003t_2.getFailCount() >= PMS_FAIL_COUNT_SET_INVALID) {
measurements.pm01_2 = utils::getInvalidPmValue();
measurements.pm25_2 = utils::getInvalidPmValue();
measurements.pm10_2 = utils::getInvalidPmValue();
measurements.pm03PCount_2 = utils::getInvalidPmValue();
measurements.temp_2 = utils::getInvalidTemperature();
measurements.hum_2 = utils::getInvalidHumidity();
}

if (ag->pms5003t_2.getFailCount() >= ag->pms5003t_2.getFailCountMax()) {
restart = true;
}
}
}

if (configuration.hasSensorPMS1 && configuration.hasSensorPMS2 &&
Expand Down Expand Up @@ -1189,6 +1222,11 @@ static void updatePm(void) {
ag->sgp41.setCompensationTemperatureHumidity(temp, hum);
}
}

if (restart) {
Serial.printf("PMS failure count reach to max set %d, restarting...", ag->pms5003.getFailCountMax());
ESP.restart();
}
}

static void sendDataToServer(void) {
Expand Down
Loading

0 comments on commit 29491e4

Please sign in to comment.