From b501d25ab6214eefdc395960aa41ff097a14b031 Mon Sep 17 00:00:00 2001 From: Bernhard Kirchen Date: Mon, 18 Sep 2023 10:30:03 +0200 Subject: [PATCH] JK BMS: fix SoC last update timestamp (#439) for the MQTT integration, JkBms::DataPointContainer::updateFrom() was changed such that the data points timestamp reflects the last change of the data point value. that timestamp was used to set the SoC last update timestamp. however, that timestampt must reflect the last time the SoC was successfully received from the JK BMS so we could make sure the value was up to date. --- src/BatteryStats.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/BatteryStats.cpp b/src/BatteryStats.cpp index fb1d2f2d..81939e7f 100644 --- a/src/BatteryStats.cpp +++ b/src/BatteryStats.cpp @@ -180,12 +180,10 @@ void JkBmsBatteryStats::mqttPublish() const void JkBmsBatteryStats::updateFrom(JkBms::DataPointContainer const& dp) { - _dataPoints.updateFrom(dp); - using Label = JkBms::DataPointLabel; _manufacturer = "JKBMS"; - auto oProductId = _dataPoints.get(); + auto oProductId = dp.get(); if (oProductId.has_value()) { _manufacturer = oProductId->c_str(); auto pos = oProductId->rfind("JK"); @@ -194,12 +192,14 @@ void JkBmsBatteryStats::updateFrom(JkBms::DataPointContainer const& dp) } } - auto oSoCValue = _dataPoints.get(); + auto oSoCValue = dp.get(); if (oSoCValue.has_value()) { _SoC = *oSoCValue; - auto oSoCDataPoint = _dataPoints.getDataPointFor(); + auto oSoCDataPoint = dp.getDataPointFor(); _lastUpdateSoC = oSoCDataPoint->getTimestamp(); } + _dataPoints.updateFrom(dp); + _lastUpdate = millis(); }