Bugfix
- SHT enable/disable crash
This commit is contained in:
parent
9e446210fb
commit
bf6a18a414
@ -22,7 +22,7 @@ class ShtUsermod : public Usermod
|
|||||||
bool haMqttDiscoveryDone = false; // Remembers if we already published the HA discovery topics
|
bool haMqttDiscoveryDone = false; // Remembers if we already published the HA discovery topics
|
||||||
|
|
||||||
// SHT vars
|
// SHT vars
|
||||||
SHT *shtTempHumidSensor; // Instance of SHT lib
|
SHT *shtTempHumidSensor = nullptr; // Instance of SHT lib
|
||||||
byte shtType = 0; // SHT sensor type to be used. Default: SHT30
|
byte shtType = 0; // SHT sensor type to be used. Default: SHT30
|
||||||
byte unitOfTemp = 0; // Temperature unit to be used. Default: Celsius (0 = Celsius, 1 = Fahrenheit)
|
byte unitOfTemp = 0; // Temperature unit to be used. Default: Celsius (0 = Celsius, 1 = Fahrenheit)
|
||||||
bool shtInitDone = false; // Remembers if SHT sensor has been initialised
|
bool shtInitDone = false; // Remembers if SHT sensor has been initialised
|
||||||
@ -37,7 +37,7 @@ class ShtUsermod : public Usermod
|
|||||||
void initShtTempHumiditySensor();
|
void initShtTempHumiditySensor();
|
||||||
void cleanupShtTempHumiditySensor();
|
void cleanupShtTempHumiditySensor();
|
||||||
void cleanup();
|
void cleanup();
|
||||||
bool isShtReady();
|
inline bool isShtReady() { return shtInitDone; } // Checks if the SHT sensor has been initialised.
|
||||||
|
|
||||||
void publishTemperatureAndHumidityViaMqtt();
|
void publishTemperatureAndHumidityViaMqtt();
|
||||||
void publishHomeAssistantAutodiscovery();
|
void publishHomeAssistantAutodiscovery();
|
||||||
@ -113,8 +113,11 @@ void ShtUsermod::initShtTempHumiditySensor()
|
|||||||
*/
|
*/
|
||||||
void ShtUsermod::cleanupShtTempHumiditySensor()
|
void ShtUsermod::cleanupShtTempHumiditySensor()
|
||||||
{
|
{
|
||||||
if (isShtReady()) shtTempHumidSensor->reset();
|
if (isShtReady()) {
|
||||||
delete shtTempHumidSensor;
|
shtTempHumidSensor->reset();
|
||||||
|
delete shtTempHumidSensor;
|
||||||
|
shtTempHumidSensor = nullptr;
|
||||||
|
}
|
||||||
shtInitDone = false;
|
shtInitDone = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -139,16 +142,6 @@ void ShtUsermod::cleanup()
|
|||||||
enabled = false;
|
enabled = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks if the SHT sensor has been initialised.
|
|
||||||
*
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
bool ShtUsermod::isShtReady()
|
|
||||||
{
|
|
||||||
return shtInitDone;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Publish temperature and humidity to WLED device topic.
|
* Publish temperature and humidity to WLED device topic.
|
||||||
*
|
*
|
||||||
@ -463,7 +456,19 @@ void ShtUsermod::addToJsonInfo(JsonObject& root)
|
|||||||
jsonHumidity.add(F(" RH"));
|
jsonHumidity.add(F(" RH"));
|
||||||
|
|
||||||
jsonTemp.add(getTemperature());
|
jsonTemp.add(getTemperature());
|
||||||
jsonTemp.add(unitOfTemp ? "°F" : "°C");
|
jsonTemp.add(getUnitString());
|
||||||
|
|
||||||
|
// sensor object
|
||||||
|
JsonObject sensor = root[F("sensor")];
|
||||||
|
if (sensor.isNull()) sensor = root.createNestedObject(F("sensor"));
|
||||||
|
|
||||||
|
jsonTemp = sensor.createNestedArray(F("temp"));
|
||||||
|
jsonTemp.add(getTemperature());
|
||||||
|
jsonTemp.add(getUnitString());
|
||||||
|
|
||||||
|
jsonHumidity = sensor.createNestedArray(F("humidity"));
|
||||||
|
jsonHumidity.add(getHumidity());
|
||||||
|
jsonHumidity.add(F(" RH"));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user