From a5f872a86c3c43e5f103dedb80fb1eaecb0f6ecb Mon Sep 17 00:00:00 2001 From: Gunnar Skjold Date: Tue, 25 Apr 2023 08:09:47 +0200 Subject: [PATCH] More timezone adjustments after testing --- src/AmsToMqttBridge.ino | 4 ++-- src/IEC6205621.cpp | 5 +++-- src/IEC6205621.h | 3 ++- src/IEC6205675.cpp | 8 ++------ 4 files changed, 9 insertions(+), 11 deletions(-) diff --git a/src/AmsToMqttBridge.ino b/src/AmsToMqttBridge.ino index dd98dc6a..c80123c2 100644 --- a/src/AmsToMqttBridge.ino +++ b/src/AmsToMqttBridge.ino @@ -96,7 +96,7 @@ RemoteDebug Debug; EntsoeApi* eapi = NULL; -Timezone* tz; +Timezone* tz = NULL; AmsWebServer ws(commonBuffer, &Debug, &hw); @@ -1093,7 +1093,7 @@ bool readHanPort() { data = new IEC6205675(payload, meterState.getMeterType(), &meterConfig, ctx); } } else if(ctx.type == DATA_TAG_DSMR) { - data = new IEC6205621(payload); + data = new IEC6205621(payload, tz); } len = 0; diff --git a/src/IEC6205621.cpp b/src/IEC6205621.cpp index b3446f62..79def1a5 100644 --- a/src/IEC6205621.cpp +++ b/src/IEC6205621.cpp @@ -1,6 +1,6 @@ #include "IEC6205621.h" -IEC6205621::IEC6205621(const char* p) { +IEC6205621::IEC6205621(const char* p, Timezone* tz) { if(strlen(p) < 16) return; @@ -58,7 +58,8 @@ IEC6205621::IEC6205621(const char* p) { tm.Hour = timestamp.substring(6,8).toInt(); tm.Minute = timestamp.substring(8,10).toInt(); tm.Second = timestamp.substring(10,12).toInt(); - meterTimestamp = makeTime(tm); // TODO: Adjust for time zone + meterTimestamp = makeTime(tm); + if(tz != NULL) meterTimestamp = tz->toUTC(meterTimestamp); } activeImportPower = (uint16_t) (extractDouble(payload, F("1.7.0"))); diff --git a/src/IEC6205621.h b/src/IEC6205621.h index 172bfa20..5ee1d7f7 100644 --- a/src/IEC6205621.h +++ b/src/IEC6205621.h @@ -3,10 +3,11 @@ #include "Arduino.h" #include "AmsData.h" +#include "Timezone.h" class IEC6205621 : public AmsData { public: - IEC6205621(const char* payload); + IEC6205621(const char* payload, Timezone* tz); private: String extract(String payload, String obis); diff --git a/src/IEC6205675.cpp b/src/IEC6205675.cpp index 61915d4f..4c534d0b 100644 --- a/src/IEC6205675.cpp +++ b/src/IEC6205675.cpp @@ -169,9 +169,7 @@ IEC6205675::IEC6205675(const char* d, uint8_t useMeterType, MeterConfig* meterCo } if(this->packageTimestamp > 0) { - if(meterType == AmsTypeAidon) { - this->packageTimestamp = tz.toUTC(this->packageTimestamp); - } else if(meterType == AmsTypeKamstrup) { + if(meterType == AmsTypeAidon || meterType == AmsTypeKamstrup) { this->packageTimestamp = this->packageTimestamp - 3600; } } @@ -274,9 +272,7 @@ IEC6205675::IEC6205675(const char* d, uint8_t useMeterType, MeterConfig* meterCo if(meterTs != NULL) { AmsOctetTimestamp* amst = (AmsOctetTimestamp*) meterTs; time_t ts = decodeCosemDateTime(amst->dt); - if(meterType == AmsTypeAidon) { - meterTimestamp = tz.toUTC(ts); - } else if(meterType == AmsTypeKamstrup) { + if(meterType == AmsTypeAidon || meterType == AmsTypeKamstrup) { meterTimestamp = ts - 3600; } else { meterTimestamp = ts;