Skip to content

Commit

Permalink
Pytes battery: Add support for native CAN protocol
Browse files Browse the repository at this point in the history
The recently added PytesCanReceiver.cpp implements the Victron CAN
protocol.

This change additionally adds support for the native Pytes CAN
protocol messages.

Features only supported in Pytes protocol:
- High-resolution state of charge / full and remaining mAh
- Charge cycle counter
- Balancing state

Features only supported in Victron protocol:
- FW version
- Serial number

Note that the only known way to select the native Pytes protocol is
via the serial console (Cisco-compatible cables work):

```
login config
setprt PYTES
logout
```

to return to Victron protocol use:
```
login config
setprt VICTRON
logout
```

The protocol switch will take effect immediately.

Tested on Pytes E-Box 4850

See #1188
  • Loading branch information
ranma committed Sep 1, 2024
1 parent dcc8313 commit ad32ed8
Show file tree
Hide file tree
Showing 6 changed files with 232 additions and 19 deletions.
10 changes: 8 additions & 2 deletions include/BatteryStats.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ class PytesBatteryStats : public BatteryStats {
public:
void getLiveViewData(JsonVariant& root) const final;
void mqttPublish() const final;
bool getImmediateChargingRequest() const { return _chargeImmediately; } ;
float getChargeCurrentLimitation() const { return _chargeCurrentLimit; } ;

private:
Expand All @@ -154,6 +155,8 @@ class PytesBatteryStats : public BatteryStats {
float _dischargeCurrentLimit;

uint16_t _stateOfHealth;
int _chargeCycles = -1;
int _balance = -1;

float _temperature;

Expand All @@ -173,8 +176,9 @@ class PytesBatteryStats : public BatteryStats {
uint8_t _moduleCountBlockingCharge;
uint8_t _moduleCountBlockingDischarge;

uint16_t _totalCapacity;
uint16_t _availableCapacity;
float _totalCapacity;
float _availableCapacity;
uint8_t _capacityPrecision = 0; // decimal places

float _chargedEnergy = -1;
float _dischargedEnergy = -1;
Expand All @@ -200,6 +204,8 @@ class PytesBatteryStats : public BatteryStats {
bool _warningHighTemperatureCharge;
bool _warningInternalFailure;
bool _warningCellImbalance;

bool _chargeImmediately;
};

class JkBmsBatteryStats : public BatteryStats {
Expand Down
19 changes: 17 additions & 2 deletions src/BatteryStats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,13 @@ void PytesBatteryStats::getLiveViewData(JsonVariant& root) const
addLiveViewValue(root, "dischargeVoltageLimitation", _dischargeVoltageLimit, "V", 1);
addLiveViewValue(root, "dischargeCurrentLimitation", _dischargeCurrentLimit, "A", 1);
addLiveViewValue(root, "stateOfHealth", _stateOfHealth, "%", 0);
if (_chargeCycles != -1) {
addLiveViewValue(root, "chargeCycles", _chargeCycles, "", 0);
}
addLiveViewValue(root, "temperature", _temperature, "°C", 1);

addLiveViewValue(root, "capacity", _totalCapacity, "Ah", 0);
addLiveViewValue(root, "availableCapacity", _availableCapacity, "Ah", 0);
addLiveViewValue(root, "capacity", _totalCapacity, "Ah", _capacityPrecision);
addLiveViewValue(root, "availableCapacity", _availableCapacity, "Ah", _capacityPrecision);

if (_chargedEnergy != -1) {
addLiveViewValue(root, "chargedEnergy", _chargedEnergy, "kWh", 1);
Expand All @@ -142,6 +145,11 @@ void PytesBatteryStats::getLiveViewData(JsonVariant& root) const
addLiveViewValue(root, "dischargedEnergy", _dischargedEnergy, "kWh", 1);
}

if (_balance != -1) {
addLiveViewTextValue(root, "balancingActive", (_balance?"yes":"no"));
}
addLiveViewTextValue(root, "chargeImmediately", (_chargeImmediately?"yes":"no"));

addLiveViewInSection(root, "cells", "cellMinVoltage", static_cast<float>(_cellMinMilliVolt)/1000, "V", 3);
addLiveViewInSection(root, "cells", "cellMaxVoltage", static_cast<float>(_cellMaxMilliVolt)/1000, "V", 3);
addLiveViewInSection(root, "cells", "cellDiffVoltage", (_cellMaxMilliVolt - _cellMinMilliVolt), "mV", 0);
Expand Down Expand Up @@ -347,6 +355,12 @@ void PytesBatteryStats::mqttPublish() const
MqttSettings.publish("battery/settings/dischargeVoltageLimitation", String(_dischargeVoltageLimit));

MqttSettings.publish("battery/stateOfHealth", String(_stateOfHealth));
if (_chargeCycles != -1) {
MqttSettings.publish("battery/chargeCycles", String(_chargeCycles));
}
if (_balance != -1) {
MqttSettings.publish("battery/balancingActive", String(_balance ? 1 : 0));
}
MqttSettings.publish("battery/temperature", String(_temperature));

if (_chargedEnergy != -1) {
Expand Down Expand Up @@ -396,6 +410,7 @@ void PytesBatteryStats::mqttPublish() const
MqttSettings.publish("battery/warning/highTemperatureCharge", String(_warningHighTemperatureCharge));
MqttSettings.publish("battery/warning/bmsInternal", String(_warningInternalFailure));
MqttSettings.publish("battery/warning/cellImbalance", String(_warningCellImbalance));
MqttSettings.publish("battery/charging/chargeImmediately", String(_chargeImmediately));
}

void JkBmsBatteryStats::mqttPublish() const
Expand Down
Loading

0 comments on commit ad32ed8

Please sign in to comment.