PMS5003 add failed count to 3 before show invalid value to display

This commit is contained in:
Phat Nguyen
2024-02-20 20:36:06 +07:00
parent 2aab02940d
commit 14fb790e2a
2 changed files with 21 additions and 9 deletions

View File

@ -381,6 +381,7 @@ static void showNr(void);
bool hasSensorS8 = true;
bool hasSensorPMS = true;
bool hasSensorSHT = true;
int pmFailCount = 0;
AgSchedule configSchedule(SERVER_CONFIG_UPDATE_INTERVAL, serverConfigPoll);
AgSchedule serverSchedule(SERVER_SYNC_INTERVAL, sendDataToServer);
AgSchedule dispSchedule(DISP_UPDATE_INTERVAL, dispHandler);
@ -617,8 +618,13 @@ void pmPoll() {
if (ag.pms5003.readData()) {
pm25 = ag.pms5003.getPm25Ae();
Serial.printf("PMS2.5: %d\r\n", pm25);
pmFailCount = 0;
} else {
pm25 = -1;
Seria.printf("PM read failed, %d", pmFailCount);
pmFailCount++;
if (pmFailCount >= 3) {
pm25 = -1;
}
}
}