Publish mqtt string stats values periodically if they are set to zero if unreachable
This commit is contained in:
parent
abf95634db
commit
7d90937d0f
@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
#include "Configuration.h"
|
#include "Configuration.h"
|
||||||
#include <Hoymiles.h>
|
#include <Hoymiles.h>
|
||||||
|
#include <TimeoutHelper.h>
|
||||||
#include <espMqttClient.h>
|
#include <espMqttClient.h>
|
||||||
|
|
||||||
class MqttHandleInverterClass {
|
class MqttHandleInverterClass {
|
||||||
@ -19,6 +20,8 @@ private:
|
|||||||
uint32_t _lastPublishStats[INV_MAX_COUNT];
|
uint32_t _lastPublishStats[INV_MAX_COUNT];
|
||||||
uint32_t _lastPublish;
|
uint32_t _lastPublish;
|
||||||
|
|
||||||
|
TimeoutHelper _statsTimeout;
|
||||||
|
|
||||||
FieldId_t _publishFields[14] = {
|
FieldId_t _publishFields[14] = {
|
||||||
FLD_UDC,
|
FLD_UDC,
|
||||||
FLD_IDC,
|
FLD_IDC,
|
||||||
|
|||||||
@ -14,6 +14,8 @@
|
|||||||
#define TOPIC_SUB_POWER "power"
|
#define TOPIC_SUB_POWER "power"
|
||||||
#define TOPIC_SUB_RESTART "restart"
|
#define TOPIC_SUB_RESTART "restart"
|
||||||
|
|
||||||
|
#define PUBLISH_MAX_INTERVAL 60000
|
||||||
|
|
||||||
MqttHandleInverterClass MqttHandleInverter;
|
MqttHandleInverterClass MqttHandleInverter;
|
||||||
|
|
||||||
void MqttHandleInverterClass::init()
|
void MqttHandleInverterClass::init()
|
||||||
@ -92,9 +94,13 @@ void MqttHandleInverterClass::loop()
|
|||||||
}
|
}
|
||||||
|
|
||||||
uint32_t lastUpdate = inv->Statistics()->getLastUpdate();
|
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;
|
_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
|
// Loop all channels
|
||||||
for (auto& t : inv->Statistics()->getChannelTypes()) {
|
for (auto& t : inv->Statistics()->getChannelTypes()) {
|
||||||
for (auto& c : inv->Statistics()->getChannelsByType(t)) {
|
for (auto& c : inv->Statistics()->getChannelsByType(t)) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user