-
-
Notifications
You must be signed in to change notification settings - Fork 92
Feature: Add new battery provider JK BMS via CAN bus #2113
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: development
Are you sure you want to change the base?
Changes from all commits
9891b01
feecee1
082baee
9a61901
3c12d2d
8fb88ac
57af4fa
1e488f4
010a69d
e098b42
ef48663
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
name: OpenDTU-onBattery Test Build | ||
|
||
on: workflow_dispatch | ||
|
||
jobs: | ||
get_default_envs: | ||
name: Gather Environments | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- name: Cache pip | ||
uses: actions/cache@v3 | ||
with: | ||
path: ~/.cache/pip | ||
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }} | ||
restore-keys: | | ||
${{ runner.os }}-pip- | ||
- uses: actions/setup-python@v4 | ||
with: | ||
python-version: "3.9" | ||
|
||
- name: Install PlatformIO | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install --upgrade platformio | ||
- name: Get default environments | ||
id: envs | ||
run: | | ||
echo "environments=$(pio project config --json-output | jq -cr '.[1][1][0][1]|split(",")')" >> $GITHUB_OUTPUT | ||
outputs: | ||
environments: ${{ steps.envs.outputs.environments }} | ||
|
||
build: | ||
name: Build Enviornments | ||
runs-on: ubuntu-latest | ||
needs: get_default_envs | ||
strategy: | ||
matrix: | ||
environment: ${{ fromJSON(needs.get_default_envs.outputs.environments) }} | ||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- name: Get tags | ||
run: git fetch --force --tags origin | ||
|
||
- name: Cache pip | ||
uses: actions/cache@v3 | ||
with: | ||
path: ~/.cache/pip | ||
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }} | ||
restore-keys: | | ||
${{ runner.os }}-pip- | ||
- name: Cache PlatformIO | ||
uses: actions/cache@v3 | ||
with: | ||
path: ~/.platformio | ||
key: ${{ runner.os }}-${{ hashFiles('**/lockfiles') }} | ||
|
||
- name: Set up Python | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: "3.9" | ||
|
||
- name: Install PlatformIO | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install --upgrade platformio | ||
- name: Setup Node.js and yarn | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: "18" | ||
cache: "yarn" | ||
cache-dependency-path: "webapp/yarn.lock" | ||
|
||
- name: Install WebApp dependencies | ||
run: yarn --cwd webapp install --frozen-lockfile | ||
|
||
- name: Build WebApp | ||
run: yarn --cwd webapp build | ||
|
||
- name: Build firmware | ||
run: pio run -e ${{ matrix.environment }} | ||
|
||
- name: Rename Firmware | ||
run: mv .pio/build/${{ matrix.environment }}/firmware.bin .pio/build/${{ matrix.environment }}/opendtu-onbattery-${{ matrix.environment }}.bin | ||
|
||
- name: Rename Factory Firmware | ||
run: mv .pio/build/${{ matrix.environment }}/firmware.factory.bin .pio/build/${{ matrix.environment }}/opendtu-onbattery-${{ matrix.environment }}.factory.bin | ||
|
||
- uses: actions/upload-artifact@v3 | ||
with: | ||
name: opendtu-onbattery-${{ matrix.environment }} | ||
path: | | ||
.pio/build/${{ matrix.environment }}/opendtu-onbattery-${{ matrix.environment }}.bin | ||
.pio/build/${{ matrix.environment }}/opendtu-onbattery-${{ matrix.environment }}.factory.bin | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,7 +55,6 @@ designs](https://opendtu-onbattery.net/3rd_party/cases/) available for you to | |
print yourself. | ||
|
||
### Ready-To-Use | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please revert the changes to the README. By looking at the commits it looks like those changes got introduced by accident. |
||
If you are interested in ready-to-use hardware available for sale, the | ||
OpenDTU-OnBattery project endorses the **[OpenDTU Fusion | ||
board](https://opendtu-onbattery.net/3rd_party/opendtu_fusion/)**. | ||
|
@@ -125,8 +124,6 @@ To find out what's new or improved have a look at the | |
[releases](https://github.com/hoylabs/OpenDTU-OnBattery/releases). | ||
|
||
## Project State | ||
|
||
OpenDTU-OnBattery is actively maintained. Please note that OpenDTU-OnBattery | ||
may change significantly during its development. Bug reports, comments, feature | ||
requests and pull requests are welcome! | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -229,12 +229,19 @@ struct BATTERY_SERIAL_CONFIG_T { | |
}; | ||
using BatterySerialConfig = struct BATTERY_SERIAL_CONFIG_T; | ||
|
||
struct BATTERY_JKBMSCAN_CONFIG_T { | ||
uint8_t NumberOfCells; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can't we know the number of cells based on the values that we retrieve from the BMS? |
||
uint8_t CanProtocolVersion; | ||
}; | ||
using BatteryJkBmsCanConfig = struct BATTERY_JKBMSCAN_CONFIG_T; | ||
|
||
struct BATTERY_CONFIG_T { | ||
bool Enabled; | ||
uint8_t Provider; | ||
BatteryMqttConfig Mqtt; | ||
BatteryZendureConfig Zendure; | ||
BatterySerialConfig Serial; | ||
BatteryJkBmsCanConfig JkBmsCan; | ||
bool EnableDischargeCurrentLimit; | ||
float DischargeCurrentLimit; | ||
float DischargeCurrentLimitBelowSoc; | ||
|
@@ -486,6 +493,7 @@ class ConfigurationClass { | |
static void serializeBatteryZendureConfig(BatteryZendureConfig const& source, JsonObject& target); | ||
static void serializeBatteryMqttConfig(BatteryMqttConfig const& source, JsonObject& target); | ||
static void serializeBatterySerialConfig(BatterySerialConfig const& source, JsonObject& target); | ||
static void serializeBatteryJkBmsCanConfig(BatteryJkBmsCanConfig const& source, JsonObject& target); | ||
static void serializePowerLimiterConfig(PowerLimiterConfig const& source, JsonObject& target); | ||
static void serializeGridChargerConfig(GridChargerConfig const& source, JsonObject& target); | ||
static void serializeGridChargerCanConfig(GridChargerCanConfig const& source, JsonObject& target); | ||
|
@@ -503,6 +511,7 @@ class ConfigurationClass { | |
static void deserializeBatteryZendureConfig(JsonObject const& source, BatteryZendureConfig& target); | ||
static void deserializeBatteryMqttConfig(JsonObject const& source, BatteryMqttConfig& target); | ||
static void deserializeBatterySerialConfig(JsonObject const& source, BatterySerialConfig& target); | ||
static void deserializeBatteryJkBmsCanConfig(JsonObject const& source, BatteryJkBmsCanConfig& target); | ||
static void deserializePowerLimiterConfig(JsonObject const& source, PowerLimiterConfig& target); | ||
static void deserializeGridChargerConfig(JsonObject const& source, GridChargerConfig& target); | ||
static void deserializeGridChargerCanConfig(JsonObject const& source, GridChargerCanConfig& target); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// SPDX-License-Identifier: GPL-2.0-or-later | ||
#pragma once | ||
|
||
#include <battery/HassIntegration.h> | ||
#include <battery/jkbmscan/Stats.h> | ||
|
||
namespace Batteries::JkBmsCan { | ||
|
||
class HassIntegration : public ::Batteries::HassIntegration { | ||
public: | ||
explicit HassIntegration(std::shared_ptr<Stats> spStats); | ||
|
||
void publishSensors() const final; | ||
}; | ||
|
||
} // namespace Batteries::JkBmsCan |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// SPDX-License-Identifier: GPL-2.0-or-later | ||
#pragma once | ||
|
||
#include <memory> | ||
#include <driver/twai.h> | ||
#include <battery/CanReceiver.h> | ||
#include <battery/jkbmscan/Stats.h> | ||
#include <battery/jkbmscan/HassIntegration.h> | ||
|
||
namespace Batteries::JkBmsCan { | ||
|
||
class Provider : public ::Batteries::CanReceiver { | ||
public: | ||
Provider(); | ||
bool init() final; | ||
void onMessage(twai_message_t rx_message) final; | ||
|
||
std::shared_ptr<::Batteries::Stats> getStats() const final { return _stats; } | ||
std::shared_ptr<::Batteries::HassIntegration> getHassIntegration() final { return _hassIntegration; } | ||
|
||
private: | ||
void dummyData(); | ||
|
||
std::shared_ptr<Stats> _stats; | ||
std::shared_ptr<HassIntegration> _hassIntegration; | ||
}; | ||
|
||
} // namespace Batteries::JkBmsCan |
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
@@ -0,0 +1,72 @@ | ||||
// SPDX-License-Identifier: GPL-2.0-or-later | ||||
#pragma once | ||||
|
||||
#include <battery/Stats.h> | ||||
|
||||
namespace Batteries::JkBmsCan { | ||||
|
||||
class Stats : public ::Batteries::Stats { | ||||
friend class Provider; | ||||
|
||||
public: | ||||
void getLiveViewData(JsonVariant& root) const final; | ||||
void mqttPublish() const final; | ||||
// bool getImmediateChargingRequest() const { return _chargeImmediately; } ; | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this supported? If not, please remove it |
||||
float getChargeCurrentLimitation() const { return _chargeCurrentLimitation; } ; | ||||
|
||||
private: | ||||
void setLastUpdate(uint32_t ts) { _lastUpdate = ts; } | ||||
|
||||
float _chargeVoltage; | ||||
float _chargeCurrentLimitation; | ||||
float _dischargeVoltageLimitation; | ||||
uint8_t _stateOfHealth; | ||||
float _temperature; | ||||
|
||||
float _cellVoltage[25]; | ||||
float _packVoltage; | ||||
float _MaxCellVoltage; | ||||
uint8_t _MaxCellVoltageNumber; | ||||
float _MinCellVoltage; | ||||
uint8_t _MinCellVoltageNumber; | ||||
|
||||
float _capacityRemaining; | ||||
float _fullChargeCapacity; | ||||
float _cycleCapacity; | ||||
uint16_t _cycleCount; | ||||
|
||||
uint32_t _bmsRunTime; | ||||
uint16_t _heaterCurrent; | ||||
|
||||
|
||||
bool _alarmOverCurrentDischarge; | ||||
bool _alarmOverCurrentCharge; | ||||
bool _alarmUnderTemperature; | ||||
bool _alarmOverTemperature; | ||||
bool _alarmUnderVoltage; | ||||
bool _alarmOverVoltage; | ||||
bool _alarmBmsInternal; | ||||
|
||||
bool _warningHighCurrentDischarge; | ||||
bool _warningHighCurrentCharge; | ||||
bool _warningLowTemperature; | ||||
bool _warningHighTemperature; | ||||
bool _warningLowVoltage; | ||||
bool _warningHighVoltage; | ||||
bool _warningBmsInternal; | ||||
|
||||
bool _chargeEnabled; | ||||
bool _dischargeEnabled; | ||||
bool _balanceEnabled; | ||||
bool _heaterEnabled; | ||||
bool _accEnabled; | ||||
bool _chargerPluged; | ||||
|
||||
bool _chargeRequest; | ||||
bool _chargeAndHeat; | ||||
|
||||
uint8_t _moduleCount; | ||||
uint8_t _JkBmsCanVersion; | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The private member
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||
}; | ||||
|
||||
} // namespace Batteries::JkBmsCan |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,8 +14,8 @@ | |
; Under Linux, the ports are in the format /dev/tty***, typically /dev/ttyUSB0 | ||
; To look up the port, execute ls /dev/tty*, then connect the device | ||
; then execute ls /dev/tty* again and check which device was added | ||
;monitor_port = COM4 | ||
;upload_port = COM4 | ||
monitor_port = /dev/ttyACM2 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please revert the changes in this file |
||
upload_port = /dev/ttyACM2 | ||
|
||
|
||
; you can define your personal board and/or settings here | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need this new workflow? based on the commit it looks like it was added by accident.