Add parameter tvoc_raw for SGP41

This commit is contained in:
Phat Nguyen
2024-02-17 13:36:32 +07:00
parent b475c5c1ec
commit 23513cf88c
4 changed files with 28 additions and 6 deletions

View File

@ -446,6 +446,7 @@ static int ledSmState = APP_SM_NORMAL; /** Save display SM */
static int dispSmState = APP_SM_NORMAL; /** Save LED SM */
static int tvocIndex = -1;
static int tvocRawIndex = -1;
static int noxIndex = -1;
static int co2Ppm = -1;
static int pm25 = -1;
@ -1440,9 +1441,11 @@ static void updateDispLedBar(void) {
*/
static void tvocPoll(void) {
tvocIndex = ag.sgp41.getTvocIndex();
tvocRawIndex = ag.sgp41.getTvocRaw();
noxIndex = ag.sgp41.getNoxIndex();
Serial.printf("tvocIndexindex: %d\r\n", tvocIndex);
Serial.printf(" TVOC index: %d\r\n", tvocIndex);
Serial.printf("TVOC raw index: %d\r\n", tvocRawIndex);
Serial.printf(" NOx index: %d\r\n", noxIndex);
}
@ -1494,6 +1497,9 @@ static void sendDataToServer(void) {
if (tvocIndex >= 0) {
root["tvoc_index"] = tvocIndex;
}
if (tvocRawIndex >= 0) {
root["tvoc_raw"] = tvocRawIndex;
}
if (noxIndex >= 0) {
root["noxIndex"] = noxIndex;
}

View File

@ -408,6 +408,7 @@ static bool wifiHasConfig = false;
static String wifiSSID = "";
int tvocIndex = -1;
int tvocRawIndex = -1;
int noxIndex = -1;
int co2Ppm = 0;
@ -554,6 +555,9 @@ static void sendDataToServer(void) {
if (tvocIndex > 0) {
root["tvoc_index"] = loopCount;
}
if (tvocRawIndex >= 0) {
root["tvoc_raw"] = tvocRawIndex;
}
if (noxIndex > 0) {
root["nox_index"] = loopCount;
}
@ -769,9 +773,11 @@ static void updateWiFiConnect(void) {
*/
static void tvocPoll(void) {
tvocIndex = ag.sgp41.getTvocIndex();
tvocRawIndex = ag.sgp41.getTvocRaw();
noxIndex = ag.sgp41.getNoxIndex();
Serial.printf("tvocIndexindex: %d\r\n", tvocIndex);
Serial.printf(" TVOC index: %d\r\n", tvocIndex);
Serial.printf("TVOC raw index: %d\r\n", tvocRawIndex);
Serial.printf(" NOx index: %d\r\n", noxIndex);
}

View File

@ -120,6 +120,7 @@ void Sgp41::_handle(void) {
for (;;) {
vTaskDelay(pdMS_TO_TICKS(1000));
if (getRawSignal(srawVoc, srawNox)) {
tvocRaw = srawVoc;
nox = noxAlgorithm()->process(srawNox);
tvoc = vocAlgorithm()->process(srawVoc);
AgLog("Polling SGP41 success: tvoc: %d, nox: %d", tvoc, nox);
@ -241,3 +242,10 @@ bool Sgp41::_noxConditioning(void) {
err = sgpSensor()->executeConditioning(defaultRh, defaultT, srawVoc);
return (err == 0);
}
/**
* @brief Get TVOC raw value
*
* @return int
*/
int Sgp41::getTvocRaw(void) { return tvocRaw; }

View File

@ -23,6 +23,7 @@ public:
void end(void);
int getTvocIndex(void);
int getNoxIndex(void);
int getTvocRaw(void);
private:
bool onConditioning = true;
@ -36,6 +37,7 @@ private:
uint16_t defaultRh = 0x8000;
uint16_t defaultT = 0x6666;
int tvoc = 0;
int tvocRaw;
int nox = 0;
#if defined(ESP8266)
uint32_t conditioningPeriod;