Skip to content

Commit

Permalink
[BREAKING] Drop unstable protocol version auto-detection (#434)
Browse files Browse the repository at this point in the history
  • Loading branch information
syssi authored Jan 26, 2024
1 parent 8d90ea9 commit 363ed49
Show file tree
Hide file tree
Showing 20 changed files with 39 additions and 49 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ All JK-BMS models with software version `>=6.0` are using the implemented protoc
* JK-B1A24S15P, hw 8.x, sw 8.1.0H (reported by [@killee](https://github.com/syssi/esphome-jk-bms/discussions/4))
* JK-B1A20S15P, hw 8.x, sw 8.14U (reported by [@trippfam07](https://github.com/syssi/esphome-jk-bms/issues/31))
* JK-B1A20S15P, hw 10.xw, sw 10.07 (reported by [@romeox44](https://github.com/syssi/esphome-jk-bms/discussions/125))
* JK-B1A20S15P, hw 10.xw, sw 10.10, using `JK02` (reported by [@austin202220](https://github.com/syssi/esphome-jk-bms/issues/297#issuecomment-1510685683))
* JK-B1A20S15P, hw 10.xw, sw 10.10, using `JK02_24S` (reported by [@austin202220](https://github.com/syssi/esphome-jk-bms/issues/297#issuecomment-1510685683))
* JK-B1A20S15P, hw 11.xw, sw 11.26, using UART-TTL (reported by [@Tesla72PL](https://github.com/syssi/esphome-jk-bms/issues/309))
* JK-B2A24S15P, hw 6.x, sw 6.1.3S (reported by [@miguel300477](https://github.com/syssi/esphome-jk-bms/issues/57))
* JK-B2A24S15P, hw 8.x, sw 8.21W (reported by [@mariusvaida](https://github.com/syssi/esphome-jk-bms/issues/120))
Expand All @@ -40,7 +40,7 @@ All JK-BMS models with software version `>=6.0` are using the implemented protoc
* JK-B2A24S20P, hw 10.X-W, sw 10.02 (reported by [@SeByDocKy](https://github.com/syssi/esphome-jk-bms/issues/37#issuecomment-1040569576))
* JK-B2A24S20P, hw 10.XG, sw 10.07D30 (reported by [@TheSmartGerman](https://github.com/syssi/esphome-jk-bms/discussions/122))
* JK-B2A24S20P, hw 10.XW, sw 10.07 (reported by [@amagr0](https://github.com/syssi/esphome-jk-bms/issues/124#issuecomment-1166366196))
* JK-B2A8S20P, hw 9.x, sw 9.01M3, using `JK02` (reported by [@EasilyBoredEngineer](https://github.com/syssi/esphome-jk-bms/discussions/110))
* JK-B2A8S20P, hw 9.x, sw 9.01M3, using `JK02_24S` (reported by [@EasilyBoredEngineer](https://github.com/syssi/esphome-jk-bms/discussions/110))
* JK-B2A8S20P, hw 9.x, sw 9.08W (reported by [@vrabi-cv](https://github.com/syssi/esphome-jk-bms/discussions/144#discussioncomment-3285901))
* JK-B2A8S20P, hw 11.XW, sw 11.17, using `JK02_32S` (reported by [@senfkorn](https://github.com/syssi/esphome-jk-bms/issues/147))
* JK-B2A8S20P, hw 11.XW, sw 11.26, using `JK02_32S` (reported by [@riker65](https://github.com/syssi/esphome-jk-bms/issues/276))
Expand Down
4 changes: 2 additions & 2 deletions components/jk_bms_ble/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
ProtocolVersion = jk_bms_ble_ns.enum("ProtocolVersion")
PROTOCOL_VERSION_OPTIONS = {
"JK04": ProtocolVersion.PROTOCOL_VERSION_JK04,
"JK02": ProtocolVersion.PROTOCOL_VERSION_JK02,
"JK02_24S": ProtocolVersion.PROTOCOL_VERSION_JK02_24S,
"JK02_32S": ProtocolVersion.PROTOCOL_VERSION_JK02_32S,
}

Expand All @@ -33,7 +33,7 @@
cv.Schema(
{
cv.GenerateID(): cv.declare_id(JkBmsBle),
cv.Optional(CONF_PROTOCOL_VERSION, default="JK02"): cv.enum(
cv.Required(CONF_PROTOCOL_VERSION): cv.enum(
PROTOCOL_VERSION_OPTIONS, upper=True
),
cv.Optional(
Expand Down
2 changes: 1 addition & 1 deletion components/jk_bms_ble/button/jk_button.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ static const char *const TAG = "jk_bms_ble.button";

void JkButton::dump_config() { LOG_BUTTON("", "JkBmsBle Button", this); }
void JkButton::press_action() {
// JK04, JK02, JK02_32S
// JK04, JK02_24S, JK02_32S
this->parent_->write_register(this->holding_register_, 0x00000000, 0x00);
}

Expand Down
20 changes: 4 additions & 16 deletions components/jk_bms_ble/jk_bms_ble.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ static const char *const TAG = "jk_bms_ble";
static const uint8_t MAX_NO_RESPONSE_COUNT = 10;

static const uint8_t FRAME_VERSION_JK04 = 0x01;
static const uint8_t FRAME_VERSION_JK02 = 0x02;
static const uint8_t FRAME_VERSION_JK02_24S = 0x02;
static const uint8_t FRAME_VERSION_JK02_32S = 0x03;

static const uint16_t JK_BMS_SERVICE_UUID = 0xFFE0;
Expand Down Expand Up @@ -315,20 +315,8 @@ void JkBmsBle::decode_jk02_cell_info_(const std::vector<uint8_t> &data) {
}
this->last_cell_info_ = now;

uint8_t frame_version = FRAME_VERSION_JK02_24S;
uint8_t offset = 0;
uint8_t frame_version = FRAME_VERSION_JK02;
if (this->protocol_version_ == PROTOCOL_VERSION_JK02) {
// Weak assumption: The value of data[189] (JK02) or data[189+32] (JK02_32S) is 0x01, 0x02 or 0x03
if (data[189] == 0x00 && data[189 + 32] > 0) {
frame_version = FRAME_VERSION_JK02_32S;
offset = 16;
ESP_LOGW(TAG,
"You hit the unstable auto detection of the protocol version. This feature will be removed in future!"
"Please update your configuration to protocol version JK02_32S if you are using a JK-B2A8S20P v11+");
}
}

// Override unstable auto detection
if (this->protocol_version_ == PROTOCOL_VERSION_JK02_32S) {
frame_version = FRAME_VERSION_JK02_32S;
offset = 16;
Expand Down Expand Up @@ -776,7 +764,7 @@ void JkBmsBle::decode_jk02_settings_(const std::vector<uint8_t> &data) {
ESP_LOGVV(TAG, " %s", format_hex_pretty(&data.front(), 160).c_str());
ESP_LOGVV(TAG, " %s", format_hex_pretty(&data.front() + 160, data.size() - 160).c_str());

// JK02 response example:
// JK02_24S response example:
//
// 0x55 0xAA 0xEB 0x90 0x01 0x4F 0x58 0x02 0x00 0x00 0x54 0x0B 0x00 0x00 0x80 0x0C 0x00 0x00 0xCC 0x10 0x00 0x00 0x68
// 0x10 0x00 0x00 0x0A 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
Expand Down Expand Up @@ -1076,7 +1064,7 @@ void JkBmsBle::decode_device_info_(const std::vector<uint8_t> &data) {
// User data:
// Setup passcode:

// JK02 response example:
// JK02_24S response example:
//
// 0x55 0xAA 0xEB 0x90 0x03 0x9F 0x4A 0x4B 0x2D 0x42 0x32 0x41 0x32 0x34 0x53 0x31 0x35 0x50 0x00 0x00 0x00 0x00 0x31
// 0x30 0x2E 0x58 0x57 0x00 0x00 0x00 0x31 0x30 0x2E 0x30 0x37 0x00 0x00 0x00 0x40 0xAF 0x01 0x00 0x06 0x00 0x00 0x00
Expand Down
4 changes: 2 additions & 2 deletions components/jk_bms_ble/jk_bms_ble.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace espbt = esphome::esp32_ble_tracker;

enum ProtocolVersion {
PROTOCOL_VERSION_JK04,
PROTOCOL_VERSION_JK02,
PROTOCOL_VERSION_JK02_24S,
PROTOCOL_VERSION_JK02_32S,
};

Expand Down Expand Up @@ -197,7 +197,7 @@ class JkBmsBle : public esphome::ble_client::BLEClientNode, public PollingCompon
} temperatures_[4];

protected:
ProtocolVersion protocol_version_{PROTOCOL_VERSION_JK02};
ProtocolVersion protocol_version_{PROTOCOL_VERSION_JK02_24S};

binary_sensor::BinarySensor *balancing_binary_sensor_;
binary_sensor::BinarySensor *charging_binary_sensor_;
Expand Down
2 changes: 1 addition & 1 deletion components/jk_bms_ble/number/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

DEFAULT_STEP = 1

# JK02
# JK02_24S
#
# 06 04 03000000 Set balance trig voltage to 0.003
# 1c 04 10000000 Set cell count to 16
Expand Down
2 changes: 1 addition & 1 deletion components/jk_bms_ble/number/jk_number.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ void JkNumber::control(float value) {
return;
}

if (this->parent_->get_protocol_version() == PROTOCOL_VERSION_JK02 && this->jk02_holding_register_) {
if (this->parent_->get_protocol_version() == PROTOCOL_VERSION_JK02_24S && this->jk02_holding_register_) {
uint32_t payload = (uint32_t) (value * this->factor_);
if (this->parent_->write_register(this->jk02_holding_register_, payload, sizeof(payload))) {
this->publish_state(state);
Expand Down
2 changes: 1 addition & 1 deletion components/jk_bms_ble/switch/jk_switch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ void JkSwitch::write_state(bool state) {
return;
}

if (this->parent_->get_protocol_version() == PROTOCOL_VERSION_JK02 && this->jk02_holding_register_) {
if (this->parent_->get_protocol_version() == PROTOCOL_VERSION_JK02_24S && this->jk02_holding_register_) {
if (this->parent_->write_register(this->jk02_holding_register_, (state) ? 0x00000001 : 0x00000000, 0x04)) {
this->publish_state(state);
}
Expand Down
8 changes: 4 additions & 4 deletions esp32-ble-example-multiple-devices.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@ substitutions:
external_components_source: github://syssi/esphome-jk-bms@main
bms0_mac_address: C8:47:8C:E1:E2:E1
bms1_mac_address: C8:47:8C:E1:E2:E2
# Defaults to "JK02" (hardware version >= 6.0 and < 11.0)
# Please use "JK02_24S" if you own a old JK-BMS < hardware version 11.0 (hardware version >= 6.0 and < 11.0)
# Please use "JK02_32S" if you own a new JK-BMS >= hardware version 11.0 (f.e. JK-B2A8S20P hw 11.XW, sw 11.26)
# Please use "JK04" if you have some old JK-BMS <= hardware version 3.0 (f.e. JK-B2A16S hw 3.0, sw. 3.3.0)
bms0_protocol_version: JK02
bms1_protocol_version: JK02
bms0_protocol_version: JK02_32S
bms1_protocol_version: JK02_32S

esphome:
name: ${name}
comment: ${device_description}
project:
name: "syssi.esphome-jk-bms"
version: 1.5.0
version: 2.0.0

esp32:
board: wemos_d1_mini32
Expand Down
6 changes: 3 additions & 3 deletions esp32-ble-example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ substitutions:
device_description: "Monitor and control a JK-BMS via bluetooth"
external_components_source: github://syssi/esphome-jk-bms@main
mac_address: C8:47:8C:E1:E2:E1
# Defaults to "JK02" (hardware version >= 6.0 and < 11.0)
# Please use "JK02_24S" if you own a old JK-BMS < hardware version 11.0 (hardware version >= 6.0 and < 11.0)
# Please use "JK02_32S" if you own a new JK-BMS >= hardware version 11.0 (f.e. JK-B2A8S20P hw 11.XW, sw 11.26)
# Please use "JK04" if you have some old JK-BMS <= hardware version 3.0 (f.e. JK-B2A16S hw 3.0, sw. 3.3.0)
protocol_version: JK02
protocol_version: JK02_32S

esphome:
name: ${name}
comment: ${device_description}
project:
name: "syssi.esphome-jk-bms"
version: 1.5.0
version: 2.0.0

esp32:
board: wemos_d1_mini32
Expand Down
4 changes: 2 additions & 2 deletions esp32-ble-jk04-example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ substitutions:
device_description: "Monitor and control a JK-BMS via bluetooth"
external_components_source: github://syssi/esphome-jk-bms@main
mac_address: C8:47:FF:FF:FF:FF
# Defaults to "JK02" (hardware version >= 6.0 and < 11.0)
# Please use "JK02_24S" if you own a old JK-BMS < hardware version 11.0 (hardware version >= 6.0 and < 11.0)
# Please use "JK02_32S" if you own a new JK-BMS >= hardware version 11.0 (f.e. JK-B2A8S20P hw 11.XW, sw 11.26)
# Please use "JK04" if you have some old JK-BMS <= hardware version 3.0 (f.e. JK-B2A16S hw 3.0, sw. 3.3.0)
protocol_version: JK04
Expand All @@ -13,7 +13,7 @@ esphome:
comment: ${device_description}
project:
name: "syssi.esphome-jk-bms"
version: 1.5.0
version: 2.0.0

esp32:
board: wemos_d1_mini32
Expand Down
2 changes: 1 addition & 1 deletion esp32-ble-scanner.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ esphome:
comment: ${device_description}
project:
name: "syssi.esphome-jk-bms"
version: 1.5.0
version: 2.0.0

esp32:
board: wemos_d1_mini32
Expand Down
6 changes: 3 additions & 3 deletions esp32-ble-uart-hybrid-example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ substitutions:

# BLE settings
mac_address: C8:47:8C:E1:E2:E1
# Defaults to "JK02" (hardware version >= 6.0 and < 11.0)
# Please use "JK02_24S" if you own a old JK-BMS < hardware version 11.0 (hardware version >= 6.0 and < 11.0)
# Please use "JK02_32S" if you own a new JK-BMS >= hardware version 11.0 (f.e. JK-B2A8S20P hw 11.XW, sw 11.26)
# Please use "JK04" if you have some old JK-BMS <= hardware version 3.0 (f.e. JK-B2A16S hw 3.0, sw. 3.3.0)
protocol_version: JK02
protocol_version: JK02_32S

# UART settings
tx_pin: GPIO16
Expand All @@ -19,7 +19,7 @@ esphome:
comment: ${device_description}
project:
name: "syssi.esphome-jk-bms"
version: 1.5.0
version: 2.0.0

esp32:
board: wemos_d1_mini32
Expand Down
4 changes: 2 additions & 2 deletions esp32-ble-v11-example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ substitutions:
device_description: "Monitor and control a JK-BMS v11 via bluetooth"
external_components_source: github://syssi/esphome-jk-bms@main
mac_address: C8:47:8C:E1:E2:E1
# Defaults to "JK02" (hardware version >= 6.0 and < 11.0)
# Please use "JK02_24S" if you own a old JK-BMS < hardware version 11.0 (hardware version >= 6.0 and < 11.0)
# Please use "JK02_32S" if you own a new JK-BMS >= hardware version 11.0 (f.e. JK-B2A8S20P hw 11.XW, sw 11.26)
# Please use "JK04" if you have some old JK-BMS <= hardware version 3.0 (f.e. JK-B2A16S hw 3.0, sw. 3.3.0)
protocol_version: JK02_32S
Expand All @@ -13,7 +13,7 @@ esphome:
comment: ${device_description}
project:
name: "syssi.esphome-jk-bms"
version: 1.5.0
version: 2.0.0

esp32:
board: wemos_d1_mini32
Expand Down
2 changes: 1 addition & 1 deletion esp32-example-multiple-devices.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ esphome:
comment: ${device_description}
project:
name: "syssi.esphome-jk-bms"
version: 1.5.0
version: 2.0.0

esp32:
board: wemos_d1_mini32
Expand Down
2 changes: 1 addition & 1 deletion esp32-example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ esphome:
comment: ${device_description}
project:
name: "syssi.esphome-jk-bms"
version: 1.5.0
version: 2.0.0

esp32:
board: wemos_d1_mini32
Expand Down
2 changes: 1 addition & 1 deletion esp32-heltec-balancer-ble-example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ esphome:
comment: ${device_description}
project:
name: "syssi.esphome-jk-bms"
version: 1.5.0
version: 2.0.0

esp32:
board: wemos_d1_mini32
Expand Down
2 changes: 1 addition & 1 deletion esp8266-example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ esphome:
comment: ${device_description}
project:
name: "syssi.esphome-jk-bms"
version: 1.5.0
version: 2.0.0

esp8266:
board: d1_mini
Expand Down
2 changes: 1 addition & 1 deletion yaml-snippets/esp32-ble-block-traffic.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ esphome:
comment: ${device_description}
project:
name: "syssi.esphome-jk-bms"
version: 1.5.0
version: 2.0.0

esp32:
board: wemos_d1_mini32
Expand Down
8 changes: 5 additions & 3 deletions yaml-snippets/esp32-ble-energy-dashboard.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,17 @@ substitutions:
device_description: "Monitor and control a JK-BMS via bluetooth"
external_components_source: github://syssi/esphome-jk-bms@main
mac_address: C8:47:8C:E1:E2:E1
# Defaults to "JK02". Please use "JK04" if you have some old JK-BMS version (f.e. JK-B2A16S hw 3.0, sw. 3.3.0)
protocol_version: JK02
# Please use "JK02_24S" if you own a old JK-BMS < hardware version 11.0 (hardware version >= 6.0 and < 11.0)
# Please use "JK02_32S" if you own a new JK-BMS >= hardware version 11.0 (f.e. JK-B2A8S20P hw 11.XW, sw 11.26)
# Please use "JK04" if you have some old JK-BMS <= hardware version 3.0 (f.e. JK-B2A16S hw 3.0, sw. 3.3.0)
protocol_version: JK02_32S

esphome:
name: ${name}
comment: ${device_description}
project:
name: "syssi.esphome-jk-bms"
version: 1.5.0
version: 2.0.0

esp32:
board: wemos_d1_mini32
Expand Down

0 comments on commit 363ed49

Please sign in to comment.