Skip to content

Commit

Permalink
Fix #1335: Only the first inverter was set to zero at midnight via mqtt
Browse files Browse the repository at this point in the history
  • Loading branch information
tbnobody committed Sep 13, 2023
1 parent a0f9d22 commit a974e21
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 9 deletions.
2 changes: 0 additions & 2 deletions include/MqttHandleInverter.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ class MqttHandleInverterClass {
uint32_t _lastPublishStats[INV_MAX_COUNT];
uint32_t _lastPublish;

TimeoutHelper _statsTimeout;

FieldId_t _publishFields[14] = {
FLD_UDC,
FLD_IDC,
Expand Down
17 changes: 17 additions & 0 deletions lib/Hoymiles/src/parser/StatisticsParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,22 @@ void StatisticsParser::zeroDailyData()
zeroFields(dailyProductionFields);
}

void StatisticsParser::setLastUpdate(uint32_t lastUpdate)
{
Parser::setLastUpdate(lastUpdate);
setLastUpdateFromInternal(lastUpdate);
}

uint32_t StatisticsParser::getLastUpdateFromInternal()
{
return _lastUpdateFromInternal;
}

void StatisticsParser::setLastUpdateFromInternal(uint32_t lastUpdate)
{
_lastUpdateFromInternal = lastUpdate;
}

void StatisticsParser::zeroFields(const FieldId_t* fields)
{
// Loop all channels
Expand All @@ -325,6 +341,7 @@ void StatisticsParser::zeroFields(const FieldId_t* fields)
}
}
}
setLastUpdateFromInternal(millis());
}

static float calcYieldTotalCh0(StatisticsParser* iv, uint8_t arg0)
Expand Down
8 changes: 8 additions & 0 deletions lib/Hoymiles/src/parser/StatisticsParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,13 @@ class StatisticsParser : public Parser {
void zeroRuntimeData();
void zeroDailyData();

// Update time when new data from the inverter is received
void setLastUpdate(uint32_t lastUpdate);

// Update time when internal data structure changes (from inverter and by internal manipulation)
uint32_t getLastUpdateFromInternal();
void setLastUpdateFromInternal(uint32_t lastUpdate);

private:
void zeroFields(const FieldId_t* fields);

Expand All @@ -154,4 +161,5 @@ class StatisticsParser : public Parser {
std::list<fieldSettings_t> _fieldSettings;

uint32_t _rxFailureCount = 0;
uint32_t _lastUpdateFromInternal = 0;
};
10 changes: 3 additions & 7 deletions src/MqttHandleInverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,9 @@ void MqttHandleInverterClass::loop()
MqttSettings.publish(subtopic + "/status/last_update", String(0));
}

uint32_t lastUpdate = inv->Statistics()->getLastUpdate();
if (lastUpdate > 0 && (lastUpdate != _lastPublishStats[i] || ((inv->getZeroValuesIfUnreachable() || inv->getZeroYieldDayOnMidnight()) && _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);
uint32_t lastUpdateInternal = inv->Statistics()->getLastUpdateFromInternal();
if (inv->Statistics()->getLastUpdate() > 0 && (lastUpdateInternal != _lastPublishStats[i])) {
_lastPublishStats[i] = lastUpdateInternal;

// Loop all channels
for (auto& t : inv->Statistics()->getChannelTypes()) {
Expand Down

0 comments on commit a974e21

Please sign in to comment.