mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-17 21:29:52 +03:00
Merge pull request #2821 from MichaelDvP/dev
mqtt publish on change: wait for queue empty
This commit is contained in:
@@ -600,7 +600,7 @@ bool AnalogSensor::update(uint8_t gpio, const char * org_name, double offset, do
|
|||||||
|
|
||||||
// check to see if values have been updated
|
// check to see if values have been updated
|
||||||
bool AnalogSensor::updated_values() {
|
bool AnalogSensor::updated_values() {
|
||||||
if (changed_) {
|
if (changed_ && Mqtt::publish_queued() == 0) {
|
||||||
changed_ = false;
|
changed_ = false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1191,16 +1191,20 @@ bool EMSESP::process_telegram(std::shared_ptr<const Telegram> telegram) {
|
|||||||
found_device = emsdevice.get();
|
found_device = emsdevice.get();
|
||||||
if (emsdevice->handle_telegram(telegram)) {
|
if (emsdevice->handle_telegram(telegram)) {
|
||||||
telegram_found = true;
|
telegram_found = true;
|
||||||
if (Mqtt::connected()
|
if (Mqtt::connected()) {
|
||||||
&& ((mqtt_.get_publish_onchange(found_device->device_type()) && found_device->has_update())
|
// publish device data if it was a validate after write
|
||||||
|| (telegram->type_id == publish_id_ && telegram->dest == EMSbus::ems_bus_id()))) {
|
if (telegram->type_id == publish_id_ && telegram->dest == EMSbus::ems_bus_id()) {
|
||||||
if (telegram->type_id == publish_id_) {
|
|
||||||
publish_id_ = 0;
|
publish_id_ = 0;
|
||||||
}
|
found_device->has_update(false); // reset flag
|
||||||
found_device->has_update(false); // reset flag
|
|
||||||
if (!Mqtt::publish_single()) {
|
|
||||||
publish_device_values(found_device->device_type()); // publish to MQTT if we explicitly have too
|
publish_device_values(found_device->device_type()); // publish to MQTT if we explicitly have too
|
||||||
}
|
}
|
||||||
|
// auto publish: timeinterval 0 and publish single not set, only if queue is empty
|
||||||
|
else if (mqtt_.get_publish_onchange(found_device->device_type()) && found_device->has_update() && mqtt_.publish_queued() == 0) {
|
||||||
|
found_device->has_update(false); // reset flag
|
||||||
|
if (!Mqtt::publish_single()) {
|
||||||
|
publish_device_values(found_device->device_type());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break; // remove this to handle same telegrams on multiple devices
|
break; // remove this to handle same telegrams on multiple devices
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -370,7 +370,7 @@ bool TemperatureSensor::update(const char * id, const char * name, int16_t offse
|
|||||||
|
|
||||||
// check to see if values have been updated
|
// check to see if values have been updated
|
||||||
bool TemperatureSensor::updated_values() {
|
bool TemperatureSensor::updated_values() {
|
||||||
if (changed_) {
|
if (changed_ && Mqtt::publish_queued() == 0) {
|
||||||
changed_ = false;
|
changed_ = false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user