diff --git a/examples/BASIC_v4/BASIC_v4.ino b/examples/BASIC_v4/BASIC_v4.ino index ac3431b..dd96b3a 100644 --- a/examples/BASIC_v4/BASIC_v4.ino +++ b/examples/BASIC_v4/BASIC_v4.ino @@ -1,7 +1,9 @@ /* -This is the code for the AirGradient DIY BASIC Air Quality Monitor with an D1 ESP8266 Microcontroller. +This is the code for the AirGradient DIY BASIC Air Quality Monitor with an D1 +ESP8266 Microcontroller. -It is an air quality monitor for PM2.5, CO2, Temperature and Humidity with a small display and can send data over Wifi. +It is an air quality monitor for PM2.5, CO2, Temperature and Humidity with a +small display and can send data over Wifi. Open source air quality monitors and kits are available: Indoor Monitor: https://www.airgradient.com/indoor/ @@ -15,11 +17,13 @@ Following libraries need to be installed: "Arduino_JSON" by Arduino version 0.2.0 "U8g2" by oliver version 2.34.22 -Please make sure you have esp8266 board manager installed. Tested with version 3.1.2. +Please make sure you have esp8266 board manager installed. Tested with +version 3.1.2. Set board to "LOLIN(WEMOS) D1 R2 & mini" -Configuration parameters, e.g. Celsius / Fahrenheit or PM unit (US AQI vs ug/m3) can be set through the AirGradient dashboard. +Configuration parameters, e.g. Celsius / Fahrenheit or PM unit (US AQI vs ug/m3) +can be set through the AirGradient dashboard. If you have any questions please visit our forum at https://forum.airgradient.com/ @@ -207,6 +211,13 @@ public: } } + /** Get 'abcDays' */ + if (JSON.typeof_(root["abcDays"]) == "number") { + co2AbcCalib = root["abcDays"]; + } else { + co2AbcCalib = -1; + } + /** Show configuration */ showServerConfig(); @@ -289,6 +300,13 @@ public: return ret; } + /** + * @brief Get the Co2 auto calib period + * + * @return int days, -1 if invalid. + */ + int getCo2Abccalib(void) { return co2AbcCalib; } + /** * @brief Get device configuration model name * @@ -308,11 +326,12 @@ public: */ void showServerConfig(void) { Serial.println("Server configuration: "); - Serial.printf(" inF: %s\r\n", inF ? "true" : "false"); - Serial.printf(" inUSAQI: %s\r\n", inUSAQI ? "true" : "false"); - Serial.printf("useRGBLedBar: %d\r\n", (int)ledBarMode); - Serial.printf(" Model: %s\r\n", models); - Serial.printf(" Mqtt Broker: %s\r\n", mqttBroker); + Serial.printf(" inF: %s\r\n", inF ? "true" : "false"); + Serial.printf(" inUSAQI: %s\r\n", inUSAQI ? "true" : "false"); + Serial.printf(" useRGBLedBar: %d\r\n", (int)ledBarMode); + Serial.printf(" Model: %s\r\n", models); + Serial.printf(" Mqtt Broker: %s\r\n", mqttBroker); + Serial.printf(" S8 calib period: %d\r\n", co2AbcCalib); } /** @@ -323,11 +342,12 @@ public: UseLedBar getLedBarMode(void) { return ledBarMode; } private: - bool inF; /** Temperature unit, true: F, false: C */ - bool inUSAQI; /** PMS unit, true: USAQI, false: ugm3 */ - bool configFailed; /** Flag indicate get server configuration failed */ - bool serverFailed; /** Flag indicate post data to server failed */ - bool co2Calib; /** Is co2Ppmcalibration requset */ + bool inF; /** Temperature unit, true: F, false: C */ + bool inUSAQI; /** PMS unit, true: USAQI, false: ugm3 */ + bool configFailed; /** Flag indicate get server configuration failed */ + bool serverFailed; /** Flag indicate post data to server failed */ + bool co2Calib; /** Is co2Ppmcalibration requset */ + int co2AbcCalib = -1; /** update auto calibration number of day */ UseLedBar ledBarMode = UseLedBarCO2; /** */ char models[20]; /** */ char mqttBroker[256]; /** */ @@ -527,6 +547,11 @@ static void serverConfigPoll(void) { if (agServer.isCo2Calib()) { co2Calibration(); } + if (agServer.getCo2Abccalib() > 0) { + if (ag.s8.setAutoCalib(agServer.getCo2Abccalib() * 24) == false) { + Serial.println("Set S8 auto calib failed"); + } + } } } diff --git a/examples/ONE_I-9PSL/ONE_I-9PSL.ino b/examples/ONE_I-9PSL/ONE_I-9PSL.ino index 8f643b8..ae32284 100644 --- a/examples/ONE_I-9PSL/ONE_I-9PSL.ino +++ b/examples/ONE_I-9PSL/ONE_I-9PSL.ino @@ -253,6 +253,13 @@ public: } } + /** Get 'abcDays' */ + if (JSON.typeof_(root["abcDays"]) == "number") { + co2AbcCalib = root["abcDays"]; + } else { + co2AbcCalib = -1; + } + /** Show configuration */ showServerConfig(); @@ -335,6 +342,13 @@ public: return ret; } + /** + * @brief Get the Co2 auto calib period + * + * @return int days, -1 if invalid. + */ + int getCo2Abccalib(void) { return co2AbcCalib; } + /** * @brief Get device configuration model name * @@ -354,11 +368,12 @@ public: */ void showServerConfig(void) { Serial.println("Server configuration: "); - Serial.printf(" inF: %s\r\n", inF ? "true" : "false"); - Serial.printf(" inUSAQI: %s\r\n", inUSAQI ? "true" : "false"); - Serial.printf("useRGBLedBar: %d\r\n", (int)ledBarMode); - Serial.printf(" Model: %s\r\n", models); - Serial.printf(" Mqtt Broker: %s\r\n", mqttBroker); + Serial.printf(" inF: %s\r\n", inF ? "true" : "false"); + Serial.printf(" inUSAQI: %s\r\n", inUSAQI ? "true" : "false"); + Serial.printf(" useRGBLedBar: %d\r\n", (int)ledBarMode); + Serial.printf(" Model: %s\r\n", models); + Serial.printf(" Mqtt Broker: %s\r\n", mqttBroker); + Serial.printf(" S8 calib period: %d\r\n", co2AbcCalib); } /** @@ -369,11 +384,12 @@ public: UseLedBar getLedBarMode(void) { return ledBarMode; } private: - bool inF; /** Temperature unit, true: F, false: C */ - bool inUSAQI; /** PMS unit, true: USAQI, false: ugm3 */ - bool configFailed; /** Flag indicate get server configuration failed */ - bool serverFailed; /** Flag indicate post data to server failed */ - bool co2Calib; /** Is co2Ppmcalibration requset */ + bool inF; /** Temperature unit, true: F, false: C */ + bool inUSAQI; /** PMS unit, true: USAQI, false: ugm3 */ + bool configFailed; /** Flag indicate get server configuration failed */ + bool serverFailed; /** Flag indicate post data to server failed */ + bool co2Calib; /** Is co2Ppmcalibration requset */ + int co2AbcCalib = -1; /** update auto calibration number of day */ UseLedBar ledBarMode = UseLedBarCO2; /** */ char models[20]; /** */ char mqttBroker[256]; /** */ @@ -922,6 +938,11 @@ static void serverConfigPoll(void) { if (agServer.isCo2Calib()) { co2Calibration(); } + if (agServer.getCo2Abccalib() > 0) { + if (ag.s8.setAutoCalib(agServer.getCo2Abccalib() * 24) == false) { + Serial.println("Set S8 auto calib failed"); + } + } } } @@ -1116,7 +1137,8 @@ static void dispSmHandler(int sm) { case APP_SM_WIFI_MAMAGER_PORTAL_ACTIVE: { if (connectCountDown >= 0) { displayShowWifiText(String(connectCountDown) + "s to connect", - "to WiFi hotspot:", "\"airgradient-", getDevId() + "\""); + "to WiFi hotspot:", "\"airgradient-", + getDevId() + "\""); connectCountDown--; } break; diff --git a/examples/Open_Air_O-1PST/Open_Air_O-1PST.ino b/examples/Open_Air_O-1PST/Open_Air_O-1PST.ino index 533d9f7..8a8eed2 100644 --- a/examples/Open_Air_O-1PST/Open_Air_O-1PST.ino +++ b/examples/Open_Air_O-1PST/Open_Air_O-1PST.ino @@ -1,19 +1,23 @@ /* -This is the code for the AirGradient Open Air open-source hardware outdoor Air Quality Monitor with an ESP32-C3 Microcontroller. +This is the code for the AirGradient Open Air open-source hardware outdoor Air +Quality Monitor with an ESP32-C3 Microcontroller. -It is an air quality monitor for PM2.5, CO2, TVOCs, NOx, Temperature and Humidity and can send data over Wifi. +It is an air quality monitor for PM2.5, CO2, TVOCs, NOx, Temperature and +Humidity and can send data over Wifi. Open source air quality monitors and kits are available: Indoor Monitor: https://www.airgradient.com/indoor/ Outdoor Monitor: https://www.airgradient.com/outdoor/ -Build Instructions: https://www.airgradient.com/documentation/open-air-pst-kit-1-3/ +Build Instructions: +https://www.airgradient.com/documentation/open-air-pst-kit-1-3/ The codes needs the following libraries installed: “WifiManager by tzapu, tablatronix” tested with version 2.0.16-rc.2 "Arduino_JSON" by Arduino Version 0.2.0 -Please make sure you have esp32 board manager installed. Tested with version 2.0.11. +Please make sure you have esp32 board manager installed. Tested with +version 2.0.11. Important flashing settings: - Set board to "ESP32C3 Dev Module" @@ -248,6 +252,13 @@ public: } } + /** Get 'abcDays' */ + if (JSON.typeof_(root["abcDays"]) == "number") { + co2AbcCalib = root["abcDays"]; + } else { + co2AbcCalib = -1; + } + /** Show configuration */ showServerConfig(); @@ -330,6 +341,13 @@ public: return ret; } + /** + * @brief Get the Co2 auto calib period + * + * @return int days, -1 if invalid. + */ + int getCo2Abccalib(void) { return co2AbcCalib; } + /** * @brief Get device configuration model name * @@ -349,11 +367,12 @@ public: */ void showServerConfig(void) { Serial.println("Server configuration: "); - Serial.printf(" inF: %s\r\n", inF ? "true" : "false"); - Serial.printf(" inUSAQI: %s\r\n", inUSAQI ? "true" : "false"); - Serial.printf("useRGBLedBar: %d\r\n", (int)ledBarMode); - Serial.printf(" Model: %s\r\n", models); - Serial.printf(" Mqtt Broker: %s\r\n", mqttBroker); + Serial.printf(" inF: %s\r\n", inF ? "true" : "false"); + Serial.printf(" inUSAQI: %s\r\n", inUSAQI ? "true" : "false"); + Serial.printf(" useRGBLedBar: %d\r\n", (int)ledBarMode); + Serial.printf(" Model: %s\r\n", models); + Serial.printf(" Mqtt Broker: %s\r\n", mqttBroker); + Serial.printf(" S8 calib period: %d\r\n", co2AbcCalib); } /** @@ -364,11 +383,12 @@ public: UseLedBar getLedBarMode(void) { return ledBarMode; } private: - bool inF; /** Temperature unit, true: F, false: C */ - bool inUSAQI; /** PMS unit, true: USAQI, false: ugm3 */ - bool configFailed; /** Flag indicate get server configuration failed */ - bool serverFailed; /** Flag indicate post data to server failed */ - bool co2Calib; /** Is co2Ppmcalibration requset */ + bool inF; /** Temperature unit, true: F, false: C */ + bool inUSAQI; /** PMS unit, true: USAQI, false: ugm3 */ + bool configFailed; /** Flag indicate get server configuration failed */ + bool serverFailed; /** Flag indicate post data to server failed */ + bool co2Calib; /** Is co2Ppmcalibration requset */ + int co2AbcCalib = -1; /** update auto calibration number of day */ UseLedBar ledBarMode = UseLedBarCO2; /** */ char models[20]; /** */ char mqttBroker[256]; /** */ @@ -693,6 +713,11 @@ static void serverConfigPoll(void) { if (agServer.isCo2Calib()) { co2Calibration(); } + if (agServer.getCo2Abccalib() > 0) { + if (ag.s8.setAutoCalib(agServer.getCo2Abccalib() * 24) == false) { + Serial.println("Set S8 auto calib failed"); + } + } } } diff --git a/examples/TestESP8266/TestESP8266.ino b/examples/TestESP8266/TestESP8266.ino index ced36fb..dbe4dfe 100644 --- a/examples/TestESP8266/TestESP8266.ino +++ b/examples/TestESP8266/TestESP8266.ino @@ -9,10 +9,11 @@ /** * @brief Define test sensor */ -#define TEST_SENSOR_SenseAirS8 0 +#define TEST_SENSOR_SenseAirS8 1 +// #define S8_BASELINE_CALIB #define TEST_SENSOR_PMS5003 0 #define TEST_SENSOR_SHT4x 0 -#define TEST_SENSOR_SGP4x 1 +#define TEST_SENSOR_SGP4x 0 #define TEST_SWITCH 0 #define TEST_OLED 0 @@ -37,11 +38,19 @@ void setup() { Serial.println("CO2S8 sensor init failure"); } +#ifdef S8_BASELINE_CALIB if (ag.s8.setBaselineCalibration()) { Serial.println("Manual calib success"); } else { Serial.println("Manual calib failure"); } +#else + if (ag.s8.setAutoCalib(8)) { + Serial.println("Set auto calib success"); + } else { + Serial.println("Set auto calib failure"); + } +#endif delay(5000); #endif @@ -141,7 +150,7 @@ void loop() { /*** * Must call this task on loop and avoid delay on loop over 1000 ms - */ + */ ag.sgp41.handle(); if (ms >= 1000) { diff --git a/src/AirGradient.cpp b/src/AirGradient.cpp index e60a4d8..81743eb 100644 --- a/src/AirGradient.cpp +++ b/src/AirGradient.cpp @@ -1,6 +1,6 @@ #include "AirGradient.h" -#define AG_LIB_VER "2.5.0" +#define AG_LIB_VER "3.0.0" AirGradient::AirGradient(BoardType type) : pms5003(type), pms5003t_1(type), pms5003t_2(type), s8(type), sht4x(type), diff --git a/src/s8/s8.cpp b/src/s8/s8.cpp index ef21ad1..628cc5b 100644 --- a/src/s8/s8.cpp +++ b/src/s8/s8.cpp @@ -793,3 +793,23 @@ void S8::sendCommand(uint8_t func, uint16_t reg, uint16_t value) { uartWriteBytes(8); } } + +/** + * @brief Set Auto calib baseline period + * + * @param hours Number of hour will trigger auto calib: [0, 4800], 0: disable + * @return true Success + * @return false Failure + */ +bool S8::setAutoCalib(int hours) { + if (isBegin() == false) { + return false; + } + + int curCalib = getCalibPeriodABC(); + if (curCalib == hours) { + return true; + } + + return setCalibPeriodABC(hours); +} diff --git a/src/s8/s8.h b/src/s8/s8.h index 556a289..b967a9e 100644 --- a/src/s8/s8.h +++ b/src/s8/s8.h @@ -78,6 +78,7 @@ public: int16_t getCo2(void); bool setBaselineCalibration(void); bool isBaseLineCalibrationDone(void); + bool setAutoCalib(int hours); private: /** Variables */