added espasyncota lib
This commit is contained in:
+23
-10
@@ -37,7 +37,8 @@ void init_tsl()
|
||||
tslInitialized = tsl->begin(true);
|
||||
ESP_LOGI(TAG, "finished with %s", tslInitialized ? "true" : "false");
|
||||
|
||||
if (tslInitialized) {
|
||||
if (tslInitialized)
|
||||
{
|
||||
sensor_t sensor = tsl->getSensor();
|
||||
ESP_LOGI(TAG, "------------------------------------");
|
||||
ESP_LOGI(TAG, "Sensor: %s", sensor.name);
|
||||
@@ -72,44 +73,56 @@ void update_tsl()
|
||||
if (!config::enable_i2c.value() || !config::enable_tsl.value())
|
||||
return;
|
||||
|
||||
if (tslInitialized) {
|
||||
if (tslInitialized)
|
||||
{
|
||||
if (espchrono::ago(last_tsl2561_readout) < 5s)
|
||||
return;
|
||||
|
||||
last_tsl2561_readout = espchrono::millis_clock::now();
|
||||
|
||||
if (std::optional<sensors_event_t> event = tsl->getEvent()) {
|
||||
if (std::optional<sensors_event_t> event = tsl->getEvent())
|
||||
{
|
||||
/* Display the results (light is measured in lux) */
|
||||
if (event->light) {
|
||||
if (event->light)
|
||||
{
|
||||
TslValue tslValue {
|
||||
.timestamp = espchrono::millis_clock::now(),
|
||||
.lux = event->light
|
||||
};
|
||||
ESP_LOGI(TAG, "read tsl: %.1f lux", tslValue.lux);
|
||||
|
||||
if (mqttConnected) {
|
||||
if (mqttConnected)
|
||||
{
|
||||
if (!lastTslValue)
|
||||
mqttVerbosePub(config::topic_tsl2561_availability.value(), "online", 0, 1);
|
||||
if (!lastTslValue || espchrono::ago(last_tsl2561_lux_pub) >= config::valueUpdateInterval.value()) {
|
||||
if (!lastTslValue || espchrono::ago(last_tsl2561_lux_pub) >= config::valueUpdateInterval.value())
|
||||
{
|
||||
if (mqttVerbosePub(config::topic_tsl2561_lux.value(), fmt::format("{:.1f}", tslValue.lux), 0, 1) >= 0)
|
||||
last_tsl2561_lux_pub = espchrono::millis_clock::now();
|
||||
}
|
||||
}
|
||||
|
||||
lastTslValue = tslValue;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
/* If event.light = 0 lux the sensor is probably saturated
|
||||
* and no reliable data could be generated! */
|
||||
ESP_LOGW(TAG, "tsl sensor overload %f", event->light);
|
||||
goto tslOffline;
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
ESP_LOGW(TAG, "tsl failed");
|
||||
goto tslOffline;
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
tslOffline:
|
||||
if (lastTslValue && espchrono::ago(lastTslValue->timestamp) >= config::availableTimeoutTime.value()) {
|
||||
if (lastTslValue && espchrono::ago(lastTslValue->timestamp) >= config::availableTimeoutTime.value())
|
||||
{
|
||||
ESP_LOGW(TAG, "tsl timeouted");
|
||||
if (mqttConnected)
|
||||
mqttVerbosePub(config::topic_tsl2561_availability.value(), "offline", 0, 1);
|
||||
|
||||
Reference in New Issue
Block a user