mirror of
https://github.com/airgradienthq/arduino.git
synced 2025-06-26 16:21:33 +02:00
Compare commits
43 Commits
Author | SHA1 | Date | |
---|---|---|---|
28096e9faf | |||
682378a47c | |||
a1861be7b7 | |||
99ddd24432 | |||
29491e4cbe | |||
87cc3fc45f | |||
7471d8079a | |||
8b0fe967f1 | |||
6f1cef4e67 | |||
02b63ff816 | |||
228bf83e92 | |||
d3534cda52 | |||
aafaa42a68 | |||
2e9ff0d7dd | |||
244b7814a6 | |||
28d27ee8fd | |||
753f22923c | |||
c45901706f | |||
663836e277 | |||
d39e10908d | |||
c52962d628 | |||
6b65efd3d6 | |||
8bb87a75ef | |||
1afcca25a1 | |||
17238cff86 | |||
03e2afbf54 | |||
104d58a8c0 | |||
7a988ea6c1 | |||
54ed83cb89 | |||
e461b92c9f | |||
db21648e91 | |||
a9654506f5 | |||
63f653d5cd | |||
b049a23657 | |||
d6766ef68b | |||
6c3259b94b | |||
2df78e9066 | |||
81b13134d2 | |||
6d01366887 | |||
040bd28038 | |||
01943f594d | |||
01a69668cc | |||
812c2ab803 |
@ -68,7 +68,6 @@ static LocalServer localServer(Serial, openMetrics, measurements, configuration,
|
|||||||
wifiConnector);
|
wifiConnector);
|
||||||
static MqttClient mqttClient(Serial);
|
static MqttClient mqttClient(Serial);
|
||||||
|
|
||||||
static int pmFailCount = 0;
|
|
||||||
static int getCO2FailCount = 0;
|
static int getCO2FailCount = 0;
|
||||||
static AgFirmwareMode fwMode = FW_MODE_I_BASIC_40PS;
|
static AgFirmwareMode fwMode = FW_MODE_I_BASIC_40PS;
|
||||||
|
|
||||||
@ -514,15 +513,20 @@ static void updatePm(void) {
|
|||||||
Serial.printf("PM2.5 ug/m3: %d\r\n", measurements.pm25_1);
|
Serial.printf("PM2.5 ug/m3: %d\r\n", measurements.pm25_1);
|
||||||
Serial.printf("PM10 ug/m3: %d\r\n", measurements.pm10_1);
|
Serial.printf("PM10 ug/m3: %d\r\n", measurements.pm10_1);
|
||||||
Serial.printf("PM0.3 Count: %d\r\n", measurements.pm03PCount_1);
|
Serial.printf("PM0.3 Count: %d\r\n", measurements.pm03PCount_1);
|
||||||
pmFailCount = 0;
|
ag.pms5003.resetFailCount();
|
||||||
} else {
|
} else {
|
||||||
pmFailCount++;
|
ag.pms5003.updateFailCount();
|
||||||
Serial.printf("PMS read failed: %d\r\n", pmFailCount);
|
Serial.printf("PMS read failed %d times\r\n", ag.pms5003.getFailCount());
|
||||||
if (pmFailCount >= 3) {
|
if (ag.pms5003.getFailCount() >= PMS_FAIL_COUNT_SET_INVALID) {
|
||||||
measurements.pm01_1 = utils::getInvalidPMS();
|
measurements.pm01_1 = utils::getInvalidPmValue();
|
||||||
measurements.pm25_1 = utils::getInvalidPMS();
|
measurements.pm25_1 = utils::getInvalidPmValue();
|
||||||
measurements.pm10_1 = utils::getInvalidPMS();
|
measurements.pm10_1 = utils::getInvalidPmValue();
|
||||||
measurements.pm03PCount_1 = utils::getInvalidPMS();
|
measurements.pm03PCount_1 = utils::getInvalidPmValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
if(ag.pms5003.getFailCount() >= ag.pms5003.getFailCountMax()) {
|
||||||
|
Serial.printf("PMS failure count reach to max set %d, restarting...", ag.pms5003.getFailCountMax());
|
||||||
|
ESP.restart();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -67,10 +67,10 @@ String OpenMetrics::getPayload(void) {
|
|||||||
|
|
||||||
float _temp = utils::getInvalidTemperature();
|
float _temp = utils::getInvalidTemperature();
|
||||||
float _hum = utils::getInvalidHumidity();
|
float _hum = utils::getInvalidHumidity();
|
||||||
int pm01 = utils::getInvalidPMS();
|
int pm01 = utils::getInvalidPmValue();
|
||||||
int pm25 = utils::getInvalidPMS();
|
int pm25 = utils::getInvalidPmValue();
|
||||||
int pm10 = utils::getInvalidPMS();
|
int pm10 = utils::getInvalidPmValue();
|
||||||
int pm03PCount = utils::getInvalidPMS();
|
int pm03PCount = utils::getInvalidPmValue();
|
||||||
int atmpCompensated = utils::getInvalidTemperature();
|
int atmpCompensated = utils::getInvalidTemperature();
|
||||||
int ahumCompensated = utils::getInvalidHumidity();
|
int ahumCompensated = utils::getInvalidHumidity();
|
||||||
|
|
||||||
@ -89,28 +89,28 @@ String OpenMetrics::getPayload(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (config.hasSensorPMS1) {
|
if (config.hasSensorPMS1) {
|
||||||
if (utils::isValidPMS(pm01)) {
|
if (utils::isValidPm(pm01)) {
|
||||||
add_metric("pm1",
|
add_metric("pm1",
|
||||||
"PM1.0 concentration as measured by the AirGradient PMS "
|
"PM1.0 concentration as measured by the AirGradient PMS "
|
||||||
"sensor, in micrograms per cubic meter",
|
"sensor, in micrograms per cubic meter",
|
||||||
"gauge", "ugm3");
|
"gauge", "ugm3");
|
||||||
add_metric_point("", String(pm01));
|
add_metric_point("", String(pm01));
|
||||||
}
|
}
|
||||||
if (utils::isValidPMS(pm25)) {
|
if (utils::isValidPm(pm25)) {
|
||||||
add_metric("pm2d5",
|
add_metric("pm2d5",
|
||||||
"PM2.5 concentration as measured by the AirGradient PMS "
|
"PM2.5 concentration as measured by the AirGradient PMS "
|
||||||
"sensor, in micrograms per cubic meter",
|
"sensor, in micrograms per cubic meter",
|
||||||
"gauge", "ugm3");
|
"gauge", "ugm3");
|
||||||
add_metric_point("", String(pm25));
|
add_metric_point("", String(pm25));
|
||||||
}
|
}
|
||||||
if (utils::isValidPMS(pm10)) {
|
if (utils::isValidPm(pm10)) {
|
||||||
add_metric("pm10",
|
add_metric("pm10",
|
||||||
"PM10 concentration as measured by the AirGradient PMS "
|
"PM10 concentration as measured by the AirGradient PMS "
|
||||||
"sensor, in micrograms per cubic meter",
|
"sensor, in micrograms per cubic meter",
|
||||||
"gauge", "ugm3");
|
"gauge", "ugm3");
|
||||||
add_metric_point("", String(pm10));
|
add_metric_point("", String(pm10));
|
||||||
}
|
}
|
||||||
if (utils::isValidPMS03Count(pm03PCount)) {
|
if (utils::isValidPm03Count(pm03PCount)) {
|
||||||
add_metric("pm0d3",
|
add_metric("pm0d3",
|
||||||
"PM0.3 concentration as measured by the AirGradient PMS "
|
"PM0.3 concentration as measured by the AirGradient PMS "
|
||||||
"sensor, in number of particules per 100 milliliters",
|
"sensor, in number of particules per 100 milliliters",
|
||||||
|
@ -68,7 +68,6 @@ static LocalServer localServer(Serial, openMetrics, measurements, configuration,
|
|||||||
wifiConnector);
|
wifiConnector);
|
||||||
static MqttClient mqttClient(Serial);
|
static MqttClient mqttClient(Serial);
|
||||||
|
|
||||||
static int pmFailCount = 0;
|
|
||||||
static int getCO2FailCount = 0;
|
static int getCO2FailCount = 0;
|
||||||
static AgFirmwareMode fwMode = FW_MODE_I_33PS;
|
static AgFirmwareMode fwMode = FW_MODE_I_33PS;
|
||||||
|
|
||||||
@ -566,15 +565,20 @@ static void updatePm(void) {
|
|||||||
Serial.printf("PM2.5 ug/m3: %d\r\n", measurements.pm25_1);
|
Serial.printf("PM2.5 ug/m3: %d\r\n", measurements.pm25_1);
|
||||||
Serial.printf("PM10 ug/m3: %d\r\n", measurements.pm10_1);
|
Serial.printf("PM10 ug/m3: %d\r\n", measurements.pm10_1);
|
||||||
Serial.printf("PM0.3 Count: %d\r\n", measurements.pm03PCount_1);
|
Serial.printf("PM0.3 Count: %d\r\n", measurements.pm03PCount_1);
|
||||||
pmFailCount = 0;
|
ag.pms5003.resetFailCount();
|
||||||
} else {
|
} else {
|
||||||
pmFailCount++;
|
ag.pms5003.updateFailCount();
|
||||||
Serial.printf("PMS read failed: %d\r\n", pmFailCount);
|
Serial.printf("PMS read failed %d times\r\n", ag.pms5003.getFailCount());
|
||||||
if (pmFailCount >= 3) {
|
if (ag.pms5003.getFailCount() >= PMS_FAIL_COUNT_SET_INVALID) {
|
||||||
measurements.pm01_1 = utils::getInvalidPMS();
|
measurements.pm01_1 = utils::getInvalidPmValue();
|
||||||
measurements.pm25_1 = utils::getInvalidPMS();
|
measurements.pm25_1 = utils::getInvalidPmValue();
|
||||||
measurements.pm10_1 = utils::getInvalidPMS();
|
measurements.pm10_1 = utils::getInvalidPmValue();
|
||||||
measurements.pm03PCount_1 = utils::getInvalidPMS();
|
measurements.pm03PCount_1 = utils::getInvalidPmValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
if(ag.pms5003.getFailCount() >= ag.pms5003.getFailCountMax()) {
|
||||||
|
Serial.printf("PMS failure count reach to max set %d, restarting...", ag.pms5003.getFailCountMax());
|
||||||
|
ESP.restart();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -67,10 +67,10 @@ String OpenMetrics::getPayload(void) {
|
|||||||
|
|
||||||
float _temp = utils::getInvalidTemperature();
|
float _temp = utils::getInvalidTemperature();
|
||||||
float _hum = utils::getInvalidHumidity();
|
float _hum = utils::getInvalidHumidity();
|
||||||
int pm01 = utils::getInvalidPMS();
|
int pm01 = utils::getInvalidPmValue();
|
||||||
int pm25 = utils::getInvalidPMS();
|
int pm25 = utils::getInvalidPmValue();
|
||||||
int pm10 = utils::getInvalidPMS();
|
int pm10 = utils::getInvalidPmValue();
|
||||||
int pm03PCount = utils::getInvalidPMS();
|
int pm03PCount = utils::getInvalidPmValue();
|
||||||
int atmpCompensated = utils::getInvalidTemperature();
|
int atmpCompensated = utils::getInvalidTemperature();
|
||||||
int ahumCompensated = utils::getInvalidHumidity();
|
int ahumCompensated = utils::getInvalidHumidity();
|
||||||
|
|
||||||
@ -89,28 +89,28 @@ String OpenMetrics::getPayload(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (config.hasSensorPMS1) {
|
if (config.hasSensorPMS1) {
|
||||||
if (utils::isValidPMS(pm01)) {
|
if (utils::isValidPm(pm01)) {
|
||||||
add_metric("pm1",
|
add_metric("pm1",
|
||||||
"PM1.0 concentration as measured by the AirGradient PMS "
|
"PM1.0 concentration as measured by the AirGradient PMS "
|
||||||
"sensor, in micrograms per cubic meter",
|
"sensor, in micrograms per cubic meter",
|
||||||
"gauge", "ugm3");
|
"gauge", "ugm3");
|
||||||
add_metric_point("", String(pm01));
|
add_metric_point("", String(pm01));
|
||||||
}
|
}
|
||||||
if (utils::isValidPMS(pm25)) {
|
if (utils::isValidPm(pm25)) {
|
||||||
add_metric("pm2d5",
|
add_metric("pm2d5",
|
||||||
"PM2.5 concentration as measured by the AirGradient PMS "
|
"PM2.5 concentration as measured by the AirGradient PMS "
|
||||||
"sensor, in micrograms per cubic meter",
|
"sensor, in micrograms per cubic meter",
|
||||||
"gauge", "ugm3");
|
"gauge", "ugm3");
|
||||||
add_metric_point("", String(pm25));
|
add_metric_point("", String(pm25));
|
||||||
}
|
}
|
||||||
if (utils::isValidPMS(pm10)) {
|
if (utils::isValidPm(pm10)) {
|
||||||
add_metric("pm10",
|
add_metric("pm10",
|
||||||
"PM10 concentration as measured by the AirGradient PMS "
|
"PM10 concentration as measured by the AirGradient PMS "
|
||||||
"sensor, in micrograms per cubic meter",
|
"sensor, in micrograms per cubic meter",
|
||||||
"gauge", "ugm3");
|
"gauge", "ugm3");
|
||||||
add_metric_point("", String(pm10));
|
add_metric_point("", String(pm10));
|
||||||
}
|
}
|
||||||
if (utils::isValidPMS03Count(pm03PCount)) {
|
if (utils::isValidPm03Count(pm03PCount)) {
|
||||||
add_metric("pm0d3",
|
add_metric("pm0d3",
|
||||||
"PM0.3 concentration as measured by the AirGradient PMS "
|
"PM0.3 concentration as measured by the AirGradient PMS "
|
||||||
"sensor, in number of particules per 100 milliliters",
|
"sensor, in number of particules per 100 milliliters",
|
||||||
|
@ -68,7 +68,6 @@ static LocalServer localServer(Serial, openMetrics, measurements, configuration,
|
|||||||
wifiConnector);
|
wifiConnector);
|
||||||
static MqttClient mqttClient(Serial);
|
static MqttClient mqttClient(Serial);
|
||||||
|
|
||||||
static int pmFailCount = 0;
|
|
||||||
static uint32_t factoryBtnPressTime = 0;
|
static uint32_t factoryBtnPressTime = 0;
|
||||||
static int getCO2FailCount = 0;
|
static int getCO2FailCount = 0;
|
||||||
static AgFirmwareMode fwMode = FW_MODE_I_42PS;
|
static AgFirmwareMode fwMode = FW_MODE_I_42PS;
|
||||||
@ -328,9 +327,7 @@ static void factoryConfigReset(void) {
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
/** Reset WIFI */
|
/** Reset WIFI */
|
||||||
// WiFi.enableSTA(true); // Incase offline mode
|
WiFi.disconnect(true, true);
|
||||||
// WiFi.disconnect(true, true);
|
|
||||||
wifiConnector.reset();
|
|
||||||
|
|
||||||
/** Reset local config */
|
/** Reset local config */
|
||||||
configuration.reset();
|
configuration.reset();
|
||||||
@ -609,15 +606,20 @@ static void updatePm(void) {
|
|||||||
Serial.printf("PM2.5 ug/m3: %d\r\n", measurements.pm25_1);
|
Serial.printf("PM2.5 ug/m3: %d\r\n", measurements.pm25_1);
|
||||||
Serial.printf("PM10 ug/m3: %d\r\n", measurements.pm10_1);
|
Serial.printf("PM10 ug/m3: %d\r\n", measurements.pm10_1);
|
||||||
Serial.printf("PM0.3 Count: %d\r\n", measurements.pm03PCount_1);
|
Serial.printf("PM0.3 Count: %d\r\n", measurements.pm03PCount_1);
|
||||||
pmFailCount = 0;
|
ag.pms5003.resetFailCount();
|
||||||
} else {
|
} else {
|
||||||
pmFailCount++;
|
ag.pms5003.updateFailCount();
|
||||||
Serial.printf("PMS read failed: %d\r\n", pmFailCount);
|
Serial.printf("PMS read failed %d times\r\n", ag.pms5003.getFailCount());
|
||||||
if (pmFailCount >= 3) {
|
if (ag.pms5003.getFailCount() >= PMS_FAIL_COUNT_SET_INVALID) {
|
||||||
measurements.pm01_1 = utils::getInvalidPMS();
|
measurements.pm01_1 = utils::getInvalidPmValue();
|
||||||
measurements.pm25_1 = utils::getInvalidPMS();
|
measurements.pm25_1 = utils::getInvalidPmValue();
|
||||||
measurements.pm10_1 = utils::getInvalidPMS();
|
measurements.pm10_1 = utils::getInvalidPmValue();
|
||||||
measurements.pm03PCount_1 = utils::getInvalidPMS();
|
measurements.pm03PCount_1 = utils::getInvalidPmValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
if(ag.pms5003.getFailCount() >= ag.pms5003.getFailCountMax()) {
|
||||||
|
Serial.printf("PMS failure count reach to max set %d, restarting...", ag.pms5003.getFailCountMax());
|
||||||
|
ESP.restart();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -67,10 +67,10 @@ String OpenMetrics::getPayload(void) {
|
|||||||
|
|
||||||
float _temp = utils::getInvalidTemperature();
|
float _temp = utils::getInvalidTemperature();
|
||||||
float _hum = utils::getInvalidHumidity();
|
float _hum = utils::getInvalidHumidity();
|
||||||
int pm01 = utils::getInvalidPMS();
|
int pm01 = utils::getInvalidPmValue();
|
||||||
int pm25 = utils::getInvalidPMS();
|
int pm25 = utils::getInvalidPmValue();
|
||||||
int pm10 = utils::getInvalidPMS();
|
int pm10 = utils::getInvalidPmValue();
|
||||||
int pm03PCount = utils::getInvalidPMS();
|
int pm03PCount = utils::getInvalidPmValue();
|
||||||
int atmpCompensated = utils::getInvalidTemperature();
|
int atmpCompensated = utils::getInvalidTemperature();
|
||||||
int ahumCompensated = utils::getInvalidHumidity();
|
int ahumCompensated = utils::getInvalidHumidity();
|
||||||
|
|
||||||
@ -89,28 +89,28 @@ String OpenMetrics::getPayload(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (config.hasSensorPMS1) {
|
if (config.hasSensorPMS1) {
|
||||||
if (utils::isValidPMS(pm01)) {
|
if (utils::isValidPm(pm01)) {
|
||||||
add_metric("pm1",
|
add_metric("pm1",
|
||||||
"PM1.0 concentration as measured by the AirGradient PMS "
|
"PM1.0 concentration as measured by the AirGradient PMS "
|
||||||
"sensor, in micrograms per cubic meter",
|
"sensor, in micrograms per cubic meter",
|
||||||
"gauge", "ugm3");
|
"gauge", "ugm3");
|
||||||
add_metric_point("", String(pm01));
|
add_metric_point("", String(pm01));
|
||||||
}
|
}
|
||||||
if (utils::isValidPMS(pm25)) {
|
if (utils::isValidPm(pm25)) {
|
||||||
add_metric("pm2d5",
|
add_metric("pm2d5",
|
||||||
"PM2.5 concentration as measured by the AirGradient PMS "
|
"PM2.5 concentration as measured by the AirGradient PMS "
|
||||||
"sensor, in micrograms per cubic meter",
|
"sensor, in micrograms per cubic meter",
|
||||||
"gauge", "ugm3");
|
"gauge", "ugm3");
|
||||||
add_metric_point("", String(pm25));
|
add_metric_point("", String(pm25));
|
||||||
}
|
}
|
||||||
if (utils::isValidPMS(pm10)) {
|
if (utils::isValidPm(pm10)) {
|
||||||
add_metric("pm10",
|
add_metric("pm10",
|
||||||
"PM10 concentration as measured by the AirGradient PMS "
|
"PM10 concentration as measured by the AirGradient PMS "
|
||||||
"sensor, in micrograms per cubic meter",
|
"sensor, in micrograms per cubic meter",
|
||||||
"gauge", "ugm3");
|
"gauge", "ugm3");
|
||||||
add_metric_point("", String(pm10));
|
add_metric_point("", String(pm10));
|
||||||
}
|
}
|
||||||
if (utils::isValidPMS03Count(pm03PCount)) {
|
if (utils::isValidPm03Count(pm03PCount)) {
|
||||||
add_metric("pm0d3",
|
add_metric("pm0d3",
|
||||||
"PM0.3 concentration as measured by the AirGradient PMS "
|
"PM0.3 concentration as measured by the AirGradient PMS "
|
||||||
"sensor, in number of particules per 100 milliliters",
|
"sensor, in number of particules per 100 milliliters",
|
||||||
|
@ -88,7 +88,6 @@ static OtaHandler otaHandler;
|
|||||||
static LocalServer localServer(Serial, openMetrics, measurements, configuration,
|
static LocalServer localServer(Serial, openMetrics, measurements, configuration,
|
||||||
wifiConnector);
|
wifiConnector);
|
||||||
|
|
||||||
static int pmFailCount = 0;
|
|
||||||
static uint32_t factoryBtnPressTime = 0;
|
static uint32_t factoryBtnPressTime = 0;
|
||||||
static int getCO2FailCount = 0;
|
static int getCO2FailCount = 0;
|
||||||
static AgFirmwareMode fwMode = FW_MODE_I_9PSL;
|
static AgFirmwareMode fwMode = FW_MODE_I_9PSL;
|
||||||
@ -424,8 +423,7 @@ static void factoryConfigReset(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Reset WIFI */
|
/** Reset WIFI */
|
||||||
Serial.println("Set wifi connect to 'airgradient' as default");
|
WiFi.disconnect(true, true);
|
||||||
WiFi.begin("airgradient", "cleanair");
|
|
||||||
|
|
||||||
/** Reset local config */
|
/** Reset local config */
|
||||||
configuration.reset();
|
configuration.reset();
|
||||||
@ -940,6 +938,9 @@ static void configUpdateHandle() {
|
|||||||
|
|
||||||
stateMachine.executeLedBarTest();
|
stateMachine.executeLedBarTest();
|
||||||
}
|
}
|
||||||
|
else if(ag->isOpenAir()) {
|
||||||
|
stateMachine.executeLedBarTest();
|
||||||
|
}
|
||||||
|
|
||||||
appDispHandler();
|
appDispHandler();
|
||||||
appLedHandler();
|
appLedHandler();
|
||||||
@ -1006,6 +1007,7 @@ static void updateTvoc(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void updatePm(void) {
|
static void updatePm(void) {
|
||||||
|
bool restart = false;
|
||||||
if (ag->isOne()) {
|
if (ag->isOne()) {
|
||||||
if (ag->pms5003.isFailed() == false) {
|
if (ag->pms5003.isFailed() == false) {
|
||||||
measurements.pm01_1 = ag->pms5003.getPm01Ae();
|
measurements.pm01_1 = ag->pms5003.getPm01Ae();
|
||||||
@ -1018,15 +1020,19 @@ static void updatePm(void) {
|
|||||||
Serial.printf("PM2.5 ug/m3: %d\r\n", measurements.pm25_1);
|
Serial.printf("PM2.5 ug/m3: %d\r\n", measurements.pm25_1);
|
||||||
Serial.printf("PM10 ug/m3: %d\r\n", measurements.pm10_1);
|
Serial.printf("PM10 ug/m3: %d\r\n", measurements.pm10_1);
|
||||||
Serial.printf("PM0.3 Count: %d\r\n", measurements.pm03PCount_1);
|
Serial.printf("PM0.3 Count: %d\r\n", measurements.pm03PCount_1);
|
||||||
pmFailCount = 0;
|
ag->pms5003.resetFailCount();
|
||||||
} else {
|
} else {
|
||||||
pmFailCount++;
|
ag->pms5003.updateFailCount();
|
||||||
Serial.printf("PMS read failed: %d\r\n", pmFailCount);
|
Serial.printf("PMS read faile %d times\r\n", ag->pms5003.getFailCount());
|
||||||
if (pmFailCount >= 3) {
|
if (ag->pms5003.getFailCount() >= PMS_FAIL_COUNT_SET_INVALID) {
|
||||||
measurements.pm01_1 = utils::getInvalidPMS();
|
measurements.pm01_1 = utils::getInvalidPmValue();
|
||||||
measurements.pm25_1 = utils::getInvalidPMS();
|
measurements.pm25_1 = utils::getInvalidPmValue();
|
||||||
measurements.pm10_1 = utils::getInvalidPMS();
|
measurements.pm10_1 = utils::getInvalidPmValue();
|
||||||
measurements.pm03PCount_1 = utils::getInvalidPMS();
|
measurements.pm03PCount_1 = utils::getInvalidPmValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ag->pms5003.getFailCount() >= ag->pms5003.getFailCountMax()) {
|
||||||
|
restart = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -1050,16 +1056,29 @@ static void updatePm(void) {
|
|||||||
Serial.printf("[1] Temperature in C: %0.2f\r\n", measurements.temp_1);
|
Serial.printf("[1] Temperature in C: %0.2f\r\n", measurements.temp_1);
|
||||||
Serial.printf("[1] Relative Humidity: %d\r\n", measurements.hum_1);
|
Serial.printf("[1] Relative Humidity: %d\r\n", measurements.hum_1);
|
||||||
Serial.printf("[1] Temperature compensated in C: %0.2f\r\n",
|
Serial.printf("[1] Temperature compensated in C: %0.2f\r\n",
|
||||||
ag->pms5003t_1.temperatureCompensated(measurements.temp_1));
|
ag->pms5003t_1.compensateTemp(measurements.temp_1));
|
||||||
Serial.printf("[1] Relative Humidity compensated: %f\r\n",
|
Serial.printf("[1] Relative Humidity compensated: %0.2f\r\n",
|
||||||
ag->pms5003t_1.humidityCompensated(measurements.hum_1));
|
ag->pms5003t_1.compensateHum(measurements.hum_1));
|
||||||
|
|
||||||
|
ag->pms5003t_1.resetFailCount();
|
||||||
} else {
|
} else {
|
||||||
measurements.pm01_1 = utils::getInvalidPMS();
|
if (configuration.hasSensorPMS1) {
|
||||||
measurements.pm25_1 = utils::getInvalidPMS();
|
ag->pms5003t_1.updateFailCount();
|
||||||
measurements.pm10_1 = utils::getInvalidPMS();
|
Serial.printf("[1] PMS read failed %d times\r\n", ag->pms5003t_1.getFailCount());
|
||||||
measurements.pm03PCount_1 = utils::getInvalidPMS();
|
|
||||||
measurements.temp_1 = utils::getInvalidTemperature();
|
if (ag->pms5003t_1.getFailCount() >= PMS_FAIL_COUNT_SET_INVALID) {
|
||||||
measurements.hum_1 = utils::getInvalidHumidity();
|
measurements.pm01_1 = utils::getInvalidPmValue();
|
||||||
|
measurements.pm25_1 = utils::getInvalidPmValue();
|
||||||
|
measurements.pm10_1 = utils::getInvalidPmValue();
|
||||||
|
measurements.pm03PCount_1 = utils::getInvalidPmValue();
|
||||||
|
measurements.temp_1 = utils::getInvalidTemperature();
|
||||||
|
measurements.hum_1 = utils::getInvalidHumidity();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ag->pms5003t_1.getFailCount() >= ag->pms5003t_1.getFailCountMax()) {
|
||||||
|
restart = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (configuration.hasSensorPMS2 && (ag->pms5003t_2.isFailed() == false)) {
|
if (configuration.hasSensorPMS2 && (ag->pms5003t_2.isFailed() == false)) {
|
||||||
@ -1080,16 +1099,29 @@ static void updatePm(void) {
|
|||||||
Serial.printf("[2] Temperature in C: %0.2f\r\n", measurements.temp_2);
|
Serial.printf("[2] Temperature in C: %0.2f\r\n", measurements.temp_2);
|
||||||
Serial.printf("[2] Relative Humidity: %d\r\n", measurements.hum_2);
|
Serial.printf("[2] Relative Humidity: %d\r\n", measurements.hum_2);
|
||||||
Serial.printf("[2] Temperature compensated in C: %0.2f\r\n",
|
Serial.printf("[2] Temperature compensated in C: %0.2f\r\n",
|
||||||
ag->pms5003t_1.temperatureCompensated(measurements.temp_2));
|
ag->pms5003t_1.compensateTemp(measurements.temp_2));
|
||||||
Serial.printf("[2] Relative Humidity compensated: %d\r\n",
|
Serial.printf("[2] Relative Humidity compensated: %0.2f\r\n",
|
||||||
ag->pms5003t_1.humidityCompensated(measurements.hum_2));
|
ag->pms5003t_1.compensateHum(measurements.hum_2));
|
||||||
|
|
||||||
|
ag->pms5003t_2.resetFailCount();
|
||||||
} else {
|
} else {
|
||||||
measurements.pm01_2 = utils::getInvalidPMS();
|
if (configuration.hasSensorPMS2) {
|
||||||
measurements.pm25_2 = utils::getInvalidPMS();
|
ag->pms5003t_2.updateFailCount();
|
||||||
measurements.pm10_2 = utils::getInvalidPMS();
|
Serial.printf("[2] PMS read failed %d times\r\n", ag->pms5003t_2.getFailCount());
|
||||||
measurements.pm03PCount_2 = utils::getInvalidPMS();
|
|
||||||
measurements.temp_2 = utils::getInvalidTemperature();
|
if (ag->pms5003t_2.getFailCount() >= PMS_FAIL_COUNT_SET_INVALID) {
|
||||||
measurements.hum_2 = utils::getInvalidHumidity();
|
measurements.pm01_2 = utils::getInvalidPmValue();
|
||||||
|
measurements.pm25_2 = utils::getInvalidPmValue();
|
||||||
|
measurements.pm10_2 = utils::getInvalidPmValue();
|
||||||
|
measurements.pm03PCount_2 = utils::getInvalidPmValue();
|
||||||
|
measurements.temp_2 = utils::getInvalidTemperature();
|
||||||
|
measurements.hum_2 = utils::getInvalidHumidity();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ag->pms5003t_2.getFailCount() >= ag->pms5003t_2.getFailCountMax()) {
|
||||||
|
restart = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (configuration.hasSensorPMS1 && configuration.hasSensorPMS2 &&
|
if (configuration.hasSensorPMS1 && configuration.hasSensorPMS2 &&
|
||||||
@ -1189,6 +1221,11 @@ static void updatePm(void) {
|
|||||||
ag->sgp41.setCompensationTemperatureHumidity(temp, hum);
|
ag->sgp41.setCompensationTemperatureHumidity(temp, hum);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (restart) {
|
||||||
|
Serial.printf("PMS failure count reach to max set %d, restarting...", ag->pms5003.getFailCountMax());
|
||||||
|
ESP.restart();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void sendDataToServer(void) {
|
static void sendDataToServer(void) {
|
||||||
|
@ -67,10 +67,10 @@ String OpenMetrics::getPayload(void) {
|
|||||||
|
|
||||||
float _temp = utils::getInvalidTemperature();
|
float _temp = utils::getInvalidTemperature();
|
||||||
float _hum = utils::getInvalidHumidity();
|
float _hum = utils::getInvalidHumidity();
|
||||||
int pm01 = utils::getInvalidPMS();
|
int pm01 = utils::getInvalidPmValue();
|
||||||
int pm25 = utils::getInvalidPMS();
|
int pm25 = utils::getInvalidPmValue();
|
||||||
int pm10 = utils::getInvalidPMS();
|
int pm10 = utils::getInvalidPmValue();
|
||||||
int pm03PCount = utils::getInvalidPMS();
|
int pm03PCount = utils::getInvalidPmValue();
|
||||||
int atmpCompensated = utils::getInvalidTemperature();
|
int atmpCompensated = utils::getInvalidTemperature();
|
||||||
int ahumCompensated = utils::getInvalidHumidity();
|
int ahumCompensated = utils::getInvalidHumidity();
|
||||||
if (config.hasSensorPMS1 && config.hasSensorPMS2) {
|
if (config.hasSensorPMS1 && config.hasSensorPMS2) {
|
||||||
@ -118,33 +118,33 @@ String OpenMetrics::getPayload(void) {
|
|||||||
atmpCompensated = _temp;
|
atmpCompensated = _temp;
|
||||||
ahumCompensated = _hum;
|
ahumCompensated = _hum;
|
||||||
} else {
|
} else {
|
||||||
atmpCompensated = ag->pms5003t_1.temperatureCompensated(_temp);
|
atmpCompensated = ag->pms5003t_1.compensateTemp(_temp);
|
||||||
ahumCompensated = ag->pms5003t_1.humidityCompensated(_hum);
|
ahumCompensated = ag->pms5003t_1.compensateHum(_hum);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (config.hasSensorPMS1 || config.hasSensorPMS2) {
|
if (config.hasSensorPMS1 || config.hasSensorPMS2) {
|
||||||
if (utils::isValidPMS(pm01)) {
|
if (utils::isValidPm(pm01)) {
|
||||||
add_metric("pm1",
|
add_metric("pm1",
|
||||||
"PM1.0 concentration as measured by the AirGradient PMS "
|
"PM1.0 concentration as measured by the AirGradient PMS "
|
||||||
"sensor, in micrograms per cubic meter",
|
"sensor, in micrograms per cubic meter",
|
||||||
"gauge", "ugm3");
|
"gauge", "ugm3");
|
||||||
add_metric_point("", String(pm01));
|
add_metric_point("", String(pm01));
|
||||||
}
|
}
|
||||||
if (utils::isValidPMS(pm25)) {
|
if (utils::isValidPm(pm25)) {
|
||||||
add_metric("pm2d5",
|
add_metric("pm2d5",
|
||||||
"PM2.5 concentration as measured by the AirGradient PMS "
|
"PM2.5 concentration as measured by the AirGradient PMS "
|
||||||
"sensor, in micrograms per cubic meter",
|
"sensor, in micrograms per cubic meter",
|
||||||
"gauge", "ugm3");
|
"gauge", "ugm3");
|
||||||
add_metric_point("", String(pm25));
|
add_metric_point("", String(pm25));
|
||||||
}
|
}
|
||||||
if (utils::isValidPMS(pm10)) {
|
if (utils::isValidPm(pm10)) {
|
||||||
add_metric("pm10",
|
add_metric("pm10",
|
||||||
"PM10 concentration as measured by the AirGradient PMS "
|
"PM10 concentration as measured by the AirGradient PMS "
|
||||||
"sensor, in micrograms per cubic meter",
|
"sensor, in micrograms per cubic meter",
|
||||||
"gauge", "ugm3");
|
"gauge", "ugm3");
|
||||||
add_metric_point("", String(pm10));
|
add_metric_point("", String(pm10));
|
||||||
}
|
}
|
||||||
if (utils::isValidPMS03Count(pm03PCount)) {
|
if (utils::isValidPm03Count(pm03PCount)) {
|
||||||
add_metric("pm0d3",
|
add_metric("pm0d3",
|
||||||
"PM0.3 concentration as measured by the AirGradient PMS "
|
"PM0.3 concentration as measured by the AirGradient PMS "
|
||||||
"sensor, in number of particules per 100 milliliters",
|
"sensor, in number of particules per 100 milliliters",
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
name=AirGradient Air Quality Sensor
|
name=AirGradient Air Quality Sensor
|
||||||
version=3.1.5
|
version=3.1.7
|
||||||
author=AirGradient <support@airgradient.com>
|
author=AirGradient <support@airgradient.com>
|
||||||
maintainer=AirGradient <support@airgradient.com>
|
maintainer=AirGradient <support@airgradient.com>
|
||||||
sentence=ESP32-C3 / ESP8266 library for air quality monitor measuring PM, CO2, Temperature, TVOC and Humidity with OLED display.
|
sentence=ESP32-C3 / ESP8266 library for air quality monitor measuring PM, CO2, Temperature, TVOC and Humidity with OLED display.
|
||||||
|
@ -306,12 +306,13 @@ void OledDisplay::showDashboard(const char *status) {
|
|||||||
/** Draw PM2.5 value */
|
/** Draw PM2.5 value */
|
||||||
int pm25 = value.pm25_1;
|
int pm25 = value.pm25_1;
|
||||||
if (config.hasSensorSHT) {
|
if (config.hasSensorSHT) {
|
||||||
pm25 = ag->pms5003.compensated(pm25, value.Humidity);
|
pm25 = ag->pms5003.compensate(pm25, value.Humidity);
|
||||||
|
logInfo("PM2.5:" + String(value.pm25_1) + String("Compensated:") + String(pm25));
|
||||||
}
|
}
|
||||||
DISP()->setFont(u8g2_font_t0_22b_tf);
|
DISP()->setFont(u8g2_font_t0_22b_tf);
|
||||||
if (config.isPmStandardInUSAQI()) {
|
if (config.isPmStandardInUSAQI()) {
|
||||||
if (utils::isValidPMS(value.pm25_1)) {
|
if (utils::isValidPm(pm25)) {
|
||||||
sprintf(strBuf, "%d", ag->pms5003.convertPm25ToUsAqi(value.pm25_1));
|
sprintf(strBuf, "%d", ag->pms5003.convertPm25ToUsAqi(pm25));
|
||||||
} else {
|
} else {
|
||||||
sprintf(strBuf, "%s", "-");
|
sprintf(strBuf, "%s", "-");
|
||||||
}
|
}
|
||||||
@ -319,8 +320,8 @@ void OledDisplay::showDashboard(const char *status) {
|
|||||||
DISP()->setFont(u8g2_font_t0_12_tf);
|
DISP()->setFont(u8g2_font_t0_12_tf);
|
||||||
DISP()->drawUTF8(55, 61, "AQI");
|
DISP()->drawUTF8(55, 61, "AQI");
|
||||||
} else {
|
} else {
|
||||||
if (utils::isValidPMS(value.pm25_1)) {
|
if (utils::isValidPm(pm25)) {
|
||||||
sprintf(strBuf, "%d", value.pm25_1);
|
sprintf(strBuf, "%d", pm25);
|
||||||
} else {
|
} else {
|
||||||
sprintf(strBuf, "%s", "-");
|
sprintf(strBuf, "%s", "-");
|
||||||
}
|
}
|
||||||
@ -366,11 +367,11 @@ void OledDisplay::showDashboard(const char *status) {
|
|||||||
/** Set PM */
|
/** Set PM */
|
||||||
int pm25 = value.pm25_1;
|
int pm25 = value.pm25_1;
|
||||||
if(config.hasSensorSHT) {
|
if(config.hasSensorSHT) {
|
||||||
pm25 = (int)ag->pms5003.compensated(pm25, value.Humidity);
|
pm25 = (int)ag->pms5003.compensate(pm25, value.Humidity);
|
||||||
}
|
}
|
||||||
ag->display.setCursor(0, 12);
|
ag->display.setCursor(0, 12);
|
||||||
if (utils::isValidPMS(value.pm25_1)) {
|
if (utils::isValidPm(pm25)) {
|
||||||
snprintf(strBuf, sizeof(strBuf), "PM2.5:%d", value.pm25_1);
|
snprintf(strBuf, sizeof(strBuf), "PM2.5:%d", pm25);
|
||||||
} else {
|
} else {
|
||||||
snprintf(strBuf, sizeof(strBuf), "PM2.5:-");
|
snprintf(strBuf, sizeof(strBuf), "PM2.5:-");
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
#include "AgStateMachine.h"
|
#include "AgStateMachine.h"
|
||||||
|
|
||||||
|
#define LED_TEST_BLINK_DELAY 50 /** ms */
|
||||||
#define LED_FAST_BLINK_DELAY 250 /** ms */
|
#define LED_FAST_BLINK_DELAY 250 /** ms */
|
||||||
#define LED_SLOW_BLINK_DELAY 1000 /** ms */
|
#define LED_SLOW_BLINK_DELAY 1000 /** ms */
|
||||||
#define LED_SHORT_BLINK_DELAY 500 /** ms */
|
#define LED_SHORT_BLINK_DELAY 500 /** ms */
|
||||||
@ -305,18 +306,23 @@ void StateMachine::co2Calibration(void) {
|
|||||||
|
|
||||||
void StateMachine::ledBarTest(void) {
|
void StateMachine::ledBarTest(void) {
|
||||||
if (config.isLedBarTestRequested()) {
|
if (config.isLedBarTestRequested()) {
|
||||||
if (config.getCountry() == "TH") {
|
if (ag->isOne()) {
|
||||||
uint32_t tstart = millis();
|
if (config.getCountry() == "TH") {
|
||||||
logInfo("Start run LED test for 2 min");
|
uint32_t tstart = millis();
|
||||||
while (1) {
|
logInfo("Start run LED test for 2 min");
|
||||||
ledBarRunTest();
|
while (1) {
|
||||||
uint32_t ms = (uint32_t)(millis() - tstart);
|
ledBarRunTest();
|
||||||
if (ms >= (60 * 1000 * 2)) {
|
uint32_t ms = (uint32_t)(millis() - tstart);
|
||||||
logInfo("LED test after 2 min finish");
|
if (ms >= (60 * 1000 * 2)) {
|
||||||
break;
|
logInfo("LED test after 2 min finish");
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
ledBarRunTest();
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
else if(ag->isOpenAir()) {
|
||||||
ledBarRunTest();
|
ledBarRunTest();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -325,22 +331,31 @@ void StateMachine::ledBarTest(void) {
|
|||||||
void StateMachine::ledBarPowerUpTest(void) { ledBarRunTest(); }
|
void StateMachine::ledBarPowerUpTest(void) { ledBarRunTest(); }
|
||||||
|
|
||||||
void StateMachine::ledBarRunTest(void) {
|
void StateMachine::ledBarRunTest(void) {
|
||||||
disp.setText("LED Test", "running", ".....");
|
if (ag->isOne()) {
|
||||||
runLedTest('r');
|
disp.setText("LED Test", "running", ".....");
|
||||||
ag->ledBar.show();
|
runLedTest('r');
|
||||||
delay(1000);
|
ag->ledBar.show();
|
||||||
runLedTest('g');
|
delay(1000);
|
||||||
ag->ledBar.show();
|
runLedTest('g');
|
||||||
delay(1000);
|
ag->ledBar.show();
|
||||||
runLedTest('b');
|
delay(1000);
|
||||||
ag->ledBar.show();
|
runLedTest('b');
|
||||||
delay(1000);
|
ag->ledBar.show();
|
||||||
runLedTest('w');
|
delay(1000);
|
||||||
ag->ledBar.show();
|
runLedTest('w');
|
||||||
delay(1000);
|
ag->ledBar.show();
|
||||||
runLedTest('n');
|
delay(1000);
|
||||||
ag->ledBar.show();
|
runLedTest('n');
|
||||||
delay(1000);
|
ag->ledBar.show();
|
||||||
|
delay(1000);
|
||||||
|
} else if (ag->isOpenAir()) {
|
||||||
|
for (int i = 0; i < 100; i++) {
|
||||||
|
ag->statusLed.setOn();
|
||||||
|
delay(LED_TEST_BLINK_DELAY);
|
||||||
|
ag->statusLed.setOff();
|
||||||
|
delay(LED_TEST_BLINK_DELAY);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void StateMachine::runLedTest(char color) {
|
void StateMachine::runLedTest(char color) {
|
||||||
|
175
src/AgValue.cpp
175
src/AgValue.cpp
@ -4,6 +4,39 @@
|
|||||||
#include "Main/utils.h"
|
#include "Main/utils.h"
|
||||||
#include "Libraries/Arduino_JSON/src/Arduino_JSON.h"
|
#include "Libraries/Arduino_JSON/src/Arduino_JSON.h"
|
||||||
|
|
||||||
|
#define json_prop_pmFirmware "firmware"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Get PMS5003 firmware version string
|
||||||
|
*
|
||||||
|
* @param fwCode
|
||||||
|
* @return String
|
||||||
|
*/
|
||||||
|
String Measurements::pms5003FirmwareVersion(int fwCode) {
|
||||||
|
return pms5003FirmwareVersionBase("PMS5003x", fwCode);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Get PMS5003T firmware version string
|
||||||
|
*
|
||||||
|
* @param fwCode
|
||||||
|
* @return String
|
||||||
|
*/
|
||||||
|
String Measurements::pms5003TFirmwareVersion(int fwCode) {
|
||||||
|
return pms5003FirmwareVersionBase("PMS5003x", fwCode);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Get firmware version string
|
||||||
|
*
|
||||||
|
* @param prefix Prefix firmware string
|
||||||
|
* @param fwCode Version code
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
String Measurements::pms5003FirmwareVersionBase(String prefix, int fwCode) {
|
||||||
|
return prefix + String("-") + String(fwCode);
|
||||||
|
}
|
||||||
|
|
||||||
String Measurements::toString(bool localServer, AgFirmwareMode fwMode, int rssi,
|
String Measurements::toString(bool localServer, AgFirmwareMode fwMode, int rssi,
|
||||||
void *_ag, void *_config) {
|
void *_ag, void *_config) {
|
||||||
AirGradient *ag = (AirGradient *)_ag;
|
AirGradient *ag = (AirGradient *)_ag;
|
||||||
@ -21,18 +54,23 @@ String Measurements::toString(bool localServer, AgFirmwareMode fwMode, int rssi,
|
|||||||
|
|
||||||
if (ag->isOne() || (ag->isPro4_2()) || ag->isPro3_3() || ag->isBasic()) {
|
if (ag->isOne() || (ag->isPro4_2()) || ag->isPro3_3() || ag->isBasic()) {
|
||||||
if (config->hasSensorPMS1) {
|
if (config->hasSensorPMS1) {
|
||||||
if (utils::isValidPMS(this->pm01_1)) {
|
if (utils::isValidPm(this->pm01_1)) {
|
||||||
root["pm01"] = this->pm01_1;
|
root["pm01"] = this->pm01_1;
|
||||||
}
|
}
|
||||||
if (utils::isValidPMS(this->pm25_1)) {
|
if (utils::isValidPm(this->pm25_1)) {
|
||||||
root["pm02"] = this->pm25_1;
|
root["pm02"] = this->pm25_1;
|
||||||
}
|
}
|
||||||
if (utils::isValidPMS(this->pm10_1)) {
|
if (utils::isValidPm(this->pm10_1)) {
|
||||||
root["pm10"] = this->pm10_1;
|
root["pm10"] = this->pm10_1;
|
||||||
}
|
}
|
||||||
if (utils::isValidPMS03Count(this->pm03PCount_1)) {
|
if (utils::isValidPm03Count(this->pm03PCount_1)) {
|
||||||
root["pm003Count"] = this->pm03PCount_1;
|
root["pm003Count"] = this->pm03PCount_1;
|
||||||
}
|
}
|
||||||
|
if (!localServer) {
|
||||||
|
|
||||||
|
root[json_prop_pmFirmware] =
|
||||||
|
this->pms5003FirmwareVersion(ag->pms5003.getFirmwareVersion());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (config->hasSensorSHT) {
|
if (config->hasSensorSHT) {
|
||||||
@ -51,7 +89,7 @@ String Measurements::toString(bool localServer, AgFirmwareMode fwMode, int rssi,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (config->hasSensorSHT && config->hasSensorPMS1) {
|
if (config->hasSensorSHT && config->hasSensorPMS1) {
|
||||||
int pm25 = ag->pms5003.compensated(this->pm25_1, this->Humidity);
|
int pm25 = ag->pms5003.compensate(this->pm25_1, this->Humidity);
|
||||||
if (pm25 >= 0) {
|
if (pm25 >= 0) {
|
||||||
root["pm02Compensated"] = pm25;
|
root["pm02Compensated"] = pm25;
|
||||||
}
|
}
|
||||||
@ -59,16 +97,16 @@ String Measurements::toString(bool localServer, AgFirmwareMode fwMode, int rssi,
|
|||||||
|
|
||||||
} else {
|
} else {
|
||||||
if (config->hasSensorPMS1 && config->hasSensorPMS2) {
|
if (config->hasSensorPMS1 && config->hasSensorPMS2) {
|
||||||
if (utils::isValidPMS(this->pm01_1) && utils::isValidPMS(this->pm01_2)) {
|
if (utils::isValidPm(this->pm01_1) && utils::isValidPm(this->pm01_2)) {
|
||||||
root["pm01"] = ag->round2((this->pm01_1 + this->pm01_2) / 2.0f);
|
root["pm01"] = ag->round2((this->pm01_1 + this->pm01_2) / 2.0f);
|
||||||
}
|
}
|
||||||
if (utils::isValidPMS(this->pm25_1) && utils::isValidPMS(this->pm25_2)) {
|
if (utils::isValidPm(this->pm25_1) && utils::isValidPm(this->pm25_2)) {
|
||||||
root["pm02"] = ag->round2((this->pm25_1 + this->pm25_2) / 2.0f);
|
root["pm02"] = ag->round2((this->pm25_1 + this->pm25_2) / 2.0f);
|
||||||
}
|
}
|
||||||
if (utils::isValidPMS(this->pm10_1) && utils::isValidPMS(this->pm10_2)) {
|
if (utils::isValidPm(this->pm10_1) && utils::isValidPm(this->pm10_2)) {
|
||||||
root["pm10"] = ag->round2((this->pm10_1 + this->pm10_2) / 2.0f);
|
root["pm10"] = ag->round2((this->pm10_1 + this->pm10_2) / 2.0f);
|
||||||
}
|
}
|
||||||
if (utils::isValidPMS(this->pm03PCount_1) && utils::isValidPMS(this->pm03PCount_2)) {
|
if (utils::isValidPm(this->pm03PCount_1) && utils::isValidPm(this->pm03PCount_2)) {
|
||||||
root["pm003Count"] = ag->round2((this->pm03PCount_1 + this->pm03PCount_2) / 2.0f);
|
root["pm003Count"] = ag->round2((this->pm03PCount_1 + this->pm03PCount_2) / 2.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -76,7 +114,7 @@ String Measurements::toString(bool localServer, AgFirmwareMode fwMode, int rssi,
|
|||||||
if (utils::isValidTemperature(this->temp_1) && utils::isValidTemperature(this->temp_1)) {
|
if (utils::isValidTemperature(this->temp_1) && utils::isValidTemperature(this->temp_1)) {
|
||||||
root["atmp"] = ag->round2((this->temp_1 + this->temp_2) / 2.0f);
|
root["atmp"] = ag->round2((this->temp_1 + this->temp_2) / 2.0f);
|
||||||
if (localServer) {
|
if (localServer) {
|
||||||
val = ag->pms5003t_2.temperatureCompensated((this->temp_1 + this->temp_2) / 2.0f);
|
val = ag->pms5003t_2.compensateTemp((this->temp_1 + this->temp_2) / 2.0f);
|
||||||
if (utils::isValidTemperature(val)) {
|
if (utils::isValidTemperature(val)) {
|
||||||
root["atmpCompensated"] = ag->round2(val);
|
root["atmpCompensated"] = ag->round2(val);
|
||||||
}
|
}
|
||||||
@ -85,15 +123,15 @@ String Measurements::toString(bool localServer, AgFirmwareMode fwMode, int rssi,
|
|||||||
if (utils::isValidHumidity(this->hum_1) && utils::isValidHumidity(this->hum_1)) {
|
if (utils::isValidHumidity(this->hum_1) && utils::isValidHumidity(this->hum_1)) {
|
||||||
root["rhum"] = ag->round2((this->hum_1 + this->hum_2) / 2.0f);
|
root["rhum"] = ag->round2((this->hum_1 + this->hum_2) / 2.0f);
|
||||||
if (localServer) {
|
if (localServer) {
|
||||||
val = ag->pms5003t_2.humidityCompensated((this->hum_1 + this->hum_2) / 2.0f);
|
val = ag->pms5003t_2.compensateHum((this->hum_1 + this->hum_2) / 2.0f);
|
||||||
if (utils::isValidHumidity(val)) {
|
if (utils::isValidHumidity(val)) {
|
||||||
root["rhumCompensated"] = (int)val;
|
root["rhumCompensated"] = (int)val;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int pm25 = (ag->pms5003t_1.compensated(this->pm25_1, this->temp_1) +
|
int pm25 = (ag->pms5003t_1.compensate(this->pm25_1, this->temp_1) +
|
||||||
ag->pms5003t_2.compensated(this->pm25_2, this->temp_2)) /
|
ag->pms5003t_2.compensate(this->pm25_2, this->temp_2)) /
|
||||||
2;
|
2;
|
||||||
root["pm02Compensated"] = pm25;
|
root["pm02Compensated"] = pm25;
|
||||||
}
|
}
|
||||||
@ -101,23 +139,23 @@ String Measurements::toString(bool localServer, AgFirmwareMode fwMode, int rssi,
|
|||||||
if (fwMode == FW_MODE_O_1PS || fwMode == FW_MODE_O_1PST) {
|
if (fwMode == FW_MODE_O_1PS || fwMode == FW_MODE_O_1PST) {
|
||||||
float val;
|
float val;
|
||||||
if (config->hasSensorPMS1) {
|
if (config->hasSensorPMS1) {
|
||||||
if (utils::isValidPMS(this->pm01_1)) {
|
if (utils::isValidPm(this->pm01_1)) {
|
||||||
root["pm01"] = this->pm01_1;
|
root["pm01"] = this->pm01_1;
|
||||||
}
|
}
|
||||||
if (utils::isValidPMS(this->pm25_1)) {
|
if (utils::isValidPm(this->pm25_1)) {
|
||||||
root["pm02"] = this->pm25_1;
|
root["pm02"] = this->pm25_1;
|
||||||
}
|
}
|
||||||
if (utils::isValidPMS(this->pm10_1)) {
|
if (utils::isValidPm(this->pm10_1)) {
|
||||||
root["pm10"] = this->pm10_1;
|
root["pm10"] = this->pm10_1;
|
||||||
}
|
}
|
||||||
if (utils::isValidPMS03Count(this->pm03PCount_1)) {
|
if (utils::isValidPm03Count(this->pm03PCount_1)) {
|
||||||
root["pm003Count"] = this->pm03PCount_1;
|
root["pm003Count"] = this->pm03PCount_1;
|
||||||
}
|
}
|
||||||
if (utils::isValidTemperature(this->temp_1)) {
|
if (utils::isValidTemperature(this->temp_1)) {
|
||||||
root["atmp"] = ag->round2(this->temp_1);
|
root["atmp"] = ag->round2(this->temp_1);
|
||||||
|
|
||||||
if (localServer) {
|
if (localServer) {
|
||||||
val = ag->pms5003t_1.temperatureCompensated(this->temp_1);
|
val = ag->pms5003t_1.compensateTemp(this->temp_1);
|
||||||
if (utils::isValidTemperature(val)) {
|
if (utils::isValidTemperature(val)) {
|
||||||
root["atmpCompensated"] = ag->round2(val);
|
root["atmpCompensated"] = ag->round2(val);
|
||||||
}
|
}
|
||||||
@ -127,25 +165,29 @@ String Measurements::toString(bool localServer, AgFirmwareMode fwMode, int rssi,
|
|||||||
root["rhum"] = this->hum_1;
|
root["rhum"] = this->hum_1;
|
||||||
|
|
||||||
if (localServer) {
|
if (localServer) {
|
||||||
val = ag->pms5003t_1.humidityCompensated(this->hum_1);
|
val = ag->pms5003t_1.compensateHum(this->hum_1);
|
||||||
if (utils::isValidHumidity(val)) {
|
if (utils::isValidHumidity(val)) {
|
||||||
root["rhumCompensated"] = (int)val;
|
root["rhumCompensated"] = (int)val;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
root["pm02Compensated"] = ag->pms5003t_1.compensated(this->pm25_1, this->temp_1);
|
root["pm02Compensated"] = ag->pms5003t_1.compensate(this->pm25_1, this->temp_1);
|
||||||
|
if (!localServer) {
|
||||||
|
root[json_prop_pmFirmware] =
|
||||||
|
pms5003TFirmwareVersion(ag->pms5003t_1.getFirmwareVersion());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (config->hasSensorPMS2) {
|
if (config->hasSensorPMS2) {
|
||||||
if(utils::isValidPMS(this->pm01_2)) {
|
if(utils::isValidPm(this->pm01_2)) {
|
||||||
root["pm01"] = this->pm01_2;
|
root["pm01"] = this->pm01_2;
|
||||||
}
|
}
|
||||||
if(utils::isValidPMS(this->pm25_2)) {
|
if(utils::isValidPm(this->pm25_2)) {
|
||||||
root["pm02"] = this->pm25_2;
|
root["pm02"] = this->pm25_2;
|
||||||
}
|
}
|
||||||
if(utils::isValidPMS(this->pm10_2)) {
|
if(utils::isValidPm(this->pm10_2)) {
|
||||||
root["pm10"] = this->pm10_2;
|
root["pm10"] = this->pm10_2;
|
||||||
}
|
}
|
||||||
if(utils::isValidPMS03Count(this->pm03PCount_2)) {
|
if(utils::isValidPm03Count(this->pm03PCount_2)) {
|
||||||
root["pm003Count"] = this->pm03PCount_2;
|
root["pm003Count"] = this->pm03PCount_2;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -154,7 +196,7 @@ String Measurements::toString(bool localServer, AgFirmwareMode fwMode, int rssi,
|
|||||||
root["atmp"] = ag->round2(this->temp_2);
|
root["atmp"] = ag->round2(this->temp_2);
|
||||||
|
|
||||||
if (localServer) {
|
if (localServer) {
|
||||||
val = ag->pms5003t_2.temperatureCompensated(this->temp_2);
|
val = ag->pms5003t_2.compensateTemp(this->temp_2);
|
||||||
if (utils::isValidTemperature(val)) {
|
if (utils::isValidTemperature(val)) {
|
||||||
root["atmpCompensated"] = ag->round2(val);
|
root["atmpCompensated"] = ag->round2(val);
|
||||||
}
|
}
|
||||||
@ -164,35 +206,39 @@ String Measurements::toString(bool localServer, AgFirmwareMode fwMode, int rssi,
|
|||||||
root["rhum"] = this->hum_2;
|
root["rhum"] = this->hum_2;
|
||||||
|
|
||||||
if (localServer) {
|
if (localServer) {
|
||||||
val = ag->pms5003t_2.humidityCompensated(this->hum_2);
|
val = ag->pms5003t_2.compensateHum(this->hum_2);
|
||||||
if (utils::isValidHumidity(val)) {
|
if (utils::isValidHumidity(val)) {
|
||||||
root["rhumCompensated"] = (int)val;
|
root["rhumCompensated"] = (int)val;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
root["pm02Compensated"] = ag->pms5003t_2.compensated(this->pm25_2, this->temp_2);
|
root["pm02Compensated"] = ag->pms5003t_2.compensate(this->pm25_2, this->temp_2);
|
||||||
|
if(!localServer) {
|
||||||
|
root[json_prop_pmFirmware] =
|
||||||
|
pms5003TFirmwareVersion(ag->pms5003t_1.getFirmwareVersion());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (fwMode == FW_MODE_O_1P) {
|
if (fwMode == FW_MODE_O_1P) {
|
||||||
float val;
|
float val;
|
||||||
if (config->hasSensorPMS1) {
|
if (config->hasSensorPMS1) {
|
||||||
if (utils::isValidPMS(this->pm01_1)) {
|
if (utils::isValidPm(this->pm01_1)) {
|
||||||
root["pm01"] = this->pm01_1;
|
root["pm01"] = this->pm01_1;
|
||||||
}
|
}
|
||||||
if (utils::isValidPMS(this->pm25_1)) {
|
if (utils::isValidPm(this->pm25_1)) {
|
||||||
root["pm02"] = this->pm25_1;
|
root["pm02"] = this->pm25_1;
|
||||||
}
|
}
|
||||||
if (utils::isValidPMS(this->pm10_1)) {
|
if (utils::isValidPm(this->pm10_1)) {
|
||||||
root["pm10"] = this->pm10_1;
|
root["pm10"] = this->pm10_1;
|
||||||
}
|
}
|
||||||
if (utils::isValidPMS03Count(this->pm03PCount_1)) {
|
if (utils::isValidPm03Count(this->pm03PCount_1)) {
|
||||||
root["pm003Count"] = this->pm03PCount_1;
|
root["pm003Count"] = this->pm03PCount_1;
|
||||||
}
|
}
|
||||||
if (utils::isValidTemperature(this->temp_1)) {
|
if (utils::isValidTemperature(this->temp_1)) {
|
||||||
root["atmp"] = ag->round2(this->temp_1);
|
root["atmp"] = ag->round2(this->temp_1);
|
||||||
|
|
||||||
if (localServer) {
|
if (localServer) {
|
||||||
val = ag->pms5003t_1.temperatureCompensated(this->temp_1);
|
val = ag->pms5003t_1.compensateTemp(this->temp_1);
|
||||||
if (utils::isValidTemperature(val)) {
|
if (utils::isValidTemperature(val)) {
|
||||||
root["atmpCompensated"] = ag->round2(val);
|
root["atmpCompensated"] = ag->round2(val);
|
||||||
}
|
}
|
||||||
@ -201,31 +247,35 @@ String Measurements::toString(bool localServer, AgFirmwareMode fwMode, int rssi,
|
|||||||
if (utils::isValidHumidity(this->hum_1)) {
|
if (utils::isValidHumidity(this->hum_1)) {
|
||||||
root["rhum"] = this->hum_1;
|
root["rhum"] = this->hum_1;
|
||||||
if(localServer) {
|
if(localServer) {
|
||||||
val = ag->pms5003t_1.humidityCompensated(this->hum_1);
|
val = ag->pms5003t_1.compensateHum(this->hum_1);
|
||||||
if(utils::isValidHumidity(val)) {
|
if(utils::isValidHumidity(val)) {
|
||||||
root["rhumCompensated"] = (int)val;
|
root["rhumCompensated"] = (int)val;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
root["pm02Compensated"] = ag->pms5003t_1.compensated(this->pm25_1, this->temp_1);
|
root["pm02Compensated"] = ag->pms5003t_1.compensate(this->pm25_1, this->temp_1);
|
||||||
|
if(!localServer) {
|
||||||
|
root[json_prop_pmFirmware] =
|
||||||
|
pms5003TFirmwareVersion(ag->pms5003t_1.getFirmwareVersion());
|
||||||
|
}
|
||||||
} else if (config->hasSensorPMS2) {
|
} else if (config->hasSensorPMS2) {
|
||||||
if(utils::isValidPMS(this->pm01_2)) {
|
if(utils::isValidPm(this->pm01_2)) {
|
||||||
root["pm01"] = this->pm01_2;
|
root["pm01"] = this->pm01_2;
|
||||||
}
|
}
|
||||||
if(utils::isValidPMS(this->pm25_2)) {
|
if(utils::isValidPm(this->pm25_2)) {
|
||||||
root["pm02"] = this->pm25_2;
|
root["pm02"] = this->pm25_2;
|
||||||
}
|
}
|
||||||
if(utils::isValidPMS(this->pm10_2)) {
|
if(utils::isValidPm(this->pm10_2)) {
|
||||||
root["pm10"] = this->pm10_2;
|
root["pm10"] = this->pm10_2;
|
||||||
}
|
}
|
||||||
if(utils::isValidPMS03Count(this->pm03PCount_2)) {
|
if(utils::isValidPm03Count(this->pm03PCount_2)) {
|
||||||
root["pm003Count"] = this->pm03PCount_2;
|
root["pm003Count"] = this->pm03PCount_2;
|
||||||
}
|
}
|
||||||
if (utils::isValidTemperature(this->temp_2)) {
|
if (utils::isValidTemperature(this->temp_2)) {
|
||||||
root["atmp"] = ag->round2(this->temp_2);
|
root["atmp"] = ag->round2(this->temp_2);
|
||||||
if (localServer) {
|
if (localServer) {
|
||||||
|
|
||||||
val = ag->pms5003t_1.temperatureCompensated(this->temp_2);
|
val = ag->pms5003t_1.compensateTemp(this->temp_2);
|
||||||
if (utils::isValidTemperature(val)) {
|
if (utils::isValidTemperature(val)) {
|
||||||
root["atmpCompensated"] = ag->round2(val);
|
root["atmpCompensated"] = ag->round2(val);
|
||||||
}
|
}
|
||||||
@ -235,34 +285,38 @@ String Measurements::toString(bool localServer, AgFirmwareMode fwMode, int rssi,
|
|||||||
root["rhum"] = this->hum_2;
|
root["rhum"] = this->hum_2;
|
||||||
|
|
||||||
if(localServer) {
|
if(localServer) {
|
||||||
val = ag->pms5003t_1.humidityCompensated(this->hum_2);
|
val = ag->pms5003t_1.compensateHum(this->hum_2);
|
||||||
if(utils::isValidHumidity(val)) {
|
if(utils::isValidHumidity(val)) {
|
||||||
root["rhumCompensated"] = (int)val;
|
root["rhumCompensated"] = (int)val;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
root["pm02Compensated"] = ag->pms5003t_1.compensated(this->pm25_1, this->temp_1);
|
root["pm02Compensated"] = ag->pms5003t_1.compensate(this->pm25_1, this->temp_1);
|
||||||
|
if(!localServer) {
|
||||||
|
root[json_prop_pmFirmware] =
|
||||||
|
pms5003TFirmwareVersion(ag->pms5003t_2.getFirmwareVersion());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
float val;
|
float val;
|
||||||
if (config->hasSensorPMS1) {
|
if (config->hasSensorPMS1) {
|
||||||
if(utils::isValidPMS(this->pm01_1)) {
|
if(utils::isValidPm(this->pm01_1)) {
|
||||||
root["channels"]["1"]["pm01"] = this->pm01_1;
|
root["channels"]["1"]["pm01"] = this->pm01_1;
|
||||||
}
|
}
|
||||||
if(utils::isValidPMS(this->pm25_1)) {
|
if(utils::isValidPm(this->pm25_1)) {
|
||||||
root["channels"]["1"]["pm02"] = this->pm25_1;
|
root["channels"]["1"]["pm02"] = this->pm25_1;
|
||||||
}
|
}
|
||||||
if(utils::isValidPMS(this->pm10_1)) {
|
if(utils::isValidPm(this->pm10_1)) {
|
||||||
root["channels"]["1"]["pm10"] = this->pm10_1;
|
root["channels"]["1"]["pm10"] = this->pm10_1;
|
||||||
}
|
}
|
||||||
if (utils::isValidPMS03Count(this->pm03PCount_1)) {
|
if (utils::isValidPm03Count(this->pm03PCount_1)) {
|
||||||
root["channels"]["1"]["pm003Count"] = this->pm03PCount_1;
|
root["channels"]["1"]["pm003Count"] = this->pm03PCount_1;
|
||||||
}
|
}
|
||||||
if(utils::isValidTemperature(this->temp_1)) {
|
if(utils::isValidTemperature(this->temp_1)) {
|
||||||
root["channels"]["1"]["atmp"] = ag->round2(this->temp_1);
|
root["channels"]["1"]["atmp"] = ag->round2(this->temp_1);
|
||||||
|
|
||||||
if (localServer) {
|
if (localServer) {
|
||||||
val = ag->pms5003t_1.temperatureCompensated(this->temp_1);
|
val = ag->pms5003t_1.compensateTemp(this->temp_1);
|
||||||
if (utils::isValidTemperature(val)) {
|
if (utils::isValidTemperature(val)) {
|
||||||
root["channels"]["1"]["atmpCompensated"] = ag->round2(val);
|
root["channels"]["1"]["atmpCompensated"] = ag->round2(val);
|
||||||
}
|
}
|
||||||
@ -272,33 +326,39 @@ String Measurements::toString(bool localServer, AgFirmwareMode fwMode, int rssi,
|
|||||||
root["channels"]["1"]["rhum"] = this->hum_1;
|
root["channels"]["1"]["rhum"] = this->hum_1;
|
||||||
|
|
||||||
if (localServer) {
|
if (localServer) {
|
||||||
val = ag->pms5003t_1.humidityCompensated(this->hum_1);
|
val = ag->pms5003t_1.compensateHum(this->hum_1);
|
||||||
if (utils::isValidHumidity(val)) {
|
if (utils::isValidHumidity(val)) {
|
||||||
root["channels"]["1"]["rhumCompensated"] = (int)val;
|
root["channels"]["1"]["rhumCompensated"] = (int)val;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
root["channels"]["1"]["pm02Compensated"] = ag->pms5003t_1.compensated(this->pm25_1, this->temp_1);
|
root["channels"]["1"]["pm02Compensated"] = ag->pms5003t_1.compensate(this->pm25_1, this->temp_1);
|
||||||
|
|
||||||
|
// PMS5003T version
|
||||||
|
if(!localServer) {
|
||||||
|
root["channels"]["1"][json_prop_pmFirmware] =
|
||||||
|
pms5003TFirmwareVersion(ag->pms5003t_1.getFirmwareVersion());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (config->hasSensorPMS2) {
|
if (config->hasSensorPMS2) {
|
||||||
float val;
|
float val;
|
||||||
if (utils::isValidPMS(this->pm01_2)) {
|
if (utils::isValidPm(this->pm01_2)) {
|
||||||
root["channels"]["2"]["pm01"] = this->pm01_2;
|
root["channels"]["2"]["pm01"] = this->pm01_2;
|
||||||
}
|
}
|
||||||
if (utils::isValidPMS(this->pm25_2)) {
|
if (utils::isValidPm(this->pm25_2)) {
|
||||||
root["channels"]["2"]["pm02"] = this->pm25_2;
|
root["channels"]["2"]["pm02"] = this->pm25_2;
|
||||||
}
|
}
|
||||||
if (utils::isValidPMS(this->pm10_2)) {
|
if (utils::isValidPm(this->pm10_2)) {
|
||||||
root["channels"]["2"]["pm10"] = this->pm10_2;
|
root["channels"]["2"]["pm10"] = this->pm10_2;
|
||||||
}
|
}
|
||||||
if (utils::isValidPMS03Count(this->pm03PCount_2)) {
|
if (utils::isValidPm03Count(this->pm03PCount_2)) {
|
||||||
root["channels"]["2"]["pm003Count"] = this->pm03PCount_2;
|
root["channels"]["2"]["pm003Count"] = this->pm03PCount_2;
|
||||||
}
|
}
|
||||||
if (utils::isValidTemperature(this->temp_2)) {
|
if (utils::isValidTemperature(this->temp_2)) {
|
||||||
root["channels"]["2"]["atmp"] = ag->round2(this->temp_2);
|
root["channels"]["2"]["atmp"] = ag->round2(this->temp_2);
|
||||||
|
|
||||||
if (localServer) {
|
if (localServer) {
|
||||||
val = ag->pms5003t_1.temperatureCompensated(this->temp_2);
|
val = ag->pms5003t_1.compensateTemp(this->temp_2);
|
||||||
if (utils::isValidTemperature(val)) {
|
if (utils::isValidTemperature(val)) {
|
||||||
root["channels"]["2"]["atmpCompensated"] = ag->round2(val);
|
root["channels"]["2"]["atmpCompensated"] = ag->round2(val);
|
||||||
}
|
}
|
||||||
@ -308,13 +368,18 @@ String Measurements::toString(bool localServer, AgFirmwareMode fwMode, int rssi,
|
|||||||
root["channels"]["2"]["rhum"] = this->hum_2;
|
root["channels"]["2"]["rhum"] = this->hum_2;
|
||||||
|
|
||||||
if (localServer) {
|
if (localServer) {
|
||||||
val = ag->pms5003t_1.humidityCompensated(this->hum_2);
|
val = ag->pms5003t_1.compensateHum(this->hum_2);
|
||||||
if (utils::isValidHumidity(val)) {
|
if (utils::isValidHumidity(val)) {
|
||||||
root["channels"]["2"]["rhumCompensated"] = (int)val;
|
root["channels"]["2"]["rhumCompensated"] = (int)val;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
root["channels"]["2"]["pm02Compensated"] = ag->pms5003t_2.compensated(this->pm25_2, this->temp_2);
|
root["channels"]["2"]["pm02Compensated"] = ag->pms5003t_2.compensate(this->pm25_2, this->temp_2);
|
||||||
|
// PMS5003T version
|
||||||
|
if(!localServer) {
|
||||||
|
root["channels"]["2"][json_prop_pmFirmware] =
|
||||||
|
pms5003TFirmwareVersion(ag->pms5003t_2.getFirmwareVersion());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,9 @@
|
|||||||
|
|
||||||
class Measurements {
|
class Measurements {
|
||||||
private:
|
private:
|
||||||
|
String pms5003FirmwareVersion(int fwCode);
|
||||||
|
String pms5003TFirmwareVersion(int fwCode);
|
||||||
|
String pms5003FirmwareVersionBase(String prefix, int fwCode);
|
||||||
public:
|
public:
|
||||||
Measurements() {
|
Measurements() {
|
||||||
pm25_1 = -1;
|
pm25_1 = -1;
|
||||||
|
@ -41,6 +41,28 @@ bool WifiConnector::connect(void) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
WiFi.begin();
|
||||||
|
String wifiSSID = WIFI()->getWiFiSSID(true);
|
||||||
|
if (wifiSSID.isEmpty()) {
|
||||||
|
logInfo("Connected WiFi is empty, connect to default wifi \"" +
|
||||||
|
String(this->defaultSsid) + String("\""));
|
||||||
|
|
||||||
|
/** Set wifi connect */
|
||||||
|
WiFi.begin(this->defaultSsid, this->defaultPassword);
|
||||||
|
|
||||||
|
/** Wait for wifi connect to AP */
|
||||||
|
int count = 0;
|
||||||
|
while (WiFi.status() != WL_CONNECTED) {
|
||||||
|
delay(1000);
|
||||||
|
count++;
|
||||||
|
if (count >= 15) {
|
||||||
|
logError("Try connect to default wifi \"" + String(this->defaultSsid) +
|
||||||
|
String("\" failed"));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
WIFI()->setConfigPortalBlocking(false);
|
WIFI()->setConfigPortalBlocking(false);
|
||||||
WIFI()->setConnectTimeout(15);
|
WIFI()->setConnectTimeout(15);
|
||||||
WIFI()->setTimeout(WIFI_CONNECT_COUNTDOWN_MAX);
|
WIFI()->setTimeout(WIFI_CONNECT_COUNTDOWN_MAX);
|
||||||
@ -383,3 +405,11 @@ bool WifiConnector::hasConfigurated(void) {
|
|||||||
* @return false
|
* @return false
|
||||||
*/
|
*/
|
||||||
bool WifiConnector::isConfigurePorttalTimeout(void) { return connectorTimeout; }
|
bool WifiConnector::isConfigurePorttalTimeout(void) { return connectorTimeout; }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Set wifi connect to default WiFi
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
void WifiConnector::setDefault(void) {
|
||||||
|
WiFi.begin("airgradient", "cleanair");
|
||||||
|
}
|
||||||
|
@ -46,6 +46,10 @@ public:
|
|||||||
String localIpStr(void);
|
String localIpStr(void);
|
||||||
bool hasConfigurated(void);
|
bool hasConfigurated(void);
|
||||||
bool isConfigurePorttalTimeout(void);
|
bool isConfigurePorttalTimeout(void);
|
||||||
|
|
||||||
|
const char* defaultSsid = "airgradient";
|
||||||
|
const char* defaultPassword = "cleanair";
|
||||||
|
void setDefault(void);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /** _AG_WIFI_CONNECTOR_H_ */
|
#endif /** _AG_WIFI_CONNECTOR_H_ */
|
||||||
|
@ -65,6 +65,10 @@ bool AirGradient::isOne(void) {
|
|||||||
return boardType == BoardType::ONE_INDOOR;
|
return boardType == BoardType::ONE_INDOOR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool AirGradient::isOpenAir(void) {
|
||||||
|
return boardType == BoardType::OPEN_AIR_OUTDOOR;
|
||||||
|
}
|
||||||
|
|
||||||
bool AirGradient::isPro4_2(void) {
|
bool AirGradient::isPro4_2(void) {
|
||||||
return boardType == BoardType::DIY_PRO_INDOOR_V4_2;
|
return boardType == BoardType::DIY_PRO_INDOOR_V4_2;
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
#include "Main/utils.h"
|
#include "Main/utils.h"
|
||||||
|
|
||||||
#ifndef GIT_VERSION
|
#ifndef GIT_VERSION
|
||||||
#define GIT_VERSION "3.1.5-snap"
|
#define GIT_VERSION "3.1.7-snap"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -135,6 +135,14 @@ public:
|
|||||||
*/
|
*/
|
||||||
bool isOne(void);
|
bool isOne(void);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Check that Airgradient object is OPEN_AIR
|
||||||
|
*
|
||||||
|
* @return true
|
||||||
|
* @return false
|
||||||
|
*/
|
||||||
|
bool isOpenAir(void);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Check that Airgradient object is DIY_PRO 4.2 indoor
|
* @brief Check that Airgradient object is DIY_PRO 4.2 indoor
|
||||||
*
|
*
|
||||||
|
@ -48,14 +48,14 @@ bool utils::isValidCO2(int16_t value) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool utils::isValidPMS(int value) {
|
bool utils::isValidPm(int value) {
|
||||||
if ((value >= VALID_PMS_MIN) && (value <= VALID_PMS_MAX)) {
|
if ((value >= VALID_PMS_MIN) && (value <= VALID_PMS_MAX)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool utils::isValidPMS03Count(int value) {
|
bool utils::isValidPm03Count(int value) {
|
||||||
if (value >= VALID_PMS03COUNT_MIN) {
|
if (value >= VALID_PMS03COUNT_MIN) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -82,7 +82,7 @@ float utils::getInvalidHumidity(void) { return INVALID_HUMIDITY; }
|
|||||||
|
|
||||||
int utils::getInvalidCO2(void) { return INVALID_CO2; }
|
int utils::getInvalidCO2(void) { return INVALID_CO2; }
|
||||||
|
|
||||||
int utils::getInvalidPMS(void) { return INVALID_PMS; }
|
int utils::getInvalidPmValue(void) { return INVALID_PMS; }
|
||||||
|
|
||||||
int utils::getInvalidNOx(void) { return INVALID_NOX; }
|
int utils::getInvalidNOx(void) { return INVALID_NOX; }
|
||||||
|
|
||||||
|
@ -14,14 +14,14 @@ public:
|
|||||||
static bool isValidTemperature(float value);
|
static bool isValidTemperature(float value);
|
||||||
static bool isValidHumidity(float value);
|
static bool isValidHumidity(float value);
|
||||||
static bool isValidCO2(int16_t value);
|
static bool isValidCO2(int16_t value);
|
||||||
static bool isValidPMS(int value);
|
static bool isValidPm(int value);
|
||||||
static bool isValidPMS03Count(int value);
|
static bool isValidPm03Count(int value);
|
||||||
static bool isValidNOx(int value);
|
static bool isValidNOx(int value);
|
||||||
static bool isValidVOC(int value);
|
static bool isValidVOC(int value);
|
||||||
static float getInvalidTemperature(void);
|
static float getInvalidTemperature(void);
|
||||||
static float getInvalidHumidity(void);
|
static float getInvalidHumidity(void);
|
||||||
static int getInvalidCO2(void);
|
static int getInvalidCO2(void);
|
||||||
static int getInvalidPMS(void);
|
static int getInvalidPmValue(void);
|
||||||
static int getInvalidNOx(void);
|
static int getInvalidNOx(void);
|
||||||
static int getInvalidVOC(void);
|
static int getInvalidVOC(void);
|
||||||
};
|
};
|
||||||
|
@ -12,6 +12,7 @@ bool PMSBase::begin(Stream *stream) {
|
|||||||
this->stream = stream;
|
this->stream = stream;
|
||||||
|
|
||||||
failed = true;
|
failed = true;
|
||||||
|
failCount = 0;
|
||||||
lastRead = 0; // To read buffer on handle without wait after 1.5sec
|
lastRead = 0; // To read buffer on handle without wait after 1.5sec
|
||||||
|
|
||||||
this->stream->flush();
|
this->stream->flush();
|
||||||
@ -147,6 +148,27 @@ void PMSBase::handle() {
|
|||||||
*/
|
*/
|
||||||
bool PMSBase::isFailed(void) { return failed; }
|
bool PMSBase::isFailed(void) { return failed; }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Increate number of fail
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
void PMSBase::updateFailCount(void) {
|
||||||
|
if (failCount < failCountMax) {
|
||||||
|
failCount++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void PMSBase::resetFailCount(void) { failCount = 0; }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Get number of fail
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
int PMSBase::getFailCount(void) { return failCount; }
|
||||||
|
|
||||||
|
int PMSBase::getFailCountMax(void) { return failCountMax; }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Read PMS 0.1 ug/m3 with CF = 1 PM estimates
|
* @brief Read PMS 0.1 ug/m3 with CF = 1 PM estimates
|
||||||
*
|
*
|
||||||
@ -245,6 +267,20 @@ int16_t PMSBase::getTemp(void) { return toI16(&package[24]); }
|
|||||||
*/
|
*/
|
||||||
uint16_t PMSBase::getHum(void) { return toU16(&package[26]); }
|
uint16_t PMSBase::getHum(void) { return toU16(&package[26]); }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Get firmware version code
|
||||||
|
*
|
||||||
|
* @return uint8_t
|
||||||
|
*/
|
||||||
|
uint8_t PMSBase::getFirmwareVersion(void) { return package[28]; }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Ge PMS5003 error code
|
||||||
|
*
|
||||||
|
* @return uint8_t
|
||||||
|
*/
|
||||||
|
uint8_t PMSBase::getErrorCode(void) { return package[29]; }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Convert PMS2.5 to US AQI unit
|
* @brief Convert PMS2.5 to US AQI unit
|
||||||
*
|
*
|
||||||
@ -273,29 +309,32 @@ int PMSBase::pm25ToAQI(int pm02) {
|
|||||||
/**
|
/**
|
||||||
* @brief Correction PM2.5
|
* @brief Correction PM2.5
|
||||||
*
|
*
|
||||||
|
* Formula: https://www.airgradient.com/documentation/correction-algorithms/
|
||||||
|
*
|
||||||
* @param pm25 Raw PM2.5 value
|
* @param pm25 Raw PM2.5 value
|
||||||
* @param humidity Humidity value (%)
|
* @param humidity Humidity value (%)
|
||||||
* @return int
|
* @return int
|
||||||
*/
|
*/
|
||||||
int PMSBase::compensated(int pm25, float humidity) {
|
int PMSBase::compensate(int pm25, float humidity) {
|
||||||
float value;
|
float value;
|
||||||
|
float fpm25 = pm25;
|
||||||
if (humidity < 0) {
|
if (humidity < 0) {
|
||||||
humidity = 0;
|
humidity = 0;
|
||||||
}
|
}
|
||||||
if (humidity > 100) {
|
if (humidity > 100) {
|
||||||
humidity = 100;
|
humidity = 100.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(pm25 < 30) {
|
if(pm25 < 30) { /** pm2.5 < 30 */
|
||||||
value = (pm25 * 0.524f) - (humidity * 0.0862f) + 5.75f;
|
value = (fpm25 * 0.524f) - (humidity * 0.0862f) + 5.75f;
|
||||||
} else if(pm25 < 50) {
|
} else if(pm25 < 50) { /** 30 <= pm2.5 < 50 */
|
||||||
value = (0.786f * (pm25 / 20 - 3 / 2) + 0.524f * (1 - (pm25 / 20 - 3 / 2))) * pm25 - (0.0862f * humidity) + 5.75f;
|
value = (0.786f * (fpm25 * 0.05f - 1.5f) + 0.524f * (1.0f - (fpm25 * 0.05f - 1.5f))) * fpm25 - (0.0862f * humidity) + 5.75f;
|
||||||
} else if(pm25 < 210) {
|
} else if(pm25 < 210) { /** 50 <= pm2.5 < 210 */
|
||||||
value = (0.786f * pm25) - (0.0862f * humidity) + 5.75f;
|
value = (0.786f * fpm25) - (0.0862f * humidity) + 5.75f;
|
||||||
} else if(pm25 < 260) {
|
} else if(pm25 < 260) { /** 210 <= pm2.5 < 260 */
|
||||||
value = (0.69f * (pm25/50 - 21/5) + 0.786f * (1 - (pm25/50 - 21/5))) * pm25 - (0.0862f * humidity * (1 - (pm25/50 - 21/5))) + (2.966f * (pm25/50 -21/5)) + (5.75f * (1 - (pm25/50 - 21/5))) + (8.84f * (1.e-4) * pm25* (pm25/50 - 21/5));
|
value = (0.69f * (fpm25 * 0.02f - 4.2f) + 0.786f * (1.0f - (fpm25 * 0.02f - 4.2f))) * fpm25 - (0.0862f * humidity * (1.0f - (fpm25 * 0.02f - 4.2f))) + (2.966f * (fpm25 * 0.02f - 4.2f)) + (5.75f * (1.0f - (fpm25 * 0.02f - 4.2f))) + (8.84f * (1.e-4) * fpm25 * fpm25 * (fpm25 * 0.02f - 4.2f));
|
||||||
} else {
|
} else { /** 260 <= pm2.5 */
|
||||||
value = 2.966f + (0.69f * pm25) + (8.84f * (1.e-4) * pm25);
|
value = 2.966f + (0.69f * fpm25) + (8.84f * (1.e-4) * fpm25 * fpm25);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(value < 0) {
|
if(value < 0) {
|
||||||
|
@ -3,11 +3,17 @@
|
|||||||
|
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
|
|
||||||
|
#define PMS_FAIL_COUNT_SET_INVALID 3
|
||||||
|
|
||||||
class PMSBase {
|
class PMSBase {
|
||||||
public:
|
public:
|
||||||
bool begin(Stream *stream);
|
bool begin(Stream *stream);
|
||||||
void handle();
|
void handle();
|
||||||
bool isFailed(void);
|
bool isFailed(void);
|
||||||
|
void updateFailCount(void);
|
||||||
|
void resetFailCount(void);
|
||||||
|
int getFailCount(void);
|
||||||
|
int getFailCountMax(void);
|
||||||
uint16_t getRaw0_1(void);
|
uint16_t getRaw0_1(void);
|
||||||
uint16_t getRaw2_5(void);
|
uint16_t getRaw2_5(void);
|
||||||
uint16_t getRaw10(void);
|
uint16_t getRaw10(void);
|
||||||
@ -26,9 +32,11 @@ public:
|
|||||||
/** For PMS5003T*/
|
/** For PMS5003T*/
|
||||||
int16_t getTemp(void);
|
int16_t getTemp(void);
|
||||||
uint16_t getHum(void);
|
uint16_t getHum(void);
|
||||||
|
uint8_t getFirmwareVersion(void);
|
||||||
|
uint8_t getErrorCode(void);
|
||||||
|
|
||||||
int pm25ToAQI(int pm02);
|
int pm25ToAQI(int pm02);
|
||||||
int compensated(int pm25, float humidity);
|
int compensate(int pm25, float humidity);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Stream *stream;
|
Stream *stream;
|
||||||
@ -36,6 +44,8 @@ private:
|
|||||||
int packageIndex;
|
int packageIndex;
|
||||||
bool failed = false;
|
bool failed = false;
|
||||||
uint32_t lastRead;
|
uint32_t lastRead;
|
||||||
|
const int failCountMax = 10;
|
||||||
|
int failCount = 0;
|
||||||
|
|
||||||
int16_t toI16(char *buf);
|
int16_t toI16(char *buf);
|
||||||
uint16_t toU16(char* buf);
|
uint16_t toU16(char* buf);
|
||||||
|
@ -78,7 +78,7 @@ bool PMS5003::begin(void) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
_ver = pms.getFirmwareVersion();
|
||||||
this->_isBegin = true;
|
this->_isBegin = true;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -124,14 +124,30 @@ int PMS5003::convertPm25ToUsAqi(int pm25) { return pms.pm25ToAQI(pm25); }
|
|||||||
/**
|
/**
|
||||||
* @brief Correct PM2.5
|
* @brief Correct PM2.5
|
||||||
*
|
*
|
||||||
|
* Reference formula: https://www.airgradient.com/documentation/correction-algorithms/
|
||||||
|
*
|
||||||
* @param pm25 PM2.5 raw value
|
* @param pm25 PM2.5 raw value
|
||||||
* @param humidity Humidity value
|
* @param humidity Humidity value
|
||||||
* @return float
|
* @return int
|
||||||
*/
|
*/
|
||||||
int PMS5003::compensated(int pm25, float humidity) {
|
int PMS5003::compensate(int pm25, float humidity) {
|
||||||
return pms.compensated(pm25, humidity);
|
return pms.compensate(pm25, humidity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Get sensor firmware version
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
int PMS5003::getFirmwareVersion(void) { return _ver; }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Get sensor error code
|
||||||
|
*
|
||||||
|
* @return uint8_t
|
||||||
|
*/
|
||||||
|
uint8_t PMS5003::getErrorCode(void) { return pms.getErrorCode(); }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Check device initialized or not
|
* @brief Check device initialized or not
|
||||||
*
|
*
|
||||||
@ -175,3 +191,25 @@ void PMS5003::handle(void) { pms.handle(); }
|
|||||||
* @return false Communication timeout or sensor has removed
|
* @return false Communication timeout or sensor has removed
|
||||||
*/
|
*/
|
||||||
bool PMS5003::isFailed(void) { return pms.isFailed(); }
|
bool PMS5003::isFailed(void) { return pms.isFailed(); }
|
||||||
|
|
||||||
|
void PMS5003::updateFailCount(void) {
|
||||||
|
pms.updateFailCount();
|
||||||
|
}
|
||||||
|
|
||||||
|
void PMS5003::resetFailCount(void) {
|
||||||
|
pms.resetFailCount();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Get number of fail count
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
int PMS5003::getFailCount(void) { return pms.getFailCount(); }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Get number of fail count max
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
int PMS5003::getFailCountMax(void) { return pms.getFailCountMax(); }
|
||||||
|
@ -19,15 +19,22 @@ public:
|
|||||||
void end(void);
|
void end(void);
|
||||||
void handle(void);
|
void handle(void);
|
||||||
bool isFailed(void);
|
bool isFailed(void);
|
||||||
|
void updateFailCount(void);
|
||||||
|
void resetFailCount(void);
|
||||||
|
int getFailCount(void);
|
||||||
|
int getFailCountMax(void);
|
||||||
int getPm01Ae(void);
|
int getPm01Ae(void);
|
||||||
int getPm25Ae(void);
|
int getPm25Ae(void);
|
||||||
int getPm10Ae(void);
|
int getPm10Ae(void);
|
||||||
int getPm03ParticleCount(void);
|
int getPm03ParticleCount(void);
|
||||||
int convertPm25ToUsAqi(int pm25);
|
int convertPm25ToUsAqi(int pm25);
|
||||||
int compensated(int pm25, float humidity);
|
int compensate(int pm25, float humidity);
|
||||||
|
int getFirmwareVersion(void);
|
||||||
|
uint8_t getErrorCode(void);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool _isBegin = false;
|
bool _isBegin = false;
|
||||||
|
int _ver;
|
||||||
BoardType _boardDef;
|
BoardType _boardDef;
|
||||||
PMSBase pms;
|
PMSBase pms;
|
||||||
const BoardDef *bsp;
|
const BoardDef *bsp;
|
||||||
|
@ -103,7 +103,7 @@ bool PMS5003T::begin(void) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
_ver = pms.getFirmwareVersion();
|
||||||
this->_isBegin = true;
|
this->_isBegin = true;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -167,14 +167,30 @@ float PMS5003T::getRelativeHumidity(void) {
|
|||||||
/**
|
/**
|
||||||
* @brief Correct PM2.5
|
* @brief Correct PM2.5
|
||||||
*
|
*
|
||||||
|
* Reference formula: https://www.airgradient.com/documentation/correction-algorithms/
|
||||||
|
*
|
||||||
* @param pm25 PM2.5 raw value
|
* @param pm25 PM2.5 raw value
|
||||||
* @param humidity Humidity value
|
* @param humidity Humidity value
|
||||||
* @return float
|
* @return int
|
||||||
*/
|
*/
|
||||||
float PMS5003T::compensated(int pm25, float humidity) {
|
int PMS5003T::compensate(int pm25, float humidity) {
|
||||||
return pms.compensated(pm25, humidity);
|
return pms.compensate(pm25, humidity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Get module(s) firmware version
|
||||||
|
*
|
||||||
|
* @return int Version code
|
||||||
|
*/
|
||||||
|
int PMS5003T::getFirmwareVersion(void) { return _ver; }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Get sensor error code
|
||||||
|
*
|
||||||
|
* @return uint8_t
|
||||||
|
*/
|
||||||
|
uint8_t PMS5003T::getErrorCode(void) { return pms.getErrorCode(); }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Check device initialized or not
|
* @brief Check device initialized or not
|
||||||
*
|
*
|
||||||
@ -216,3 +232,24 @@ void PMS5003T::handle(void) { pms.handle(); }
|
|||||||
*/
|
*/
|
||||||
bool PMS5003T::isFailed(void) { return pms.isFailed(); }
|
bool PMS5003T::isFailed(void) { return pms.isFailed(); }
|
||||||
|
|
||||||
|
void PMS5003T::updateFailCount(void) {
|
||||||
|
pms.updateFailCount();
|
||||||
|
}
|
||||||
|
|
||||||
|
void PMS5003T::resetFailCount(void) {
|
||||||
|
pms.resetFailCount();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Get fail count
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
int PMS5003T::getFailCount(void) { return pms.getFailCount(); }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Get fail count max
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
int PMS5003T::getFailCountMax(void) { return pms.getFailCountMax(); }
|
||||||
|
@ -22,6 +22,10 @@ public:
|
|||||||
|
|
||||||
void handle(void);
|
void handle(void);
|
||||||
bool isFailed(void);
|
bool isFailed(void);
|
||||||
|
void updateFailCount(void);
|
||||||
|
void resetFailCount(void);
|
||||||
|
int getFailCount(void);
|
||||||
|
int getFailCountMax(void);
|
||||||
int getPm01Ae(void);
|
int getPm01Ae(void);
|
||||||
int getPm25Ae(void);
|
int getPm25Ae(void);
|
||||||
int getPm10Ae(void);
|
int getPm10Ae(void);
|
||||||
@ -29,11 +33,14 @@ public:
|
|||||||
int convertPm25ToUsAqi(int pm25);
|
int convertPm25ToUsAqi(int pm25);
|
||||||
float getTemperature(void);
|
float getTemperature(void);
|
||||||
float getRelativeHumidity(void);
|
float getRelativeHumidity(void);
|
||||||
float compensated(int pm25, float humidity);
|
int compensate(int pm25, float humidity);
|
||||||
|
int getFirmwareVersion(void);
|
||||||
|
uint8_t getErrorCode(void);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool _isBegin = false;
|
bool _isBegin = false;
|
||||||
bool _isSleep = false;
|
bool _isSleep = false;
|
||||||
|
int _ver; /** Firmware version code */
|
||||||
|
|
||||||
BoardType _boardDef;
|
BoardType _boardDef;
|
||||||
const BoardDef *bsp;
|
const BoardDef *bsp;
|
||||||
|
@ -4,14 +4,30 @@ PMS5003TBase::PMS5003TBase() {}
|
|||||||
|
|
||||||
PMS5003TBase::~PMS5003TBase() {}
|
PMS5003TBase::~PMS5003TBase() {}
|
||||||
|
|
||||||
float PMS5003TBase::temperatureCompensated(float temp) {
|
/**
|
||||||
|
* @brief Compensate the temperature
|
||||||
|
*
|
||||||
|
* Reference formula: https://www.airgradient.com/documentation/correction-algorithms/
|
||||||
|
*
|
||||||
|
* @param temp
|
||||||
|
* @return * float
|
||||||
|
*/
|
||||||
|
float PMS5003TBase::compensateTemp(float temp) {
|
||||||
if (temp < 10.0f) {
|
if (temp < 10.0f) {
|
||||||
return temp * 1.327f - 6.738f;
|
return temp * 1.327f - 6.738f;
|
||||||
}
|
}
|
||||||
return temp * 1.181f - 5.113f;
|
return temp * 1.181f - 5.113f;
|
||||||
}
|
}
|
||||||
|
|
||||||
float PMS5003TBase::humidityCompensated(float hum) {
|
/**
|
||||||
|
* @brief Compensate the humidity
|
||||||
|
*
|
||||||
|
* Reference formula: https://www.airgradient.com/documentation/correction-algorithms/
|
||||||
|
*
|
||||||
|
* @param temp
|
||||||
|
* @return * float
|
||||||
|
*/
|
||||||
|
float PMS5003TBase::compensateHum(float hum) {
|
||||||
hum = hum * 1.259f + 7.34f;
|
hum = hum * 1.259f + 7.34f;
|
||||||
|
|
||||||
if (hum > 100.0f) {
|
if (hum > 100.0f) {
|
||||||
|
@ -8,8 +8,8 @@ private:
|
|||||||
public:
|
public:
|
||||||
PMS5003TBase();
|
PMS5003TBase();
|
||||||
~PMS5003TBase();
|
~PMS5003TBase();
|
||||||
float temperatureCompensated(float temp);
|
float compensateTemp(float temp);
|
||||||
float humidityCompensated(float hum);
|
float compensateHum(float hum);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Reference in New Issue
Block a user