diff --git a/include/MqttHandleInverter.h b/include/MqttHandleInverter.h index ee427503..e1b292e4 100644 --- a/include/MqttHandleInverter.h +++ b/include/MqttHandleInverter.h @@ -3,6 +3,7 @@ #include "Configuration.h" #include +#include #include class MqttHandleInverterClass { @@ -19,6 +20,8 @@ private: uint32_t _lastPublishStats[INV_MAX_COUNT]; uint32_t _lastPublish; + TimeoutHelper _statsTimeout; + FieldId_t _publishFields[14] = { FLD_UDC, FLD_IDC, diff --git a/src/MqttHandleInverter.cpp b/src/MqttHandleInverter.cpp index c9621e33..9ca3679a 100644 --- a/src/MqttHandleInverter.cpp +++ b/src/MqttHandleInverter.cpp @@ -14,6 +14,8 @@ #define TOPIC_SUB_POWER "power" #define TOPIC_SUB_RESTART "restart" +#define PUBLISH_MAX_INTERVAL 60000 + MqttHandleInverterClass MqttHandleInverter; void MqttHandleInverterClass::init() @@ -92,9 +94,13 @@ void MqttHandleInverterClass::loop() } uint32_t lastUpdate = inv->Statistics()->getLastUpdate(); - if (lastUpdate > 0 && lastUpdate != _lastPublishStats[i]) { + if (lastUpdate > 0 && (lastUpdate != _lastPublishStats[i] || (inv->getZeroValuesIfUnreachable() && _statsTimeout.occured()))) { _lastPublishStats[i] = lastUpdate; + // At first a change of the stats have to occour. Then the stats + // are published on every change or every 60 seconds + _statsTimeout.set(PUBLISH_MAX_INTERVAL); + // Loop all channels for (auto& t : inv->Statistics()->getChannelTypes()) { for (auto& c : inv->Statistics()->getChannelsByType(t)) {