Skip to content

Commit

Permalink
Fix: PMS Read Failed
Browse files Browse the repository at this point in the history
  • Loading branch information
pnt325 committed Mar 14, 2024
1 parent d92d312 commit be1a977
Show file tree
Hide file tree
Showing 13 changed files with 398 additions and 325 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ If you have any questions or problems, check out [our forum](https://forum.airgr
- [Sensirion Core](https://github.com/Sensirion/arduino-core/)
- [Sensirion I2C SGP41](https://github.com/Sensirion/arduino-i2c-sgp41)
- [Sensirion I2C SHT](https://github.com/Sensirion/arduino-sht)
- [PMS](https://github.com/fu-hsi/pms)

## License
CC BY-SA 4.0 Attribution-ShareAlike 4.0 International License
5 changes: 4 additions & 1 deletion examples/BASIC/BASIC.ino
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,9 @@ void loop() {
}

updateWiFiConnect();

/** Read PMS on loop */
ag.pms5003.handle();
}

static void sendPing() {
Expand Down Expand Up @@ -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;
Expand Down
7 changes: 6 additions & 1 deletion examples/ONE/ONE.ino
Original file line number Diff line number Diff line change
Expand Up @@ -845,6 +845,11 @@ void loop() {

/** factory reset handle */
factoryConfigReset();

/** Read PMS on loop */
if (hasSensorPMS) {
ag.pms5003.handle();
}
}

static void setTestColor(char color) {
Expand Down Expand Up @@ -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();
Expand Down
13 changes: 10 additions & 3 deletions examples/Open_Air/Open_Air.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -802,6 +802,13 @@ void loop() {
updateWiFiConnect();

factoryConfigReset();

if (hasSensorPMS1) {
ag.pms5003t_1.handle();
}
if (hasSensorPMS2) {
ag.pms5003t_2.handle();
}
}

void sendPing() {
Expand Down Expand Up @@ -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();
Expand All @@ -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();
Expand Down
68 changes: 41 additions & 27 deletions examples/TestPM/TestPM.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -35,42 +35,56 @@ void setup() {
#endif
}

uint32_t lastRead = 0;
void loop() {
int PM2;
bool readResul = false;

uint32_t ms = (uint32_t)(millis() - lastRead);
if (ms >= 5000) {
lastRead = millis();
#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()) {
if (ag.pms5003.isFailed() == false) {
PM2 = ag.pms5003.getPm25Ae();
readResul = true;
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");
}
}

if (readResul) {
Serial.printf("PM2.5 in ug/m3: %d\r\n", PM2);
#else
if (ag.getBoardType() == OPEN_AIR_OUTDOOR) {
Serial.printf("PM2.5 in US AQI: %d\r\n",
ag.pms5003t_1.convertPm25ToUsAqi(PM2));
if (ag.pms5003t_1.isFailed() == false) {
PM2 = ag.pms5003t_1.getPm25Ae();
readResul = true;
}
} else {
Serial.printf("PM2.5 in US AQI: %d\r\n",
ag.pms5003.convertPm25ToUsAqi(PM2));
if (ag.pms5003.isFailed() == false) {
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 {
Serial.printf("PM2.5 in US AQI: %d\r\n",
ag.pms5003.convertPm25ToUsAqi(PM2));
}
} else {
Serial.println("PMS sensor failed");
}
}
#endif
}

delay(5000);
if (ag.getBoardType() == OPEN_AIR_OUTDOOR) {
ag.pms5003t_1.handle();
} else {
ag.pms5003.handle();
}
}

void failedHandler(String msg) {
Expand Down
Loading

0 comments on commit be1a977

Please sign in to comment.