Skip to content

Commit c22ae2b

Browse files
committed
Feature: show BMS FW and HW version (JK BMS, SmartShunt)
1 parent 561f4be commit c22ae2b

File tree

8 files changed

+52
-6
lines changed

8 files changed

+52
-6
lines changed

include/BatteryStats.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ class BatteryStats {
5858
}
5959

6060
String _manufacturer = "unknown";
61+
String _hwversion = "";
62+
String _fwversion = "";
6163
uint32_t _lastUpdate = 0;
6264

6365
private:
@@ -157,7 +159,6 @@ class VictronSmartShuntStats : public BatteryStats {
157159
uint32_t _timeToGo;
158160
float _chargedEnergy;
159161
float _dischargedEnergy;
160-
String _modelName;
161162
int32_t _instantaneousPower;
162163
float _midpointVoltage;
163164
float _midpointDeviation;

lib/VeDirectFrameHandler/VeDirectData.cpp

+10-3
Original file line numberDiff line numberDiff line change
@@ -158,18 +158,25 @@ uint32_t veStruct::getFwVersionAsInteger() const
158158
String veStruct::getFwVersionFormatted() const
159159
{
160160
char const* strVersion = firmwareVer_FW;
161+
char rc = 0;
161162

162163
// VE.Direct protocol manual states that the first char can be a non-digit,
163164
// in which case that char represents a release candidate version
164-
if (strVersion[0] < '0' || strVersion[0] > '9') { ++strVersion; }
165+
if (strVersion[0] < '0' || strVersion[0] > '9') {
166+
rc = strVersion[0];
167+
++strVersion;
168+
}
169+
170+
// SmartShunt firmware version is transmitted with leading zero(es)
171+
while (strVersion[0] == '0') { ++strVersion; }
165172

166173
String res(strVersion[0]);
167174
res += ".";
168175
res += strVersion + 1;
169176

170-
if (strVersion > firmwareVer_FW) {
177+
if (rc != 0) {
171178
res += "-rc-";
172-
res += firmwareVer_FW[0];
179+
res += rc;
173180
}
174181

175182
return res;

src/BatteryStats.cpp

+26-2
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,12 @@ bool BatteryStats::updateAvailable(uint32_t since) const
6262
void BatteryStats::getLiveViewData(JsonVariant& root) const
6363
{
6464
root["manufacturer"] = _manufacturer;
65+
if (!_fwversion.isEmpty()) {
66+
root["fwversion"] = _fwversion;
67+
}
68+
if (!_hwversion.isEmpty()) {
69+
root["hwversion"] = _hwversion;
70+
}
6571
root["data_age"] = getAgeSeconds();
6672

6773
addLiveViewValue(root, "SoC", _soc, "%", _socPrecision);
@@ -375,20 +381,38 @@ void JkBmsBatteryStats::updateFrom(JkBms::DataPointContainer const& dp)
375381
_cellVoltageTimestamp = millis();
376382
}
377383

384+
auto oVersion = _dataPoints.get<Label::BmsSoftwareVersion>();
385+
if (oVersion.has_value()) {
386+
// raw: "11.XW_S11.262H_"
387+
// => Hardware "V11.XW" (displayed in Android app)
388+
// => Software "V11.262H" (displayed in Android app)
389+
auto first = oVersion->find('_');
390+
if (first != std::string::npos) {
391+
_hwversion = oVersion->substr(0, first).c_str();
392+
393+
auto second = oVersion->find('_', first + 1);
394+
395+
// the 'S' seems to be merely an indicator for "software"?
396+
if (oVersion->at(first + 1) == 'S') { first++; }
397+
398+
_fwversion = oVersion->substr(first + 1, second - first - 1).c_str();
399+
}
400+
}
401+
378402
_lastUpdate = millis();
379403
}
380404

381405
void VictronSmartShuntStats::updateFrom(VeDirectShuntController::data_t const& shuntData) {
382406
BatteryStats::setVoltage(shuntData.batteryVoltage_V_mV / 1000.0, millis());
383407
BatteryStats::setSoC(static_cast<float>(shuntData.SOC) / 10, 1/*precision*/, millis());
408+
_fwversion = shuntData.getFwVersionFormatted();
384409

385410
_current = static_cast<float>(shuntData.batteryCurrent_I_mA) / 1000;
386-
_modelName = shuntData.getPidAsString().data();
387411
_chargeCycles = shuntData.H4;
388412
_timeToGo = shuntData.TTG / 60;
389413
_chargedEnergy = static_cast<float>(shuntData.H18) / 100;
390414
_dischargedEnergy = static_cast<float>(shuntData.H17) / 100;
391-
_manufacturer = "Victron " + _modelName;
415+
_manufacturer = String("Victron ") + shuntData.getPidAsString().data();
392416
_temperature = shuntData.T;
393417
_tempPresent = shuntData.tempPresent;
394418
_midpointVoltage = static_cast<float>(shuntData.VM) / 1000;

webapp/src/components/BatteryView.vue

+6
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@
1818
<div style="padding-right: 2em;">
1919
{{ $t('battery.battery') }}: {{ batteryData.manufacturer }}
2020
</div>
21+
<div style="padding-right: 2em;" v-if="'fwversion' in batteryData">
22+
{{ $t('battery.FwVersion') }}: {{ batteryData.fwversion }}
23+
</div>
24+
<div style="padding-right: 2em;" v-if="'hwversion' in batteryData">
25+
{{ $t('battery.HwVersion') }}: {{ batteryData.hwversion }}
26+
</div>
2127
<div style="padding-right: 2em;">
2228
{{ $t('battery.DataAge') }} {{ $t('battery.Seconds', { 'val': batteryData.data_age }) }}
2329
</div>

webapp/src/locales/de.json

+2
Original file line numberDiff line numberDiff line change
@@ -874,6 +874,8 @@
874874
},
875875
"battery": {
876876
"battery": "Batterie",
877+
"FwVersion": "Firmware-Version",
878+
"HwVersion": "Hardware-Version",
877879
"DataAge": "letzte Aktualisierung: ",
878880
"Seconds": "vor {val} Sekunden",
879881
"status": "Status",

webapp/src/locales/en.json

+2
Original file line numberDiff line numberDiff line change
@@ -881,6 +881,8 @@
881881
},
882882
"battery": {
883883
"battery": "Battery",
884+
"FwVersion": "Firmware Version",
885+
"HwVersion": "Hardware Version",
884886
"DataAge": "Data Age: ",
885887
"Seconds": " {val} seconds",
886888
"status": "Status",

webapp/src/locales/fr.json

+2
Original file line numberDiff line numberDiff line change
@@ -866,6 +866,8 @@
866866
},
867867
"battery": {
868868
"battery": "Battery",
869+
"FwVersion": "Firmware Version",
870+
"HwVersion": "Hardware Version",
869871
"DataAge": "Data Age: ",
870872
"Seconds": " {val} seconds",
871873
"status": "Status",

webapp/src/types/BatteryDataStatus.ts

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ type BatteryData = (ValueObject | string)[];
44

55
export interface Battery {
66
manufacturer: string;
7+
fwversion: string;
8+
hwversion: string;
79
data_age: number;
810
values: BatteryData[];
911
issues: number[];

0 commit comments

Comments
 (0)