Skip to content

Commit 3d128f5

Browse files
committed
Fix issue for ex DLMS where accumulated is always included
1 parent dda61db commit 3d128f5

File tree

2 files changed

+8
-10
lines changed

2 files changed

+8
-10
lines changed

lib/AmsDataStorage/src/AmsDataStorage.cpp

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -639,25 +639,22 @@ bool AmsDataStorage::isDayHappy(time_t now) {
639639
return false;
640640
}
641641

642-
if(now < FirmwareVersion::BuildEpoch) return false;
643-
644-
if(now < day.lastMeterReadTime) {
642+
// If the timestamp is before the firware was built, there is something seriously wrong..
643+
if(now < FirmwareVersion::BuildEpoch) {
645644
return false;
646645
}
647-
// There are cases where the meter reports before the hour. The update method will then receive the meter timestamp as reference, thus there will not be 3600s between.
648-
// Leaving a 100s buffer for these cases
649-
if(now-day.lastMeterReadTime > 3500) {
646+
647+
// If the timestamp is before the last time we updated, there is also something wrong..
648+
if(now < day.lastMeterReadTime) {
650649
return false;
651650
}
652651

653652
tmElements_t tm, last;
654653
breakTime(tz->toLocal(now), tm);
655654
breakTime(tz->toLocal(day.lastMeterReadTime), last);
656-
if(tm.Hour != last.Hour) {
657-
return false;
658-
}
659655

660-
return true;
656+
// If the timestamp is at the same day and hour as last update, we are happy
657+
return tm.Day == last.Day && tm.Hour == last.Hour;
661658
}
662659

663660
bool AmsDataStorage::isMonthHappy(time_t now) {

src/AmsToMqttBridge.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1577,6 +1577,7 @@ void handleDataSuccess(AmsData* data) {
15771577

15781578
time_t dataUpdateTime = now;
15791579
if(abs(now - meterTime) < 300) {
1580+
// If the meter timestamp is close to our internal clock, use meter timestamp, because that is best for data tracking
15801581
dataUpdateTime = meterTime;
15811582
}
15821583

0 commit comments

Comments
 (0)