Files
OpenMQTTGateway/main/sensorSHTC3.cpp
Ryan Powell 585df9a420 [SYS] Update arduino core to 3.1.1 + refactor ino to cpp (#2177)
* Update arduino core to 3.1.1

* Fix Blufi build

* Update arduinojson, fix build errors with idf

* Fix narrowing

* fix RF builds

* WIP-Convert ino files to cpp

* Fix pilight build

* Fix Somfy actuator build.

* Update esp32dev-rf partition

* Fix Weatherstation build

* Fix GFSunInverter build

* Fix esp32dev-ir build

* Fix ble-aws build

* Fix eth builds

* Fix m5Stack missing pins_arduino.h

* Fix build errors for M5 stack/tough, others are upstream issues.

* Fix RTL 433 build - remaining errors are from radolib

* Fix nodemcu build

* fix 2g builds

* Fix serial build

* Fix actuator on off builds

* Fix SSD1306 build - remaining errors are from radiolib

* Fix multiple definition of OTAserver_cert

* Fix nodemcu rf2 build

* Fix ADC builds

* Fix sensor builds

* Fix LORA builds

* Fix multi-receiver builds - remaining errors are in radiolib

* Fix fastled builds

* Fix theegns board builds

* Fix broker builds

* Update fastled - old version failed all-test build

* Fix RN8209 builds

* Fix max temp actuator builds

* Fix PWM builds

* Fix C37 sensor builds

* Fix HTU21 builds

* Fix INA266 builds

* Fix undefined variables in mqtt discovery

* Fix webui build

* Fix fastled invalid pin error

* Fix wifi manual setup builds

* Fix onewire/all-test build - bin too big error remaining

* Fix theengs plug build

* Fix rfbridge builds

* Fix blufi builds

* Fix undefined functions in serial

* Fix preprocessor definition checks

* Set IDF log level to erre

* Add delay in loop to prevent watchdog timeout

* Use xTaskCreateUniveral to support single core processors

* Remove old HTTPUpdate files - upsteam fixed.

* Cleanup and move common declarations to header file

* Use custom partiton table to fix builds where bin is too large

* Update M5StickC - fixs esp32-m5stick-c-ble build

* Revert to Arduino core 2.x for builds with incompatible libs

* Remove "Z" from file names and rename omg_common to TheengsCommon

* Fix gateway name when using MAC with new Arduino core

* Update IDF config to reduce loop task stack use

* Update esp-nimble-cpp version, corrects BLE uppercase ID's

* Update wifi manager to fix watchdog timeout error
2025-05-06 19:35:50 -05:00

77 lines
2.3 KiB
C++

#include "User_config.h"
#ifdef ZsensorSHTC3
# include <SparkFun_SHTC3.h>
# include "TheengsCommon.h"
SHTC3 mySHTC3;
//Time used to wait for an interval before resending temp and hum
unsigned long timedht = 0;
void errorDecoder(SHTC3_Status_TypeDef message);
void errorDecoder(SHTC3_Status_TypeDef message) // The errorDecoder function prints "SHTC3_Status_TypeDef" resultsin a human-friendly way
{
switch (message) {
case SHTC3_Status_Nominal:
Log.notice(F("Nominal"));
break;
case SHTC3_Status_Error:
Log.error(F("Error"));
break;
case SHTC3_Status_CRC_Fail:
Log.error(F("CRC Fail"));
break;
default:
Log.error(F("Unknown return code"));
break;
}
}
void setupSHTC3() {
Wire.begin();
errorDecoder(mySHTC3.begin()); // To start the sensor you must call "begin()", the default settings use Wire (default Arduino I2C port)
}
void MeasureTempAndHum() {
if (millis() > (timedht + TimeBetweenReadingSHTC3)) { //retrieving value of temperature and humidity of the box from SHTC3 every xUL
timedht = millis();
static float persistedh;
static float persistedt;
SHTC3_Status_TypeDef result = mySHTC3.update();
if (mySHTC3.lastStatus == SHTC3_Status_Nominal) {
// Read temperature as Celsius (the default)
float t = mySHTC3.toDegC();
float h = mySHTC3.toPercent();
// Check if any reads failed and exit early (to try again).
if (isnan(h) || isnan(t)) {
Log.error(F("Failed to read from SHTC3 sensor!" CR));
} else {
Log.trace(F("Creating SHTC3 buffer" CR));
StaticJsonDocument<JSON_MSG_BUFFER> SHTC3dataBuffer;
JsonObject SHTC3data = SHTC3dataBuffer.to<JsonObject>();
if (h != persistedh || shtc3_always) {
SHTC3data["hum"] = (float)h;
} else {
Log.trace(F("Same hum don't send it" CR));
}
if (t != persistedt || shtc3_always) {
SHTC3data["tempc"] = (float)t;
SHTC3data["tempf"] = mySHTC3.toDegF();
} else {
Log.trace(F("Same temp don't send it" CR));
}
SHTC3data["origin"] = SHTC3TOPIC;
enqueueJsonObject(SHTC3data);
}
persistedh = h;
persistedt = t;
} else {
errorDecoder(mySHTC3.lastStatus);
Log.error(F("Failed to read from SHTC3 sensor!" CR));
}
}
}
#endif