Fix: PMS Read Failed

This commit is contained in:
Phat Nguyen
2024-03-14 21:17:43 +07:00
parent d92d312b0c
commit be1a9778e6
13 changed files with 409 additions and 336 deletions

View File

@ -457,6 +457,9 @@ void loop() {
}
updateWiFiConnect();
/** Read PMS on loop */
ag.pms5003.handle();
}
static void sendPing() {
@ -629,7 +632,7 @@ static void co2Update() {
}
void pmUpdate() {
if (ag.pms5003.readData()) {
if (ag.pms5003.isFailed() == false) {
pm25 = ag.pms5003.getPm25Ae();
Serial.printf("PMS2.5: %d\r\n", pm25);
pmFailCount = 0;

View File

@ -845,6 +845,11 @@ void loop() {
/** factory reset handle */
factoryConfigReset();
/** Read PMS on loop */
if (hasSensorPMS) {
ag.pms5003.handle();
}
}
static void setTestColor(char color) {
@ -2240,7 +2245,7 @@ static void tvocUpdate(void) {
*
*/
static void pmUpdate(void) {
if (ag.pms5003.readData()) {
if (ag.pms5003.isFailed() == false) {
pm01 = ag.pms5003.getPm01Ae();
pm25 = ag.pms5003.getPm25Ae();
pm10 = ag.pms5003.getPm10Ae();

View File

@ -57,7 +57,7 @@ enum {
phone */
APP_SM_WIFI_MANAGER_STA_CONNECTING, /** After SSID and PW entered and OK
clicked, connection to WiFI network is
attempted*/
attempted*/
APP_SM_WIFI_MANAGER_STA_CONNECTED, /** Connecting to WiFi worked */
APP_SM_WIFI_OK_SERVER_CONNECTING, /** Once connected to WiFi an attempt to
reach the server is performed */
@ -802,6 +802,13 @@ void loop() {
updateWiFiConnect();
factoryConfigReset();
if (hasSensorPMS1) {
ag.pms5003t_1.handle();
}
if (hasSensorPMS2) {
ag.pms5003t_2.handle();
}
}
void sendPing() {
@ -1101,7 +1108,7 @@ static void tvocUpdate(void) {
static void pmUpdate(void) {
bool pmsResult_1 = false;
bool pmsResult_2 = false;
if (hasSensorPMS1 && ag.pms5003t_1.readData()) {
if (hasSensorPMS1 && (ag.pms5003t_1.isFailed() == false)) {
pm01_1 = ag.pms5003t_1.getPm01Ae();
pm25_1 = ag.pms5003t_1.getPm25Ae();
pm10_1 = ag.pms5003t_1.getPm10Ae();
@ -1127,7 +1134,7 @@ static void pmUpdate(void) {
hum_1 = -1;
}
if (hasSensorPMS2 && ag.pms5003t_2.readData()) {
if (hasSensorPMS2 && (ag.pms5003t_2.isFailed() == false)) {
pm01_2 = ag.pms5003t_2.getPm01Ae();
pm25_2 = ag.pms5003t_2.getPm25Ae();
pm10_2 = ag.pms5003t_2.getPm10Ae();

View File

@ -10,8 +10,8 @@ CC BY-SA 4.0 Attribution-ShareAlike 4.0 International License
#ifdef ESP8266
AirGradient ag = AirGradient(DIY_BASIC);
#else
// AirGradient ag = AirGradient(ONE_INDOOR);
AirGradient ag = AirGradient(OPEN_AIR_OUTDOOR);
AirGradient ag = AirGradient(ONE_INDOOR);
// AirGradient ag = AirGradient(OPEN_AIR_OUTDOOR);
#endif
void failedHandler(String msg);
@ -35,42 +35,56 @@ void setup() {
#endif
}
uint32_t lastRead = 0;
void loop() {
int PM2;
bool readResul = false;
#ifdef ESP8266
if (ag.pms5003.readData()) {
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",
ag.pms5003.convertPm25ToUsAqi(PM2));
}
#else
if (ag.getBoardType() == OPEN_AIR_OUTDOOR) {
if (ag.pms5003t_1.readData()) {
PM2 = ag.pms5003t_1.getPm25Ae();
readResul = true;
}
} else {
if (ag.pms5003.readData()) {
PM2 = ag.pms5003.getPm25Ae();
readResul = true;
}
}
if (readResul) {
Serial.printf("PM2.5 in ug/m3: %d\r\n", PM2);
if (ag.getBoardType() == OPEN_AIR_OUTDOOR) {
Serial.printf("PM2.5 in US AQI: %d\r\n",
ag.pms5003t_1.convertPm25ToUsAqi(PM2));
} else {
uint32_t ms = (uint32_t)(millis() - lastRead);
if (ms >= 5000) {
lastRead = millis();
#ifdef ESP8266
if (ag.pms5003.isFailed() == false) {
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",
ag.pms5003.convertPm25ToUsAqi(PM2));
} else {
Serial.println("PMS sensor failed");
}
#else
if (ag.getBoardType() == OPEN_AIR_OUTDOOR) {
if (ag.pms5003t_1.isFailed() == false) {
PM2 = ag.pms5003t_1.getPm25Ae();
readResul = true;
}
} else {
if (ag.pms5003.isFailed() == false) {
PM2 = ag.pms5003.getPm25Ae();
readResul = true;
}
}
}
#endif
delay(5000);
if (readResul) {
Serial.printf("PM2.5 in ug/m3: %d\r\n", PM2);
if (ag.getBoardType() == OPEN_AIR_OUTDOOR) {
Serial.printf("PM2.5 in US AQI: %d\r\n",
ag.pms5003t_1.convertPm25ToUsAqi(PM2));
} else {
Serial.printf("PM2.5 in US AQI: %d\r\n",
ag.pms5003.convertPm25ToUsAqi(PM2));
}
} else {
Serial.println("PMS sensor failed");
}
#endif
}
if (ag.getBoardType() == OPEN_AIR_OUTDOOR) {
ag.pms5003t_1.handle();
} else {
ag.pms5003.handle();
}
}
void failedHandler(String msg) {