Skip to content

Commit

Permalink
Merge pull request #247 from airgradienthq/fix/pms-read-data
Browse files Browse the repository at this point in the history
Fix: PMS sensor read failed in case PM value is low
  • Loading branch information
airgradienthq committed Sep 24, 2024
2 parents 0370a8a + 359394a commit c841476
Show file tree
Hide file tree
Showing 11 changed files with 232 additions and 180 deletions.
2 changes: 1 addition & 1 deletion examples/BASIC/BASIC.ino
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ static void updateTvoc(void) {
}

static void updatePm(void) {
if (ag.pms5003.isFailed() == false) {
if (ag.pms5003.connected()) {
measurements.pm01_1 = ag.pms5003.getPm01Ae();
measurements.pm25_1 = ag.pms5003.getPm25Ae();
measurements.pm10_1 = ag.pms5003.getPm10Ae();
Expand Down
2 changes: 1 addition & 1 deletion examples/DiyProIndoorV3_3/DiyProIndoorV3_3.ino
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ static void updateTvoc(void) {
}

static void updatePm(void) {
if (ag.pms5003.isFailed() == false) {
if (ag.pms5003.connected()) {
measurements.pm01_1 = ag.pms5003.getPm01Ae();
measurements.pm25_1 = ag.pms5003.getPm25Ae();
measurements.pm10_1 = ag.pms5003.getPm10Ae();
Expand Down
2 changes: 1 addition & 1 deletion examples/DiyProIndoorV4_2/DiyProIndoorV4_2.ino
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,7 @@ static void updateTvoc(void) {
}

static void updatePm(void) {
if (ag.pms5003.isFailed() == false) {
if (ag.pms5003.connected()) {
measurements.pm01_1 = ag.pms5003.getPm01Ae();
measurements.pm25_1 = ag.pms5003.getPm25Ae();
measurements.pm10_1 = ag.pms5003.getPm10Ae();
Expand Down
11 changes: 8 additions & 3 deletions examples/OneOpenAir/OneOpenAir.ino
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,11 @@ void loop() {
if (ag->isOne()) {
if (configuration.hasSensorPMS1) {
ag->pms5003.handle();
static bool pmsConnected = false;
if (pmsConnected != ag->pms5003.connected()) {
pmsConnected = ag->pms5003.connected();
Serial.printf("PMS sensor %s ", pmsConnected?"connected":"removed");
}
}
} else {
if (configuration.hasSensorPMS1) {
Expand Down Expand Up @@ -992,7 +997,7 @@ static void updateTvoc(void) {
static void updatePm(void) {
bool restart = false;
if (ag->isOne()) {
if (ag->pms5003.isFailed() == false) {
if (ag->pms5003.connected()) {
measurements.pm01_1 = ag->pms5003.getPm01Ae();
measurements.pm25_1 = ag->pms5003.getPm25Ae();
measurements.pm10_1 = ag->pms5003.getPm10Ae();
Expand Down Expand Up @@ -1022,7 +1027,7 @@ static void updatePm(void) {
} else {
bool pmsResult_1 = false;
bool pmsResult_2 = false;
if (configuration.hasSensorPMS1 && (ag->pms5003t_1.isFailed() == false)) {
if (configuration.hasSensorPMS1 && ag->pms5003t_1.connected()) {
measurements.pm01_1 = ag->pms5003t_1.getPm01Ae();
measurements.pm25_1 = ag->pms5003t_1.getPm25Ae();
measurements.pm10_1 = ag->pms5003t_1.getPm10Ae();
Expand Down Expand Up @@ -1066,7 +1071,7 @@ static void updatePm(void) {
}
}

if (configuration.hasSensorPMS2 && (ag->pms5003t_2.isFailed() == false)) {
if (configuration.hasSensorPMS2 && ag->pms5003t_2.connected()) {
measurements.pm01_2 = ag->pms5003t_2.getPm01Ae();
measurements.pm25_2 = ag->pms5003t_2.getPm25Ae();
measurements.pm10_2 = ag->pms5003t_2.getPm10Ae();
Expand Down
6 changes: 3 additions & 3 deletions examples/TestPM/TestPM.ino
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ void loop() {
if (ms >= 5000) {
lastRead = millis();
#ifdef ESP8266
if (ag.pms5003.isFailed() == false) {
if (ag.pms5003.connected()) {
PM2 = ag.pms5003.getPm25Ae();
Serial.printf("PM2.5 in ug/m3: %d\r\n", PM2);
Serial.printf("PM2.5 in US AQI: %d\r\n",
Expand All @@ -54,12 +54,12 @@ void loop() {
}
#else
if (ag.getBoardType() == OPEN_AIR_OUTDOOR) {
if (ag.pms5003t_1.isFailed() == false) {
if (ag.pms5003t_1.connected()) {
PM2 = ag.pms5003t_1.getPm25Ae();
readResul = true;
}
} else {
if (ag.pms5003.isFailed() == false) {
if (ag.pms5003.connected()) {
PM2 = ag.pms5003.getPm25Ae();
readResul = true;
}
Expand Down
Loading

0 comments on commit c841476

Please sign in to comment.