Merge pull request #73 from airgradienthq/develop

Develop
This commit is contained in:
Phat Nguyen
2024-03-06 17:24:52 +07:00
committed by GitHub
8 changed files with 164 additions and 59 deletions

View File

@ -382,7 +382,9 @@ bool hasSensorS8 = true;
bool hasSensorPMS = true; bool hasSensorPMS = true;
bool hasSensorSHT = true; bool hasSensorSHT = true;
int pmFailCount = 0; int pmFailCount = 0;
AgSchedule configSchedule(SERVER_CONFIG_UPDATE_INTERVAL, updateServerConfiguration); int getCO2FailCount = 0;
AgSchedule configSchedule(SERVER_CONFIG_UPDATE_INTERVAL,
updateServerConfiguration);
AgSchedule serverSchedule(SERVER_SYNC_INTERVAL, sendDataToServer); AgSchedule serverSchedule(SERVER_SYNC_INTERVAL, sendDataToServer);
AgSchedule dispSchedule(DISP_UPDATE_INTERVAL, dispHandler); AgSchedule dispSchedule(DISP_UPDATE_INTERVAL, dispHandler);
AgSchedule co2Schedule(SENSOR_CO2_UPDATE_INTERVAL, co2Update); AgSchedule co2Schedule(SENSOR_CO2_UPDATE_INTERVAL, co2Update);
@ -591,7 +593,7 @@ static void updateServerConfiguration(void) {
Serial.printf("abcDays config: %d days(%d hours)\r\n", Serial.printf("abcDays config: %d days(%d hours)\r\n",
agServer.getCo2AbcDaysConfig(), newHour); agServer.getCo2AbcDaysConfig(), newHour);
int curHour = ag.s8.getAbcPeriod(); int curHour = ag.s8.getAbcPeriod();
Serial.printf("Current config: %d (hours)\r\n", ag.s8.getAbcPeriod()); Serial.printf("Current config: %d (hours)\r\n", curHour);
if (curHour == newHour) { if (curHour == newHour) {
Serial.println("set 'abcDays' ignored"); Serial.println("set 'abcDays' ignored");
} else { } else {
@ -610,8 +612,18 @@ static void updateServerConfiguration(void) {
} }
static void co2Update() { static void co2Update() {
co2Ppm = ag.s8.getCo2(); int value = ag.s8.getCo2();
Serial.printf("CO2 index: %d\r\n", co2Ppm); if (value >= 0) {
co2Ppm = value;
getCO2FailCount = 0;
Serial.printf("CO2 index: %d\r\n", co2Ppm);
} else {
getCO2FailCount++;
Serial.printf("Get CO2 failed: %d\r\n", getCO2FailCount);
if (getCO2FailCount >= 3) {
co2Ppm = -1;
}
}
} }
void pmUpdate() { void pmUpdate() {

View File

@ -669,6 +669,7 @@ static int dispSmState = APP_SM_NORMAL; /** Save LED SM */
static int tvocIndex = -1; static int tvocIndex = -1;
static int tvocRawIndex = -1; static int tvocRawIndex = -1;
static int noxIndex = -1; static int noxIndex = -1;
static int noxRawIndex = -1;
static int co2Ppm = -1; static int co2Ppm = -1;
static int pm25 = -1; static int pm25 = -1;
static int pm01 = -1; static int pm01 = -1;
@ -711,6 +712,7 @@ bool hasSensorSHT = true;
int pmFailCount = 0; int pmFailCount = 0;
uint32_t factoryBtnPressTime = 0; uint32_t factoryBtnPressTime = 0;
String mdnsModelName = ""; String mdnsModelName = "";
int getCO2FailCount = 0;
AgSchedule dispLedSchedule(DISP_UPDATE_INTERVAL, displayAndLedBarUpdate); AgSchedule dispLedSchedule(DISP_UPDATE_INTERVAL, displayAndLedBarUpdate);
AgSchedule configSchedule(SERVER_CONFIG_UPDATE_INTERVAL, AgSchedule configSchedule(SERVER_CONFIG_UPDATE_INTERVAL,
updateServerConfiguration); updateServerConfiguration);
@ -736,7 +738,7 @@ void setup() {
u8g2.begin(); u8g2.begin();
/** Show boot display */ /** Show boot display */
Serial.println("Firmware Version: "+ag.getVersion()); Serial.println("Firmware Version: " + ag.getVersion());
displayShowText("One V9", "FW Ver: " + ag.getVersion(), ""); displayShowText("One V9", "FW Ver: " + ag.getVersion(), "");
delay(DISPLAY_DELAY_SHOW_CONTENT_MS); delay(DISPLAY_DELAY_SHOW_CONTENT_MS);
@ -909,8 +911,18 @@ static void ledTest2Min(void) {
} }
static void co2Update(void) { static void co2Update(void) {
co2Ppm = ag.s8.getCo2(); int value = ag.s8.getCo2();
Serial.printf("CO2 index: %d\r\n", co2Ppm); if (value >= 0) {
co2Ppm = value;
getCO2FailCount = 0;
Serial.printf("CO2 index: %d\r\n", co2Ppm);
} else {
getCO2FailCount++;
Serial.printf("Get CO2 failed: %d\r\n", getCO2FailCount);
if (getCO2FailCount >= 3) {
co2Ppm = 1;
}
}
} }
static void showNr(void) { Serial.println("Serial nr: " + getDevId()); } static void showNr(void) { Serial.println("Serial nr: " + getDevId()); }
@ -1016,7 +1028,7 @@ void webServerMetricsGet(void) {
add_metric_point("", String(tvocIndex)); add_metric_point("", String(tvocIndex));
} }
if (tvocRawIndex >= 0) { if (tvocRawIndex >= 0) {
add_metric("tvoc_raw_index", add_metric("tvoc_raw",
"The raw input value to the Total Volatile Organic Compounds " "The raw input value to the Total Volatile Organic Compounds "
"(TVOC) index as measured by the AirGradient SGP sensor", "(TVOC) index as measured by the AirGradient SGP sensor",
"gauge"); "gauge");
@ -1029,6 +1041,13 @@ void webServerMetricsGet(void) {
"gauge"); "gauge");
add_metric_point("", String(noxIndex)); add_metric_point("", String(noxIndex));
} }
if (noxRawIndex >= 0) {
add_metric("nox_raw",
"The raw input value to the Nitrous Oxide (NOx) index as "
"measured by the AirGradient SGP sensor",
"gauge");
add_metric_point("", String(noxRawIndex));
}
} }
if (hasSensorSHT) { if (hasSensorSHT) {
@ -1072,10 +1091,7 @@ static void webServerInit(void) {
webServer.on("/metrics", HTTP_GET, webServerMetricsGet); webServer.on("/metrics", HTTP_GET, webServerMetricsGet);
webServer.begin(); webServer.begin();
MDNS.addService("http", "tcp", 80); MDNS.addService("http", "tcp", 80);
if (agServer.getModelName().isEmpty() != true) { MDNS.addServiceTxt("http", "_tcp", "model", ag.getBoardName());
MDNS.addServiceTxt("http", "_tcp", "model", agServer.getModelName());
mdnsModelName = agServer.getModelName();
}
MDNS.addServiceTxt("http", "_tcp", "serialno", getDevId()); MDNS.addServiceTxt("http", "_tcp", "serialno", getDevId());
MDNS.addServiceTxt("http", "_tcp", "fw_ver", ag.getVersion()); MDNS.addServiceTxt("http", "_tcp", "fw_ver", ag.getVersion());
@ -1121,6 +1137,9 @@ static String getServerSyncData(bool localServer) {
if (noxIndex >= 0) { if (noxIndex >= 0) {
root["nox_index"] = noxIndex; root["nox_index"] = noxIndex;
} }
if (noxRawIndex >= 0) {
root["nox_raw"] = noxRawIndex;
}
} }
if (hasSensorSHT) { if (hasSensorSHT) {
if (temp > -1001) { if (temp > -1001) {
@ -1744,7 +1763,7 @@ static void updateServerConfiguration(void) {
Serial.printf("abcDays config: %d days(%d hours)\r\n", Serial.printf("abcDays config: %d days(%d hours)\r\n",
agServer.getCo2AbcDaysConfig(), newHour); agServer.getCo2AbcDaysConfig(), newHour);
int curHour = ag.s8.getAbcPeriod(); int curHour = ag.s8.getAbcPeriod();
Serial.printf("Current config: %d (hours)\r\n", ag.s8.getAbcPeriod()); Serial.printf("Current config: %d (hours)\r\n", curHour);
if (curHour == newHour) { if (curHour == newHour) {
Serial.println("set 'abcDays' ignored"); Serial.println("set 'abcDays' ignored");
} else { } else {
@ -1783,11 +1802,6 @@ static void updateServerConfiguration(void) {
Serial.println("Connect to new mqtt broker failed"); Serial.println("Connect to new mqtt broker failed");
} }
} }
if (mdnsModelName != agServer.getModelName()) {
MDNS.addServiceTxt("http", "_tcp", "model", agServer.getModelName());
mdnsModelName = agServer.getModelName();
}
} }
} }
@ -2187,11 +2201,13 @@ static void tvocUpdate(void) {
tvocIndex = ag.sgp41.getTvocIndex(); tvocIndex = ag.sgp41.getTvocIndex();
tvocRawIndex = ag.sgp41.getTvocRaw(); tvocRawIndex = ag.sgp41.getTvocRaw();
noxIndex = ag.sgp41.getNoxIndex(); noxIndex = ag.sgp41.getNoxIndex();
noxRawIndex = ag.sgp41.getNoxRaw();
Serial.println(); 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);
Serial.printf(" NOx raw index: %d\r\n", noxRawIndex);
} }
/** /**

View File

@ -77,9 +77,9 @@ enum {
APP_SM_SERVER_LOST, /** Connected to WiFi network but the server cannot be APP_SM_SERVER_LOST, /** Connected to WiFi network but the server cannot be
reached through the internet, e.g. blocked by firewall reached through the internet, e.g. blocked by firewall
*/ */
APP_SM_SENSOR_CONFIG_FAILED, /** Server is reachabFirmware nodele but there is some APP_SM_SENSOR_CONFIG_FAILED, /** Server is reachabFirmware nodele but there is
configuration issue to be fixed on the server some configuration issue to be fixed on the
side */ server side */
APP_SM_NORMAL, APP_SM_NORMAL,
}; };
@ -666,7 +666,8 @@ WebServer webServer;
int tvocIndex = -1; int tvocIndex = -1;
int tvocRawIndex = -1; int tvocRawIndex = -1;
int noxIndex = -1; int noxIndex = -1;
int co2Ppm = 0; int noxRawIndex = -1;
int co2Ppm = -1;
int pm25_1 = -1; int pm25_1 = -1;
int pm01_1 = -1; int pm01_1 = -1;
@ -727,6 +728,7 @@ bool hasSensorPMS2 = true;
bool hasSensorSGP = true; bool hasSensorSGP = true;
uint32_t factoryBtnPressTime = 0; uint32_t factoryBtnPressTime = 0;
String mdnsModelName = ""; String mdnsModelName = "";
int getCO2FailCount = 0;
AgSchedule configSchedule(SERVER_CONFIG_UPDATE_INTERVAL, AgSchedule configSchedule(SERVER_CONFIG_UPDATE_INTERVAL,
updateServerConfiguration); updateServerConfiguration);
AgSchedule serverSchedule(SERVER_SYNC_INTERVAL, sendDataToServer); AgSchedule serverSchedule(SERVER_SYNC_INTERVAL, sendDataToServer);
@ -906,23 +908,42 @@ void boardInit(void) {
failedHandler("Init I2C failed"); failedHandler("Init I2C failed");
} }
Serial.println("Firmware Version: "+ag.getVersion()); Serial.println("Firmware Version: " + ag.getVersion());
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 */
/**
* Serial1 and Serial0 is use for connect S8 and PM sensor or both PM
*/
bool serial1Available = true;
bool serial0Available = true;
if (ag.s8.begin(Serial1) == false) { if (ag.s8.begin(Serial1) == false) {
hasSensorS8 = false;
Serial.println("CO2 S8 sensor not found");
Serial.println("Can not detect S8 run mode 'PPT'");
fw_mode = FW_MODE_PPT;
/** De-initialize Serial1 */
Serial1.end(); Serial1.end();
delay(200);
Serial.println("Can not detect S8 on Serial1, try on Serial0");
/** Check on other port */
if (ag.s8.begin(Serial0) == false) {
hasSensorS8 = false;
Serial.println("CO2 S8 sensor not found");
Serial.println("Can not detect S8 run mode 'PPT'");
fw_mode = FW_MODE_PPT;
Serial0.end();
delay(200);
} else {
Serial.println("Found S8 on Serial0");
serial0Available = false;
}
} else {
Serial.println("Found S8 on Serial1");
serial1Available = false;
} }
if (ag.sgp41.begin(Wire) == false) { if (ag.sgp41.begin(Wire) == false) {
hasSensorSGP = false; hasSensorSGP = false;
Serial.println("SGP sensor not found"); Serial.println("SGP sensor not found");
@ -931,20 +952,43 @@ void boardInit(void) {
fw_mode = FW_MODE_PP; fw_mode = FW_MODE_PP;
} }
if (ag.pms5003t_1.begin(Serial0) == false) { /** Try to find the PMS on other difference port with S8 */
hasSensorPMS1 = false; if (fw_mode == FW_MODE_PST) {
Serial.println("PMS1 sensor not found"); bool pmInitSuccess = false;
if (serial0Available) {
if (ag.pms5003t_2.begin(Serial1) == false) { if (ag.pms5003t_1.begin(Serial0) == false) {
hasSensorPMS2 = false; hasSensorPMS1 = false;
Serial.println("PMS2 sensor not found"); Serial.println("PMS1 sensor not found");
} else {
serial0Available = false;
pmInitSuccess = true;
Serial.println("Found PMS 1 on Serial0");
}
}
if (pmInitSuccess == false) {
if (serial1Available) {
if (ag.pms5003t_1.begin(Serial1) == false) {
hasSensorPMS1 = false;
Serial.println("PMS1 sensor not found");
} else {
serial1Available = false;
Serial.println("Found PMS 1 on Serial1");
}
}
}
hasSensorPMS2 = false; // Disable PM2
} else {
if (ag.pms5003t_1.begin(Serial0) == false) {
hasSensorPMS1 = false;
Serial.println("PMS1 sensor not found");
} else {
Serial.println("Found PMS 1 on Serial0");
} }
}
if (fw_mode != FW_MODE_PST) {
if (ag.pms5003t_2.begin(Serial1) == false) { if (ag.pms5003t_2.begin(Serial1) == false) {
hasSensorPMS2 = false; hasSensorPMS2 = false;
Serial.println("PMS2 sensor not found"); Serial.println("PMS2 sensor not found");
} else {
Serial.println("Found PMS 2 on Serial1");
} }
} }
@ -1019,11 +1063,13 @@ static void tvocUpdate(void) {
tvocIndex = ag.sgp41.getTvocIndex(); tvocIndex = ag.sgp41.getTvocIndex();
tvocRawIndex = ag.sgp41.getTvocRaw(); tvocRawIndex = ag.sgp41.getTvocRaw();
noxIndex = ag.sgp41.getNoxIndex(); noxIndex = ag.sgp41.getNoxIndex();
noxRawIndex = ag.sgp41.getNoxRaw();
Serial.println(); 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);
Serial.printf(" NOx raw index: %d\r\n", noxRawIndex);
} }
/** /**
@ -1139,8 +1185,18 @@ static void pmUpdate(void) {
} }
static void co2Update(void) { static void co2Update(void) {
co2Ppm = ag.s8.getCo2(); int value = ag.s8.getCo2();
Serial.printf("CO2 index: %d\r\n", co2Ppm); if (value >= 0) {
co2Ppm = value;
getCO2FailCount = 0;
Serial.printf("CO2 index: %d\r\n", co2Ppm);
} else {
getCO2FailCount++;
Serial.printf("Get CO2 failed: %d\r\n", getCO2FailCount);
if (getCO2FailCount >= 3) {
co2Ppm = -1;
}
}
} }
static void updateServerConfiguration(void) { static void updateServerConfiguration(void) {
@ -1161,7 +1217,7 @@ static void updateServerConfiguration(void) {
Serial.printf("abcDays config: %d days(%d hours)\r\n", Serial.printf("abcDays config: %d days(%d hours)\r\n",
agServer.getCo2AbcDaysConfig(), newHour); agServer.getCo2AbcDaysConfig(), newHour);
int curHour = ag.s8.getAbcPeriod(); int curHour = ag.s8.getAbcPeriod();
Serial.printf("Current config: %d (hours)\r\n", ag.s8.getAbcPeriod()); Serial.printf("Current config: %d (hours)\r\n", curHour);
if (curHour == newHour) { if (curHour == newHour) {
Serial.println("set 'abcDays' ignored"); Serial.println("set 'abcDays' ignored");
} else { } else {
@ -1192,11 +1248,6 @@ static void updateServerConfiguration(void) {
Serial.println("Connect to new mqtt broker failed"); Serial.println("Connect to new mqtt broker failed");
} }
} }
if (mdnsModelName != agServer.getModelName()) {
MDNS.addServiceTxt("http", "_tcp", "model", agServer.getModelName());
mdnsModelName = agServer.getModelName();
}
} }
} }
@ -1339,10 +1390,7 @@ static void webServerInit(void) {
webServer.on("/measures/current", HTTP_GET, webServerMeasureCurrentGet); webServer.on("/measures/current", HTTP_GET, webServerMeasureCurrentGet);
webServer.begin(); webServer.begin();
MDNS.addService("http", "tcp", 80); MDNS.addService("http", "tcp", 80);
if (mdnsModelName != agServer.getModelName()) { MDNS.addServiceTxt("http", "_tcp", "model", ag.getBoardName());
MDNS.addServiceTxt("http", "_tcp", "model", agServer.getModelName());
mdnsModelName = agServer.getModelName();
}
MDNS.addServiceTxt("http", "_tcp", "serialno", getDevId()); MDNS.addServiceTxt("http", "_tcp", "serialno", getDevId());
MDNS.addServiceTxt("http", "_tcp", "fw_ver", ag.getVersion()); MDNS.addServiceTxt("http", "_tcp", "fw_ver", ag.getVersion());
@ -1420,6 +1468,9 @@ static String getServerSyncData(bool localServer) {
if (noxIndex >= 0) { if (noxIndex >= 0) {
root["nox_index"] = noxIndex; root["nox_index"] = noxIndex;
} }
if (noxRawIndex >= 0) {
root["nox_raw"] = noxRawIndex;
}
} }
} }

View File

@ -25,7 +25,7 @@ void setup()
if (ag.s8.begin(&Serial) == false) if (ag.s8.begin(&Serial) == false)
{ {
#else #else
if (ag.s8.begin(Serial1) == false) if (ag.s8.begin(Serial0) == false)
{ {
#endif #endif
failedHandler("SenseAir S8 init failed"); failedHandler("SenseAir S8 init failed");

View File

@ -79,19 +79,21 @@ bool PMS5003T::begin(void) {
#if ARDUINO_USB_CDC_ON_BOOT // Serial used for USB CDC #if ARDUINO_USB_CDC_ON_BOOT // Serial used for USB CDC
if (this->_serial == &Serial0) { if (this->_serial == &Serial0) {
AgLog("Init Serial0");
_serial->begin(9600, SERIAL_8N1);
#else #else
if (this->_serial == &Serial) { if (this->_serial == &Serial) {
#endif
AgLog("Init Serial"); AgLog("Init Serial");
this->_serial->begin(9600, SERIAL_8N1, bsp->Pms5003.uart_rx_pin, this->_serial->begin(9600, SERIAL_8N1, bsp->Pms5003.uart_rx_pin,
bsp->Pms5003.uart_tx_pin); bsp->Pms5003.uart_tx_pin);
#endif
} else { } else {
/** Share with sensor air s8*/
if (bsp->SenseAirS8.supported == false) { if (bsp->SenseAirS8.supported == false) {
AgLog("Board [%d] PMS5003T_2 not supported", this->_boardDef); AgLog("Board [%d] PMS5003T_2 not supported", this->_boardDef);
return false; return false;
} }
/** Share with sensor air s8*/
AgLog("Init Serialx"); AgLog("Init Serialx");
this->_serial->begin(9600, SERIAL_8N1, bsp->SenseAirS8.uart_rx_pin, this->_serial->begin(9600, SERIAL_8N1, bsp->SenseAirS8.uart_rx_pin,
bsp->SenseAirS8.uart_tx_pin); bsp->SenseAirS8.uart_tx_pin);

View File

@ -228,7 +228,7 @@ int16_t S8::getCo2(void) {
return -1; return -1;
} }
int16_t co2 = 0; int16_t co2 = -1;
// Ask CO2 value // Ask CO2 value
sendCommand(MODBUS_FUNC_READ_INPUT_REGISTERS, MODBUS_IR4, 0x0001); sendCommand(MODBUS_FUNC_READ_INPUT_REGISTERS, MODBUS_IR4, 0x0001);
@ -649,11 +649,25 @@ bool S8::init(int txPin, int rxPin, uint32_t baud) {
uart->begin(baud); uart->begin(baud);
this->_uartStream = uart; this->_uartStream = uart;
#else #else
#if ARDUINO_USB_CDC_ON_BOOT
/** The 'Serial0' can ont configure tx, rx pin, only use as default */
if (_serial == &Serial0) {
AgLog("Init on 'Serial0'");
_serial->begin(baud, SERIAL_8N1);
} else {
AgLog("Init on 'Serialx'");
this->_serial->begin(baud, SERIAL_8N1, rxPin, txPin);
}
this->_uartStream = this->_serial;
#else
AgLog("Init on 'Serialx'");
this->_serial->begin(baud, SERIAL_8N1, rxPin, txPin); this->_serial->begin(baud, SERIAL_8N1, rxPin, txPin);
this->_uartStream = this->_serial; this->_uartStream = this->_serial;
#endif
#endif #endif
/** Check communication by get firmware version */ /** Check communication by get firmware version */
delay(100);
char fwVers[11]; char fwVers[11];
this->_isBegin = true; this->_isBegin = true;
this->getFirmwareVersion(fwVers); this->getFirmwareVersion(fwVers);
@ -712,7 +726,7 @@ uint8_t S8::uartReadBytes(uint8_t max_bytes, uint32_t timeout_ms) {
#if defined(ESP32) #if defined(ESP32)
// Relax 5ms to avoid watchdog reset // Relax 5ms to avoid watchdog reset
vTaskDelay(pdMS_TO_TICKS(5)); vTaskDelay(pdMS_TO_TICKS(1));
#endif #endif
} }
return nb; return nb;

View File

@ -91,7 +91,7 @@ void Sgp41::handle(void) {
if (getRawSignal(srawVoc, srawNox)) { if (getRawSignal(srawVoc, srawNox)) {
nox = noxAlgorithm()->process(srawNox); nox = noxAlgorithm()->process(srawNox);
tvoc = vocAlgorithm()->process(srawVoc); tvoc = vocAlgorithm()->process(srawVoc);
AgLog("Polling SGP41 success: tvoc: %d, nox: %d", tvoc, nox); // AgLog("Polling SGP41 success: tvoc: %d, nox: %d", tvoc, nox);
} }
} }
} }
@ -121,9 +121,10 @@ void Sgp41::_handle(void) {
vTaskDelay(pdMS_TO_TICKS(1000)); vTaskDelay(pdMS_TO_TICKS(1000));
if (getRawSignal(srawVoc, srawNox)) { if (getRawSignal(srawVoc, srawNox)) {
tvocRaw = srawVoc; tvocRaw = srawVoc;
noxRaw = srawNox;
nox = noxAlgorithm()->process(srawNox); nox = noxAlgorithm()->process(srawNox);
tvoc = vocAlgorithm()->process(srawVoc); tvoc = vocAlgorithm()->process(srawVoc);
AgLog("Polling SGP41 success: tvoc: %d, nox: %d", tvoc, nox); // AgLog("Polling SGP41 success: tvoc: %d, nox: %d", tvoc, nox);
} }
} }
} }
@ -249,3 +250,10 @@ bool Sgp41::_noxConditioning(void) {
* @return int * @return int
*/ */
int Sgp41::getTvocRaw(void) { return tvocRaw; } int Sgp41::getTvocRaw(void) { return tvocRaw; }
/**
* @brief Get NOX raw value
*
* @return int
*/
int Sgp41::getNoxRaw(void) { return noxRaw; }

View File

@ -24,6 +24,7 @@ public:
int getTvocIndex(void); int getTvocIndex(void);
int getNoxIndex(void); int getNoxIndex(void);
int getTvocRaw(void); int getTvocRaw(void);
int getNoxRaw(void);
private: private:
bool onConditioning = true; bool onConditioning = true;
@ -39,6 +40,7 @@ private:
int tvoc = 0; int tvoc = 0;
int tvocRaw; int tvocRaw;
int nox = 0; int nox = 0;
int noxRaw;
#if defined(ESP8266) #if defined(ESP8266)
uint32_t conditioningPeriod; uint32_t conditioningPeriod;
uint8_t conditioningCount; uint8_t conditioningCount;