33class SGP41 :
public Element {
38 vocchannel->setDefaultUnitAfterValue(
"");
39 vocchannel->setInitialCaption(
"VOC index");
40 vocchannel->getChannel()->setDefaultIcon(8);
41 vocchannel->setDefaultValuePrecision(1);
44 noxchannel->setDefaultUnitAfterValue(
"");
45 noxchannel->setInitialCaption(
"NOx index");
46 noxchannel->getChannel()->setDefaultIcon(8);
47 noxchannel->setDefaultValuePrecision(1);
64 if (millis() - lastReadTime > 1000) {
65 readValuesFromDevice();
66 lastReadTime = millis();
71 void readValuesFromDevice() {
73 float temperature = TEMPERATURE_NOT_AVAILABLE;
74 float humidity = HUMIDITY_NOT_AVAILABLE;
76 temperature = th->getChannel()->getLastTemperature();
77 humidity = th->getChannel()->getValueDoubleSecond();
82 if (temperature != TEMPERATURE_NOT_AVAILABLE) {
83 compensationT =
static_cast<uint16_t
>((temperature + 45) * 65535 / 175);
85 compensationT = defaultCompenstaionT;
88 if (humidity != HUMIDITY_NOT_AVAILABLE) {
89 compensationRh =
static_cast<uint16_t
>(humidity * 65535 / 100);
91 compensationRh = defaultCompenstaionRh;
94 if (skipFirstReadingsCounter > 0) {
95 error = sgp.executeConditioning(compensationRh, compensationT, srawVoc);
96 skipFirstReadingsCounter--;
98 error = sgp.measureRawSignals(compensationRh, compensationT, srawVoc,
104 if (retryCount > 10) {
105 vocchannel->setValue(NAN);
106 noxchannel->setValue(NAN);
110 vocchannel->setValue(srawVoc);
111 noxchannel->setValue(srawNox);
116 uint16_t defaultCompenstaionRh = 0x8000;
117 uint16_t defaultCompenstaionT = 0x6666;
118 uint16_t compensationRh = 0;
119 uint16_t compensationT = 0;
120 int8_t retryCount = 0;
121 ::SensirionI2CSgp41 sgp;
122 GeneralPurposeMeasurement *vocchannel =
nullptr;
123 GeneralPurposeMeasurement *noxchannel =
nullptr;
124 ThermHygroMeter *th =
nullptr;
125 uint32_t lastReadTime = 0;
126 int skipFirstReadingsCounter = 10;