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

View File

@ -690,6 +690,7 @@ bool hasSensorS8 = true;
bool hasSensorPMS = true; bool hasSensorPMS = true;
bool hasSensorSGP = true; bool hasSensorSGP = true;
bool hasSensorSHT = true; bool hasSensorSHT = true;
int pmFailCount = 0;
AgSchedule dispLedSchedule(DISP_UPDATE_INTERVAL, updateDispLedBar); AgSchedule dispLedSchedule(DISP_UPDATE_INTERVAL, updateDispLedBar);
AgSchedule configSchedule(SERVER_CONFIG_UPDATE_INTERVAL, serverConfigPoll); AgSchedule configSchedule(SERVER_CONFIG_UPDATE_INTERVAL, serverConfigPoll);
AgSchedule serverSchedule(SERVER_SYNC_INTERVAL, sendDataToServer); AgSchedule serverSchedule(SERVER_SYNC_INTERVAL, sendDataToServer);
@ -1035,7 +1036,7 @@ static void displayShowDashboard(String err) {
/** Show temperature */ /** Show temperature */
if (agServer.isTemperatureUnitF()) { if (agServer.isTemperatureUnitF()) {
if (temp > -10001) { if (temp > -1001) {
float tempF = (temp * 9 / 5) + 32; float tempF = (temp * 9 / 5) + 32;
sprintf(strBuf, "%.1f°F", tempF); sprintf(strBuf, "%.1f°F", tempF);
} else { } else {
@ -1043,7 +1044,7 @@ static void displayShowDashboard(String err) {
} }
u8g2.drawUTF8(1, 10, strBuf); u8g2.drawUTF8(1, 10, strBuf);
} else { } else {
if (temp > -10001) { if (temp > -1001) {
sprintf(strBuf, "%.1f°C", temp); sprintf(strBuf, "%.1f°C", temp);
} else { } else {
sprintf(strBuf, "-°C"); sprintf(strBuf, "-°C");
@ -1070,7 +1071,7 @@ static void displayShowDashboard(String err) {
if (err == "WiFi N/A") { if (err == "WiFi N/A") {
u8g2.setFont(u8g2_font_t0_12_tf); u8g2.setFont(u8g2_font_t0_12_tf);
if (agServer.isTemperatureUnitF()) { if (agServer.isTemperatureUnitF()) {
if (temp > -10001) { if (temp > -1001) {
float tempF = (temp * 9 / 5) + 32; float tempF = (temp * 9 / 5) + 32;
sprintf(strBuf, "%.1f", tempF); sprintf(strBuf, "%.1f", tempF);
} else { } else {
@ -1078,7 +1079,7 @@ static void displayShowDashboard(String err) {
} }
u8g2.drawUTF8(1, 10, strBuf); u8g2.drawUTF8(1, 10, strBuf);
} else { } else {
if (temp > -10001) { if (temp > -1001) {
sprintf(strBuf, "%.1f", temp); sprintf(strBuf, "%.1f", temp);
} else { } else {
sprintf(strBuf, "-"); sprintf(strBuf, "-");
@ -1810,11 +1811,16 @@ static void pmPoll(void) {
Serial.printf(" PMS2.5: %d\r\n", pm25); Serial.printf(" PMS2.5: %d\r\n", pm25);
Serial.printf(" PMS10.0: %d\r\n", pm10); Serial.printf(" PMS10.0: %d\r\n", pm10);
Serial.printf("PMS3.0 Count: %d\r\n", pm03PCount); Serial.printf("PMS3.0 Count: %d\r\n", pm03PCount);
pmFailCount = 0;
} else { } else {
pm01 = -1; pmFailCount++;
pm25 = -1; Serial.printf("PM read failed: %d\r\n", pmFailCount);
pm10 = -1; if (pmFailCount >= 3) {
pm03PCount = -1; pm01 = -1;
pm25 = -1;
pm10 = -1;
pm03PCount = -1;
}
} }
} }