diff --git a/src/ebusd/knxhandler.cpp b/src/ebusd/knxhandler.cpp index a777df4e..da2690e1 100644 --- a/src/ebusd/knxhandler.cpp +++ b/src/ebusd/knxhandler.cpp @@ -899,6 +899,7 @@ void KnxHandler::run() { if (!m_updatedMessages.empty()) { m_messages->lock(); if (m_con->isConnected()) { + time_t maxUpdates = 0; for (auto it = m_updatedMessages.begin(); it != m_updatedMessages.end(); ) { const vector* messages = m_messages->getByKey(it->first); if (!messages) { @@ -906,16 +907,20 @@ void KnxHandler::run() { continue; } for (const auto& message : *messages) { - if (message->getLastChangeTime() <= 0) { + time_t changeTime = message->getLastChangeTime(); + if (changeTime <= 0) { continue; } + if (changeTime > lastUpdates && changeTime > maxUpdates) { + maxUpdates = changeTime; + } const auto mit = m_subscribedMessages.find(message->getKey()); if (mit == m_subscribedMessages.cend()) { continue; } if (!(message->getDataHandlerState()&2)) { message->setDataHandlerState(2, true); // first update still needed - } else if (message->getLastChangeTime() <= lastUpdates) { + } else if (changeTime <= lastUpdates) { continue; } for (auto destFlags : mit->second) { @@ -936,7 +941,7 @@ void KnxHandler::run() { } it = m_updatedMessages.erase(it); } - time(&lastUpdates); + lastUpdates = maxUpdates == 0 || lastUpdates > maxUpdates ? now : maxUpdates + 1; } else { m_updatedMessages.clear(); } diff --git a/src/ebusd/mqtthandler.cpp b/src/ebusd/mqtthandler.cpp index 5412b10c..6e1f17c1 100755 --- a/src/ebusd/mqtthandler.cpp +++ b/src/ebusd/mqtthandler.cpp @@ -1068,22 +1068,27 @@ void MqttHandler::run() { if (!m_updatedMessages.empty()) { m_messages->lock(); if (m_connected) { + time_t maxUpdates = 0; for (auto it = m_updatedMessages.begin(); it != m_updatedMessages.end(); ) { const vector* messages = m_messages->getByKey(it->first); if (messages) { for (const auto& message : *messages) { - if (message->getLastChangeTime() > 0 && message->isAvailable() - && (!g_onlyChanges || message->getLastChangeTime() > lastUpdates)) { + time_t changeTime = message->getLastChangeTime(); + if (changeTime > 0 && message->isAvailable() + && (!g_onlyChanges || changeTime > lastUpdates)) { updates.str(""); updates.clear(); updates << dec; publishMessage(message, &updates); } + if (changeTime > lastUpdates && changeTime > maxUpdates) { + maxUpdates = changeTime; + } } } it = m_updatedMessages.erase(it); } - time(&lastUpdates); + lastUpdates = maxUpdates == 0 || lastUpdates > maxUpdates ? now : maxUpdates + 1; } else { m_updatedMessages.clear(); }