Skip to content

Commit

Permalink
JK BMS: fix SoC last update timestamp
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
schlimmchen committed Sep 13, 2023
1 parent 24018a1 commit 314e38a
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/BatteryStats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<Label::ProductId>();
auto oProductId = dp.get<Label::ProductId>();
if (oProductId.has_value()) {
_manufacturer = oProductId->c_str();
auto pos = oProductId->rfind("JK");
Expand All @@ -194,12 +192,14 @@ void JkBmsBatteryStats::updateFrom(JkBms::DataPointContainer const& dp)
}
}

auto oSoCValue = _dataPoints.get<Label::BatterySoCPercent>();
auto oSoCValue = dp.get<Label::BatterySoCPercent>();
if (oSoCValue.has_value()) {
_SoC = *oSoCValue;
auto oSoCDataPoint = _dataPoints.getDataPointFor<Label::BatterySoCPercent>();
auto oSoCDataPoint = dp.getDataPointFor<Label::BatterySoCPercent>();
_lastUpdateSoC = oSoCDataPoint->getTimestamp();
}

_dataPoints.updateFrom(dp);

_lastUpdate = millis();
}

0 comments on commit 314e38a

Please sign in to comment.