mirror of
https://github.com/airgradienthq/arduino.git
synced 2025-07-19 19:52:08 +02:00
fix: FW stops if some sensor not found
This commit is contained in:
@ -359,7 +359,7 @@ AirGradient ag = AirGradient(DIY_BASIC);
|
|||||||
|
|
||||||
static int co2Ppm = -1;
|
static int co2Ppm = -1;
|
||||||
static int pm25 = -1;
|
static int pm25 = -1;
|
||||||
static float temp = -1;
|
static float temp = -1001;
|
||||||
static int hum = -1;
|
static int hum = -1;
|
||||||
static long val;
|
static long val;
|
||||||
static String wifiSSID = "";
|
static String wifiSSID = "";
|
||||||
@ -378,6 +378,9 @@ static String getDevId(void);
|
|||||||
static void updateWiFiConnect(void);
|
static void updateWiFiConnect(void);
|
||||||
static void showNr(void);
|
static void showNr(void);
|
||||||
|
|
||||||
|
bool hasSensorS8 = true;
|
||||||
|
bool hasSensorPMS = true;
|
||||||
|
bool hasSensorSHT = true;
|
||||||
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);
|
||||||
@ -438,9 +441,15 @@ void loop() {
|
|||||||
configSchedule.run();
|
configSchedule.run();
|
||||||
serverSchedule.run();
|
serverSchedule.run();
|
||||||
dispSchedule.run();
|
dispSchedule.run();
|
||||||
co2Schedule.run();
|
if (hasSensorS8) {
|
||||||
pmsSchedule.run();
|
co2Schedule.run();
|
||||||
tempHumSchedule.run();
|
}
|
||||||
|
if (hasSensorPMS) {
|
||||||
|
pmsSchedule.run();
|
||||||
|
}
|
||||||
|
if (hasSensorSHT) {
|
||||||
|
tempHumSchedule.run();
|
||||||
|
}
|
||||||
|
|
||||||
updateWiFiConnect();
|
updateWiFiConnect();
|
||||||
}
|
}
|
||||||
@ -510,17 +519,20 @@ void connectToWifi() {
|
|||||||
static void boardInit(void) {
|
static void boardInit(void) {
|
||||||
/** Init SHT sensor */
|
/** Init SHT sensor */
|
||||||
if (ag.sht.begin(Wire) == false) {
|
if (ag.sht.begin(Wire) == false) {
|
||||||
failedHandler("SHT init failed");
|
hasSensorSHT = false;
|
||||||
|
Serial.println("SHT sensor not found");
|
||||||
}
|
}
|
||||||
|
|
||||||
/** CO2 init */
|
/** CO2 init */
|
||||||
if (ag.s8.begin(&Serial) == false) {
|
if (ag.s8.begin(&Serial) == false) {
|
||||||
failedHandler("SenseAirS8 init failed");
|
Serial.println("CO2 S8 snsor not found");
|
||||||
|
hasSensorS8 = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** PMS init */
|
/** PMS init */
|
||||||
if (ag.pms5003.begin(&Serial) == false) {
|
if (ag.pms5003.begin(&Serial) == false) {
|
||||||
failedHandler("PMS5003 init failed");
|
Serial.println("PMS sensor not found");
|
||||||
|
hasSensorPMS = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Display init */
|
/** Display init */
|
||||||
@ -566,22 +578,31 @@ static void co2Calibration(void) {
|
|||||||
static void serverConfigPoll(void) {
|
static void serverConfigPoll(void) {
|
||||||
if (agServer.pollServerConfig(getDevId())) {
|
if (agServer.pollServerConfig(getDevId())) {
|
||||||
if (agServer.isCo2Calib()) {
|
if (agServer.isCo2Calib()) {
|
||||||
co2Calibration();
|
if (hasSensorS8) {
|
||||||
|
co2Calibration();
|
||||||
|
} else {
|
||||||
|
Serial.println("CO2 S8 not available, calib ignored");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (agServer.getCo2AbcDaysConfig() > 0) {
|
if (agServer.getCo2AbcDaysConfig() > 0) {
|
||||||
int newHour = agServer.getCo2AbcDaysConfig() * 24;
|
if (hasSensorS8) {
|
||||||
Serial.printf("abcDays config: %d days(%d hours)\r\n",
|
int newHour = agServer.getCo2AbcDaysConfig() * 24;
|
||||||
agServer.getCo2AbcDaysConfig(), newHour);
|
Serial.printf("abcDays config: %d days(%d hours)\r\n",
|
||||||
int curHour = ag.s8.getAbcPeriod();
|
agServer.getCo2AbcDaysConfig(), newHour);
|
||||||
Serial.printf("Current config: %d (hours)\r\n", ag.s8.getAbcPeriod());
|
int curHour = ag.s8.getAbcPeriod();
|
||||||
if (curHour == newHour) {
|
Serial.printf("Current config: %d (hours)\r\n", ag.s8.getAbcPeriod());
|
||||||
Serial.println("set 'abcDays' ignored");
|
if (curHour == newHour) {
|
||||||
} else {
|
Serial.println("set 'abcDays' ignored");
|
||||||
if (ag.s8.setAbcPeriod(agServer.getCo2AbcDaysConfig() * 24) == false) {
|
|
||||||
Serial.println("Set S8 abcDays period calib failed");
|
|
||||||
} else {
|
} else {
|
||||||
Serial.println("Set S8 abcDays period calib success");
|
if (ag.s8.setAbcPeriod(agServer.getCo2AbcDaysConfig() * 24) ==
|
||||||
|
false) {
|
||||||
|
Serial.println("Set S8 abcDays period calib failed");
|
||||||
|
} else {
|
||||||
|
Serial.println("Set S8 abcDays period calib success");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
Serial.println("CO2 S8 not available, set 'abcDays' ignored");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -621,7 +642,7 @@ static void sendDataToServer() {
|
|||||||
if (pm25 >= 0) {
|
if (pm25 >= 0) {
|
||||||
root["pm02"] = pm25;
|
root["pm02"] = pm25;
|
||||||
}
|
}
|
||||||
if (temp >= 0) {
|
if (temp > -1001) {
|
||||||
root["atmp"] = ag.round2(temp);
|
root["atmp"] = ag.round2(temp);
|
||||||
}
|
}
|
||||||
if (hum >= 0) {
|
if (hum >= 0) {
|
||||||
|
@ -567,7 +567,7 @@ static int pm25 = -1;
|
|||||||
static int pm01 = -1;
|
static int pm01 = -1;
|
||||||
static int pm10 = -1;
|
static int pm10 = -1;
|
||||||
static int pm03PCount = -1;
|
static int pm03PCount = -1;
|
||||||
static float temp = -1;
|
static float temp = -1001;
|
||||||
static int hum = -1;
|
static int hum = -1;
|
||||||
static int bootCount;
|
static int bootCount;
|
||||||
static String wifiSSID = "";
|
static String wifiSSID = "";
|
||||||
@ -595,6 +595,10 @@ static void webServerInit(void);
|
|||||||
static String getServerSyncData(void);
|
static String getServerSyncData(void);
|
||||||
|
|
||||||
/** Init schedule */
|
/** Init schedule */
|
||||||
|
bool hasSensorS8 = true;
|
||||||
|
bool hasSensorPMS = true;
|
||||||
|
bool hasSensorSGP = true;
|
||||||
|
bool hasSensorSHT = true;
|
||||||
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);
|
||||||
@ -680,10 +684,22 @@ void loop() {
|
|||||||
dispLedSchedule.run();
|
dispLedSchedule.run();
|
||||||
configSchedule.run();
|
configSchedule.run();
|
||||||
serverSchedule.run();
|
serverSchedule.run();
|
||||||
co2Schedule.run();
|
|
||||||
pmsSchedule.run();
|
if (hasSensorS8) {
|
||||||
tempHumSchedule.run();
|
co2Schedule.run();
|
||||||
tvocSchedule.run();
|
}
|
||||||
|
|
||||||
|
if (hasSensorPMS) {
|
||||||
|
pmsSchedule.run();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hasSensorSHT) {
|
||||||
|
tempHumSchedule.run();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hasSensorSGP) {
|
||||||
|
tvocSchedule.run();
|
||||||
|
}
|
||||||
|
|
||||||
/** Check for handle WiFi reconnect */
|
/** Check for handle WiFi reconnect */
|
||||||
updateWiFiConnect();
|
updateWiFiConnect();
|
||||||
@ -793,35 +809,43 @@ static void webServerInit(void) {
|
|||||||
static String getServerSyncData(void) {
|
static String getServerSyncData(void) {
|
||||||
JSONVar root;
|
JSONVar root;
|
||||||
root["wifi"] = WiFi.RSSI();
|
root["wifi"] = WiFi.RSSI();
|
||||||
if (co2Ppm >= 0) {
|
if (hasSensorS8) {
|
||||||
root["rco2"] = co2Ppm;
|
if (co2Ppm >= 0) {
|
||||||
|
root["rco2"] = co2Ppm;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (pm01 >= 0) {
|
if (hasSensorPMS) {
|
||||||
root["pm01"] = pm01;
|
if (pm01 >= 0) {
|
||||||
|
root["pm01"] = pm01;
|
||||||
|
}
|
||||||
|
if (pm25 >= 0) {
|
||||||
|
root["pm02"] = pm25;
|
||||||
|
}
|
||||||
|
if (pm10 >= 0) {
|
||||||
|
root["pm10"] = pm10;
|
||||||
|
}
|
||||||
|
if (pm03PCount >= 0) {
|
||||||
|
root["pm003_count"] = pm03PCount;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (pm25 >= 0) {
|
if (hasSensorSGP) {
|
||||||
root["pm02"] = pm25;
|
if (tvocIndex >= 0) {
|
||||||
|
root["tvoc_index"] = tvocIndex;
|
||||||
|
}
|
||||||
|
if (tvocRawIndex >= 0) {
|
||||||
|
root["tvoc_raw"] = tvocRawIndex;
|
||||||
|
}
|
||||||
|
if (noxIndex >= 0) {
|
||||||
|
root["noxIndex"] = noxIndex;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (pm10 >= 0) {
|
if (hasSensorSHT) {
|
||||||
root["pm10"] = pm10;
|
if (temp > -1001) {
|
||||||
}
|
root["atmp"] = ag.round2(temp);
|
||||||
if (pm03PCount >= 0) {
|
}
|
||||||
root["pm003_count"] = pm03PCount;
|
if (hum >= 0) {
|
||||||
}
|
root["rhum"] = hum;
|
||||||
if (tvocIndex >= 0) {
|
}
|
||||||
root["tvoc_index"] = tvocIndex;
|
|
||||||
}
|
|
||||||
if (tvocRawIndex >= 0) {
|
|
||||||
root["tvoc_raw"] = tvocRawIndex;
|
|
||||||
}
|
|
||||||
if (noxIndex >= 0) {
|
|
||||||
root["noxIndex"] = noxIndex;
|
|
||||||
}
|
|
||||||
if (temp >= 0) {
|
|
||||||
root["atmp"] = ag.round2(temp);
|
|
||||||
}
|
|
||||||
if (hum >= 0) {
|
|
||||||
root["rhum"] = hum;
|
|
||||||
}
|
}
|
||||||
root["boot"] = bootCount;
|
root["boot"] = bootCount;
|
||||||
|
|
||||||
@ -1226,12 +1250,14 @@ static void boardInit(void) {
|
|||||||
|
|
||||||
/** Init sensor SGP41 */
|
/** Init sensor SGP41 */
|
||||||
if (ag.sgp41.begin(Wire) == false) {
|
if (ag.sgp41.begin(Wire) == false) {
|
||||||
failedHandler("Init SGP41 failed");
|
Serial.println("SGP41 sensor not found");
|
||||||
|
hasSensorSGP = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** INit SHT */
|
/** INit SHT */
|
||||||
if (ag.sht.begin(Wire) == false) {
|
if (ag.sht.begin(Wire) == false) {
|
||||||
failedHandler("Init SHT failed");
|
Serial.println("SHTx sensor not found");
|
||||||
|
hasSensorSHT = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Init watchdog */
|
/** Init watchdog */
|
||||||
@ -1239,12 +1265,15 @@ static void boardInit(void) {
|
|||||||
|
|
||||||
/** Init S8 CO2 sensor */
|
/** Init S8 CO2 sensor */
|
||||||
if (ag.s8.begin(Serial1) == false) {
|
if (ag.s8.begin(Serial1) == false) {
|
||||||
failedHandler("Init SenseAirS8 failed");
|
// failedHandler("Init SenseAirS8 failed");
|
||||||
|
Serial.println("CO2 S8 sensor not found");
|
||||||
|
hasSensorS8 = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Init PMS5003 */
|
/** Init PMS5003 */
|
||||||
if (ag.pms5003.begin(Serial0) == false) {
|
if (ag.pms5003.begin(Serial0) == false) {
|
||||||
failedHandler("Init PMS5003 failed");
|
Serial.println("PMS sensor not found");
|
||||||
|
hasSensorPMS = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1266,23 +1295,32 @@ static void failedHandler(String msg) {
|
|||||||
static void serverConfigPoll(void) {
|
static void serverConfigPoll(void) {
|
||||||
if (agServer.pollServerConfig(getDevId())) {
|
if (agServer.pollServerConfig(getDevId())) {
|
||||||
if (agServer.isCo2Calib()) {
|
if (agServer.isCo2Calib()) {
|
||||||
co2Calibration();
|
if (hasSensorS8) {
|
||||||
|
co2Calibration();
|
||||||
|
} else {
|
||||||
|
Serial.println("CO2 S8 not available, calib ignored");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (agServer.getCo2AbcDaysConfig() > 0) {
|
if (agServer.getCo2AbcDaysConfig() > 0) {
|
||||||
int newHour = agServer.getCo2AbcDaysConfig() * 24;
|
if (hasSensorS8) {
|
||||||
Serial.printf("abcDays config: %d days(%d hours)\r\n",
|
int newHour = agServer.getCo2AbcDaysConfig() * 24;
|
||||||
agServer.getCo2AbcDaysConfig(), newHour);
|
Serial.printf("abcDays config: %d days(%d hours)\r\n",
|
||||||
int curHour = ag.s8.getAbcPeriod();
|
agServer.getCo2AbcDaysConfig(), newHour);
|
||||||
Serial.printf("Current config: %d (hours)\r\n", ag.s8.getAbcPeriod());
|
int curHour = ag.s8.getAbcPeriod();
|
||||||
if (curHour == newHour) {
|
Serial.printf("Current config: %d (hours)\r\n", ag.s8.getAbcPeriod());
|
||||||
Serial.println("set 'abcDays' ignored");
|
if (curHour == newHour) {
|
||||||
} else {
|
Serial.println("set 'abcDays' ignored");
|
||||||
if (ag.s8.setAbcPeriod(agServer.getCo2AbcDaysConfig() * 24) == false) {
|
|
||||||
Serial.println("Set S8 abcDays period calib failed");
|
|
||||||
} else {
|
} else {
|
||||||
Serial.println("Set S8 abcDays period calib success");
|
if (ag.s8.setAbcPeriod(agServer.getCo2AbcDaysConfig() * 24) ==
|
||||||
|
false) {
|
||||||
|
Serial.println("Set S8 abcDays period calib failed");
|
||||||
|
} else {
|
||||||
|
Serial.println("Set S8 abcDays period calib success");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
Serial.println("CO2 S8 not available, set 'abcDays' ignored");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1638,6 +1676,7 @@ static void tvocPoll(void) {
|
|||||||
tvocRawIndex = ag.sgp41.getTvocRaw();
|
tvocRawIndex = ag.sgp41.getTvocRaw();
|
||||||
noxIndex = ag.sgp41.getNoxIndex();
|
noxIndex = ag.sgp41.getNoxIndex();
|
||||||
|
|
||||||
|
Serial.println();
|
||||||
Serial.printf(" TVOC index: %d\r\n", tvocIndex);
|
Serial.printf(" TVOC index: %d\r\n", tvocIndex);
|
||||||
Serial.printf("TVOC raw index: %d\r\n", tvocRawIndex);
|
Serial.printf("TVOC raw index: %d\r\n", tvocRawIndex);
|
||||||
Serial.printf(" NOx index: %d\r\n", noxIndex);
|
Serial.printf(" NOx index: %d\r\n", noxIndex);
|
||||||
@ -1654,6 +1693,7 @@ static void pmPoll(void) {
|
|||||||
pm10 = ag.pms5003.getPm10Ae();
|
pm10 = ag.pms5003.getPm10Ae();
|
||||||
pm03PCount = ag.pms5003.getPm03ParticleCount();
|
pm03PCount = ag.pms5003.getPm03ParticleCount();
|
||||||
|
|
||||||
|
Serial.println();
|
||||||
Serial.printf(" PMS0.1: %d\r\n", pm01);
|
Serial.printf(" PMS0.1: %d\r\n", pm01);
|
||||||
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);
|
||||||
|
@ -530,15 +530,15 @@ int pm25_1 = -1;
|
|||||||
int pm01_1 = -1;
|
int pm01_1 = -1;
|
||||||
int pm10_1 = -1;
|
int pm10_1 = -1;
|
||||||
int pm03PCount_1 = -1;
|
int pm03PCount_1 = -1;
|
||||||
float temp_1;
|
float temp_1 = -1001;
|
||||||
int hum_1;
|
int hum_1 = -1;
|
||||||
|
|
||||||
int pm25_2 = -1;
|
int pm25_2 = -1;
|
||||||
int pm01_2 = -1;
|
int pm01_2 = -1;
|
||||||
int pm10_2 = -1;
|
int pm10_2 = -1;
|
||||||
int pm03PCount_2 = -1;
|
int pm03PCount_2 = -1;
|
||||||
float temp_2;
|
float temp_2 = -1001;
|
||||||
int hum_2;
|
int hum_2 = -1;
|
||||||
|
|
||||||
int pm1Value01;
|
int pm1Value01;
|
||||||
int pm1Value25;
|
int pm1Value25;
|
||||||
@ -577,6 +577,10 @@ static void showNr(void);
|
|||||||
static void webServerInit(void);
|
static void webServerInit(void);
|
||||||
static String getServerSyncData(void);
|
static String getServerSyncData(void);
|
||||||
|
|
||||||
|
bool hasSensorS8 = true;
|
||||||
|
bool hasSensorPMS1 = true;
|
||||||
|
bool hasSensorPMS2 = true;
|
||||||
|
bool hasSensorSGP = true;
|
||||||
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 co2Schedule(SENSOR_CO2_UPDATE_INTERVAL, co2Poll);
|
AgSchedule co2Schedule(SENSOR_CO2_UPDATE_INTERVAL, co2Poll);
|
||||||
@ -616,12 +620,21 @@ void setup() {
|
|||||||
void loop() {
|
void loop() {
|
||||||
configSchedule.run();
|
configSchedule.run();
|
||||||
serverSchedule.run();
|
serverSchedule.run();
|
||||||
|
|
||||||
if (fw_mode == FW_MODE_PST) {
|
if (fw_mode == FW_MODE_PST) {
|
||||||
co2Schedule.run();
|
if (hasSensorS8) {
|
||||||
|
co2Schedule.run();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
pmsSchedule.run();
|
|
||||||
|
if (hasSensorPMS1 || hasSensorPMS2) {
|
||||||
|
pmsSchedule.run();
|
||||||
|
}
|
||||||
|
|
||||||
if (fw_mode == FW_MODE_PST || fw_mode == FW_MODE_PPT) {
|
if (fw_mode == FW_MODE_PST || fw_mode == FW_MODE_PPT) {
|
||||||
tvocSchedule.run();
|
if (hasSensorSGP) {
|
||||||
|
tvocSchedule.run();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
updateWiFiConnect();
|
updateWiFiConnect();
|
||||||
}
|
}
|
||||||
@ -741,39 +754,50 @@ void boardInit(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ag.watchdog.begin();
|
ag.watchdog.begin();
|
||||||
|
|
||||||
ag.button.begin();
|
ag.button.begin();
|
||||||
|
|
||||||
ag.statusLed.begin();
|
ag.statusLed.begin();
|
||||||
|
|
||||||
/** detect sensor: PMS5003, PMS5003T, SGP41 and S8 */
|
/** detect sensor: PMS5003, PMS5003T, SGP41 and S8 */
|
||||||
if (ag.s8.begin(Serial1) == false) {
|
if (ag.s8.begin(Serial1) == false) {
|
||||||
Serial.println("S8 not detect run mode 'PPT'");
|
hasSensorS8 = false;
|
||||||
|
|
||||||
|
Serial.println("CO2 S8 sensor not found");
|
||||||
|
Serial.println("Can not detect S8 run mode 'PPT'");
|
||||||
fw_mode = FW_MODE_PPT;
|
fw_mode = FW_MODE_PPT;
|
||||||
|
|
||||||
/** De-initialize Serial1 */
|
/** De-initialize Serial1 */
|
||||||
Serial1.end();
|
Serial1.end();
|
||||||
}
|
}
|
||||||
if (ag.sgp41.begin(Wire) == false) {
|
if (ag.sgp41.begin(Wire) == false) {
|
||||||
if (fw_mode == FW_MODE_PST) {
|
hasSensorSGP = false;
|
||||||
failedHandler("Init SGP41 failed");
|
Serial.println("SGP sensor not found");
|
||||||
} else {
|
|
||||||
Serial.println("SGP41 not detect run mode 'PP'");
|
Serial.println("Can not detect SGP run mode 'PP'");
|
||||||
fw_mode = FW_MODE_PP;
|
fw_mode = FW_MODE_PP;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ag.pms5003t_1.begin(Serial0) == false) {
|
if (ag.pms5003t_1.begin(Serial0) == false) {
|
||||||
failedHandler("Init PMS5003T_1 failed");
|
hasSensorPMS1 = false;
|
||||||
}
|
Serial.println("PMS1 sensor not found");
|
||||||
if (fw_mode != FW_MODE_PST) {
|
|
||||||
if (ag.pms5003t_2.begin(Serial1) == false) {
|
if (ag.pms5003t_2.begin(Serial1) == false) {
|
||||||
failedHandler("Init PMS5003T_2 failed");
|
hasSensorPMS2 = false;
|
||||||
|
Serial.println("PMS2 sensor not found");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fw_mode != FW_MODE_PST) {
|
if (fw_mode != FW_MODE_PST) {
|
||||||
pmsSchedule.setPeriod(2000);
|
if (ag.pms5003t_2.begin(Serial1) == false) {
|
||||||
|
hasSensorPMS2 = false;
|
||||||
|
Serial.println("PMS2 sensor not found");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** update the PMS poll period base on fw mode and sensor available */
|
||||||
|
if (fw_mode != FW_MODE_PST) {
|
||||||
|
if (hasSensorPMS1 && hasSensorPMS2) {
|
||||||
|
pmsSchedule.setPeriod(2000);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Serial.printf("Firmware node: %s\r\n", getFwMode(fw_mode));
|
Serial.printf("Firmware node: %s\r\n", getFwMode(fw_mode));
|
||||||
@ -841,6 +865,7 @@ static void tvocPoll(void) {
|
|||||||
tvocRawIndex = ag.sgp41.getTvocRaw();
|
tvocRawIndex = ag.sgp41.getTvocRaw();
|
||||||
noxIndex = ag.sgp41.getNoxIndex();
|
noxIndex = ag.sgp41.getNoxIndex();
|
||||||
|
|
||||||
|
Serial.println();
|
||||||
Serial.printf(" TVOC index: %d\r\n", tvocIndex);
|
Serial.printf(" TVOC index: %d\r\n", tvocIndex);
|
||||||
Serial.printf("TVOC raw index: %d\r\n", tvocRawIndex);
|
Serial.printf("TVOC raw index: %d\r\n", tvocRawIndex);
|
||||||
Serial.printf(" NOx index: %d\r\n", noxIndex);
|
Serial.printf(" NOx index: %d\r\n", noxIndex);
|
||||||
@ -851,59 +876,109 @@ static void tvocPoll(void) {
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
static void pmPoll(void) {
|
static void pmPoll(void) {
|
||||||
if (fw_mode == FW_MODE_PST) {
|
bool pmsResult_1 = false;
|
||||||
if (ag.pms5003t_1.readData()) {
|
bool pmsResult_2 = false;
|
||||||
pm01_1 = ag.pms5003t_1.getPm01Ae();
|
if (hasSensorPMS1 && ag.pms5003t_1.readData()) {
|
||||||
pm25_1 = ag.pms5003t_1.getPm25Ae();
|
pm01_1 = ag.pms5003t_1.getPm01Ae();
|
||||||
pm25_1 = ag.pms5003t_1.getPm10Ae();
|
pm25_1 = ag.pms5003t_1.getPm25Ae();
|
||||||
pm03PCount_1 = ag.pms5003t_1.getPm03ParticleCount();
|
pm10_1 = ag.pms5003t_1.getPm10Ae();
|
||||||
temp_1 = ag.pms5003t_1.getTemperature();
|
pm03PCount_1 = ag.pms5003t_1.getPm03ParticleCount();
|
||||||
hum_1 = ag.pms5003t_1.getRelativeHumidity();
|
temp_1 = ag.pms5003t_1.getTemperature();
|
||||||
}
|
hum_1 = ag.pms5003t_1.getRelativeHumidity();
|
||||||
|
|
||||||
|
pmsResult_1 = true;
|
||||||
|
|
||||||
|
Serial.println();
|
||||||
|
Serial.printf("[1] PMS0.1: %d\r\n", pm01_1);
|
||||||
|
Serial.printf("[1] PMS2.5: %d\r\n", pm25_1);
|
||||||
|
Serial.printf("[1] PMS10.0: %d\r\n", pm10_1);
|
||||||
|
Serial.printf("[1]PMS3.0 Count: %d\r\n", pm03PCount_1);
|
||||||
|
Serial.printf("[1] Temperature: %0.2f\r\n", temp_1);
|
||||||
|
Serial.printf("[1] Humidity: %d\r\n", hum_1);
|
||||||
} else {
|
} else {
|
||||||
if (ag.pms5003t_1.readData() && ag.pms5003t_2.readData()) {
|
pm01_1 = -1;
|
||||||
pm1Value01 = pm1Value01 + ag.pms5003t_1.getPm01Ae();
|
pm25_1 = -1;
|
||||||
pm1Value25 = pm1Value25 + ag.pms5003t_1.getPm25Ae();
|
pm10_1 = -1;
|
||||||
pm1Value10 = pm1Value10 + ag.pms5003t_1.getPm10Ae();
|
pm03PCount_1 = -1;
|
||||||
pm1PCount = pm1PCount + ag.pms5003t_1.getPm03ParticleCount();
|
temp_1 = -1001;
|
||||||
pm1temp = pm1temp + ag.pms5003t_1.getTemperature();
|
hum_1 = -1;
|
||||||
pm1hum = pm1hum + ag.pms5003t_1.getRelativeHumidity();
|
}
|
||||||
pm2Value01 = pm2Value01 + ag.pms5003t_2.getPm01Ae();
|
|
||||||
pm2Value25 = pm2Value25 + ag.pms5003t_2.getPm25Ae();
|
|
||||||
pm2Value10 = pm2Value10 + ag.pms5003t_2.getPm10Ae();
|
|
||||||
pm2PCount = pm2PCount + ag.pms5003t_2.getPm03ParticleCount();
|
|
||||||
pm2temp = pm2temp + ag.pms5003t_2.getTemperature();
|
|
||||||
pm2hum = pm2hum + ag.pms5003t_2.getRelativeHumidity();
|
|
||||||
countPosition++;
|
|
||||||
if (countPosition == targetCount) {
|
|
||||||
pm01_1 = pm1Value01 / targetCount;
|
|
||||||
pm25_1 = pm1Value25 / targetCount;
|
|
||||||
pm10_1 = pm1Value10 / targetCount;
|
|
||||||
pm03PCount_1 = pm1PCount / targetCount;
|
|
||||||
temp_1 = pm1temp / targetCount;
|
|
||||||
hum_1 = pm1hum / targetCount;
|
|
||||||
pm01_2 = pm2Value01 / targetCount;
|
|
||||||
pm25_2 = pm2Value25 / targetCount;
|
|
||||||
pm10_2 = pm2Value10 / targetCount;
|
|
||||||
pm03PCount_2 = pm2PCount / targetCount;
|
|
||||||
temp_2 = pm2temp / targetCount;
|
|
||||||
hum_2 = pm2hum / targetCount;
|
|
||||||
|
|
||||||
countPosition = 0;
|
if (hasSensorPMS2 && ag.pms5003t_2.readData()) {
|
||||||
|
pm01_2 = ag.pms5003t_2.getPm01Ae();
|
||||||
|
pm25_2 = ag.pms5003t_2.getPm25Ae();
|
||||||
|
pm10_2 = ag.pms5003t_2.getPm10Ae();
|
||||||
|
pm03PCount_2 = ag.pms5003t_2.getPm03ParticleCount();
|
||||||
|
temp_2 = ag.pms5003t_2.getTemperature();
|
||||||
|
hum_2 = ag.pms5003t_2.getRelativeHumidity();
|
||||||
|
|
||||||
pm1Value01 = 0;
|
pmsResult_2 = true;
|
||||||
pm1Value25 = 0;
|
|
||||||
pm1Value10 = 0;
|
Serial.println();
|
||||||
pm1PCount = 0;
|
Serial.printf("[2] PMS0.1: %d\r\n", pm01_2);
|
||||||
pm1temp = 0;
|
Serial.printf("[2] PMS2.5: %d\r\n", pm25_2);
|
||||||
pm1hum = 0;
|
Serial.printf("[2] PMS10.0: %d\r\n", pm10_2);
|
||||||
pm2Value01 = 0;
|
Serial.printf("[2]PMS3.0 Count: %d\r\n", pm03PCount_2);
|
||||||
pm2Value25 = 0;
|
Serial.printf("[2] Temperature: %0.2f\r\n", temp_2);
|
||||||
pm2Value10 = 0;
|
Serial.printf("[2] Humidity: %d\r\n", hum_2);
|
||||||
pm2PCount = 0;
|
} else {
|
||||||
pm2temp = 0;
|
pm01_2 = -1;
|
||||||
pm2hum = 0;
|
pm25_2 = -1;
|
||||||
}
|
pm10_2 = -1;
|
||||||
|
pm03PCount_2 = -1;
|
||||||
|
temp_2 = -1001;
|
||||||
|
hum_2 = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hasSensorPMS1 && hasSensorPMS2 && pmsResult_1 && pmsResult_2) {
|
||||||
|
/** Get total of PMS1*/
|
||||||
|
pm1Value01 = pm1Value01 + pm01_1;
|
||||||
|
pm1Value25 = pm1Value25 + pm25_1;
|
||||||
|
pm1Value10 = pm1Value10 + pm10_1;
|
||||||
|
pm1PCount = pm1PCount + pm03PCount_1;
|
||||||
|
pm1temp = pm1temp + temp_1;
|
||||||
|
pm1hum = pm1hum + hum_1;
|
||||||
|
|
||||||
|
/** Get total of PMS2 */
|
||||||
|
pm2Value01 = pm2Value01 + pm01_2;
|
||||||
|
pm2Value25 = pm2Value25 + pm25_2;
|
||||||
|
pm2Value10 = pm2Value10 + pm10_2;
|
||||||
|
pm2PCount = pm2PCount + pm03PCount_2;
|
||||||
|
pm2temp = pm2temp + temp_2;
|
||||||
|
pm2hum = pm2hum + hum_2;
|
||||||
|
|
||||||
|
countPosition++;
|
||||||
|
|
||||||
|
/** Get average */
|
||||||
|
if (countPosition == targetCount) {
|
||||||
|
pm01_1 = pm1Value01 / targetCount;
|
||||||
|
pm25_1 = pm1Value25 / targetCount;
|
||||||
|
pm10_1 = pm1Value10 / targetCount;
|
||||||
|
pm03PCount_1 = pm1PCount / targetCount;
|
||||||
|
temp_1 = pm1temp / targetCount;
|
||||||
|
hum_1 = pm1hum / targetCount;
|
||||||
|
|
||||||
|
pm01_2 = pm2Value01 / targetCount;
|
||||||
|
pm25_2 = pm2Value25 / targetCount;
|
||||||
|
pm10_2 = pm2Value10 / targetCount;
|
||||||
|
pm03PCount_2 = pm2PCount / targetCount;
|
||||||
|
temp_2 = pm2temp / targetCount;
|
||||||
|
hum_2 = pm2hum / targetCount;
|
||||||
|
|
||||||
|
countPosition = 0;
|
||||||
|
|
||||||
|
pm1Value01 = 0;
|
||||||
|
pm1Value25 = 0;
|
||||||
|
pm1Value10 = 0;
|
||||||
|
pm1PCount = 0;
|
||||||
|
pm1temp = 0;
|
||||||
|
pm1hum = 0;
|
||||||
|
pm2Value01 = 0;
|
||||||
|
pm2Value25 = 0;
|
||||||
|
pm2Value10 = 0;
|
||||||
|
pm2PCount = 0;
|
||||||
|
pm2temp = 0;
|
||||||
|
pm2hum = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -918,25 +993,33 @@ static void serverConfigPoll(void) {
|
|||||||
/** Only support CO2 S8 sensor on FW_MODE_PST */
|
/** Only support CO2 S8 sensor on FW_MODE_PST */
|
||||||
if (fw_mode == FW_MODE_PST) {
|
if (fw_mode == FW_MODE_PST) {
|
||||||
if (agServer.isCo2Calib()) {
|
if (agServer.isCo2Calib()) {
|
||||||
co2Calibration();
|
if (hasSensorS8) {
|
||||||
|
co2Calibration();
|
||||||
|
} else {
|
||||||
|
Serial.println("CO2 S8 not available, calib ignored");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (agServer.getCo2AbcDaysConfig() > 0) {
|
if (agServer.getCo2AbcDaysConfig() > 0) {
|
||||||
int newHour = agServer.getCo2AbcDaysConfig() * 24;
|
if (hasSensorS8) {
|
||||||
Serial.printf("abcDays config: %d days(%d hours)\r\n",
|
int newHour = agServer.getCo2AbcDaysConfig() * 24;
|
||||||
agServer.getCo2AbcDaysConfig(), newHour);
|
Serial.printf("abcDays config: %d days(%d hours)\r\n",
|
||||||
int curHour = ag.s8.getAbcPeriod();
|
agServer.getCo2AbcDaysConfig(), newHour);
|
||||||
Serial.printf("Current config: %d (hours)\r\n", ag.s8.getAbcPeriod());
|
int curHour = ag.s8.getAbcPeriod();
|
||||||
if (curHour == newHour) {
|
Serial.printf("Current config: %d (hours)\r\n", ag.s8.getAbcPeriod());
|
||||||
Serial.println("set 'abcDays' ignored");
|
if (curHour == newHour) {
|
||||||
} else {
|
Serial.println("set 'abcDays' ignored");
|
||||||
if (ag.s8.setAbcPeriod(agServer.getCo2AbcDaysConfig() * 24) ==
|
|
||||||
false) {
|
|
||||||
Serial.println("Set S8 abcDays period calib failed");
|
|
||||||
} else {
|
} else {
|
||||||
Serial.println("Set S8 abcDays period calib success");
|
if (ag.s8.setAbcPeriod(agServer.getCo2AbcDaysConfig() * 24) ==
|
||||||
|
false) {
|
||||||
|
Serial.println("Set S8 abcDays period calib failed");
|
||||||
|
} else {
|
||||||
|
Serial.println("Set S8 abcDays period calib success");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
Serial.println("CO2 S8 not available, set 'abcDays' ignored");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1096,66 +1179,94 @@ static String getServerSyncData(void) {
|
|||||||
JSONVar root;
|
JSONVar root;
|
||||||
root["wifi"] = WiFi.RSSI();
|
root["wifi"] = WiFi.RSSI();
|
||||||
root["boot"] = loopCount;
|
root["boot"] = loopCount;
|
||||||
|
|
||||||
if (fw_mode == FW_MODE_PST) {
|
if (fw_mode == FW_MODE_PST) {
|
||||||
if (co2Ppm >= 0) {
|
if (hasSensorS8) {
|
||||||
root["rco2"] = co2Ppm;
|
if (co2Ppm >= 0) {
|
||||||
|
root["rco2"] = co2Ppm;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (pm01_1 >= 0) {
|
|
||||||
root["pm01"] = pm01_1;
|
if (hasSensorPMS1) {
|
||||||
}
|
if (pm01_1 >= 0) {
|
||||||
if (pm25_1 >= 0) {
|
root["pm01"] = pm01_1;
|
||||||
root["pm02"] = pm25_1;
|
}
|
||||||
}
|
if (pm25_1 >= 0) {
|
||||||
if (pm10_1 >= 0) {
|
root["pm02"] = pm25_1;
|
||||||
root["pm10"] = pm10_1;
|
}
|
||||||
}
|
if (pm10_1 >= 0) {
|
||||||
if (pm03PCount_1 >= 0) {
|
root["pm10"] = pm10_1;
|
||||||
root["pm003_count"] = pm03PCount_1;
|
}
|
||||||
}
|
if (pm03PCount_1 >= 0) {
|
||||||
if (tvocIndex >= 0) {
|
root["pm003_count"] = pm03PCount_1;
|
||||||
root["tvoc_index"] = tvocIndex;
|
}
|
||||||
}
|
if (temp_1 > -1001) {
|
||||||
if (noxIndex >= 0) {
|
root["atmp"] = ag.round2(temp_1);
|
||||||
root["noxIndex"] = noxIndex;
|
}
|
||||||
}
|
if (hum_1 >= 0) {
|
||||||
if (temp_1 >= 0) {
|
root["rhum"] = hum_1;
|
||||||
root["atmp"] = ag.round2(temp_1);
|
}
|
||||||
}
|
} else if (hasSensorPMS2) {
|
||||||
if (hum_1 >= 0) {
|
if (pm01_2 >= 0) {
|
||||||
root["rhum"] = hum_1;
|
root["pm01"] = pm01_2;
|
||||||
|
}
|
||||||
|
if (pm25_2 >= 0) {
|
||||||
|
root["pm02"] = pm25_2;
|
||||||
|
}
|
||||||
|
if (pm10_2 >= 0) {
|
||||||
|
root["pm10"] = pm10_2;
|
||||||
|
}
|
||||||
|
if (pm03PCount_2 >= 0) {
|
||||||
|
root["pm003_count"] = pm03PCount_2;
|
||||||
|
}
|
||||||
|
if (temp_2 > -1001) {
|
||||||
|
root["atmp"] = ag.round2(temp_2);
|
||||||
|
}
|
||||||
|
if (hum_2 >= 0) {
|
||||||
|
root["rhum"] = hum_2;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((fw_mode == FW_MODE_PPT) || (fw_mode == FW_MODE_PST)) {
|
if ((fw_mode == FW_MODE_PPT) || (fw_mode == FW_MODE_PST)) {
|
||||||
if (tvocIndex > 0) {
|
if (hasSensorSGP) {
|
||||||
root["tvoc_index"] = loopCount;
|
if (tvocIndex > 0) {
|
||||||
}
|
root["tvoc_index"] = tvocIndex;
|
||||||
if (tvocRawIndex >= 0) {
|
}
|
||||||
root["tvoc_raw"] = tvocRawIndex;
|
if (tvocRawIndex >= 0) {
|
||||||
}
|
root["tvoc_raw"] = tvocRawIndex;
|
||||||
if (noxIndex > 0) {
|
}
|
||||||
root["nox_index"] = loopCount;
|
if (noxIndex > 0) {
|
||||||
|
root["nox_index"] = noxIndex;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((fw_mode == FW_MODE_PP) || (fw_mode == FW_MODE_PPT)) {
|
if ((fw_mode == FW_MODE_PP) || (fw_mode == FW_MODE_PPT)) {
|
||||||
root["pm01"] = ag.round2((pm01_1 + pm01_2) / 2.0);
|
if (hasSensorPMS1 && hasSensorPMS2) {
|
||||||
root["pm02"] = ag.round2((pm25_1 + pm25_2) / 2.0);
|
root["pm01"] = ag.round2((pm01_1 + pm01_2) / 2.0);
|
||||||
root["pm003_count"] = ag.round2((pm03PCount_1 + pm03PCount_2) / 2.0);
|
root["pm02"] = ag.round2((pm25_1 + pm25_2) / 2.0);
|
||||||
root["atmp"] = ag.round2((temp_1 + temp_2) / 2.0);
|
root["pm10"] = ag.round2((pm10_1 + pm10_2) / 2.0);
|
||||||
root["rhum"] = ag.round2((hum_1 + hum_2) / 2.0);
|
root["pm003_count"] = ag.round2((pm03PCount_1 + pm03PCount_2) / 2.0);
|
||||||
root["channels"]["1"]["pm01"] = pm01_1;
|
root["atmp"] = ag.round2((temp_1 + temp_2) / 2.0);
|
||||||
root["channels"]["1"]["pm02"] = pm25_1;
|
root["rhum"] = ag.round2((hum_1 + hum_2) / 2.0);
|
||||||
root["channels"]["1"]["pm10"] = pm10_1;
|
}
|
||||||
root["channels"]["1"]["pm003_count"] = pm03PCount_1;
|
if (hasSensorPMS1) {
|
||||||
root["channels"]["1"]["atmp"] = ag.round2(temp_1);
|
root["channels"]["1"]["pm01"] = pm01_1;
|
||||||
root["channels"]["1"]["rhum"] = hum_1;
|
root["channels"]["1"]["pm02"] = pm25_1;
|
||||||
root["channels"]["2"]["pm01"] = pm01_2;
|
root["channels"]["1"]["pm10"] = pm10_1;
|
||||||
root["channels"]["2"]["pm02"] = pm25_2;
|
root["channels"]["1"]["pm003_count"] = pm03PCount_1;
|
||||||
root["channels"]["2"]["pm10"] = pm10_2;
|
root["channels"]["1"]["atmp"] = ag.round2(temp_1);
|
||||||
root["channels"]["2"]["pm003_count"] = pm03PCount_2;
|
root["channels"]["1"]["rhum"] = hum_1;
|
||||||
root["channels"]["2"]["atmp"] = ag.round2(temp_2);
|
}
|
||||||
root["channels"]["2"]["rhum"] = hum_2;
|
if (hasSensorPMS2) {
|
||||||
|
root["channels"]["2"]["pm01"] = pm01_2;
|
||||||
|
root["channels"]["2"]["pm02"] = pm25_2;
|
||||||
|
root["channels"]["2"]["pm10"] = pm10_2;
|
||||||
|
root["channels"]["2"]["pm003_count"] = pm03PCount_2;
|
||||||
|
root["channels"]["2"]["atmp"] = ag.round2(temp_2);
|
||||||
|
root["channels"]["2"]["rhum"] = hum_2;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return JSON.stringify(root);
|
return JSON.stringify(root);
|
||||||
|
Reference in New Issue
Block a user