syssi / esphome-jk-bms

ESPHome component to monitor and control a Jikong Battery Management System (JK-BMS) via UART-TTL or BLE
Apache License 2.0
405 stars 134 forks source link

Device won't start or connect (ESP32S3) #391

Closed manziman closed 5 months ago

manziman commented 8 months ago

Hi, I'm new to ESPHome and Home Assistant in general. I tried following the tutorials in the ESPHome docs and built my config using the example files here, but I cannot get the device to start properly or connect. Here's my config (you can see which board I'm using there):

substitutions:
  name: jk-bms
  bms0: "${name} Battery 1"
  bms1: "${name} Battery 2"
  device_description: "Monitor and control a JK-BMS via bluetooth"
  external_components_source: github://syssi/esphome-jk-bms@main
  bms0_mac_address: C8:47:80:01:CF:7B
  bms1_mac_address: C8:47:80:01:C6:83
  # Defaults to "JK02" (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_32S
  bms1_protocol_version: JK02_32S

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

esp32:
  board: adafruit_feather_esp32s3_tft
  framework:
    type: esp-idf
  variant: esp32s3

external_components:
  - source: ${external_components_source}
    refresh: 0s

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

ota:

logger:
  level: VERY_VERBOSE
  logs:
    esp32_ble_tracker: VERY_VERBOSE
    jk_bms_ble: VERY_VERBOSE
    scheduler: DEBUG
    component: DEBUG
    sensor: DEBUG
    api.service: INFO
    api: INFO

# If you don't use Home Assistant please remove this `api` section and uncomment the `mqtt` component!
api:

# mqtt:
#   broker: !secret mqtt_host
#   username: !secret mqtt_username
#   password: !secret mqtt_password
#   id: mqtt_client

esp32_ble_tracker:
  on_ble_advertise:
    then:
      - lambda: |-
          if (x.get_name().rfind("JK-", 0) == 0) {
            ESP_LOGI("ble_adv", "New JK-BMS found");
            ESP_LOGI("ble_adv", "  Name: %s", x.get_name().c_str());
            ESP_LOGI("ble_adv", "  MAC address: %s", x.address_str().c_str());
            ESP_LOGD("ble_adv", "  Advertised service UUIDs:");
            for (auto uuid : x.get_service_uuids()) {
              ESP_LOGD("ble_adv", "    - %s", uuid.to_string().c_str());
            }
          }

ble_client:
  - mac_address: ${bms0_mac_address}
    id: client0
  - mac_address: ${bms1_mac_address}
    id: client1

jk_bms_ble:
  - ble_client_id: client0
    protocol_version: ${bms0_protocol_version}
    throttle: 5s
    id: bms0
  - ble_client_id: client1
    protocol_version: ${bms1_protocol_version}
    throttle: 5s
    id: bms1

binary_sensor:
  - platform: jk_bms_ble
    jk_bms_ble_id: bms0
    balancing:
      name: "${bms0} balancing"
    charging:
      name: "${bms0} charging"
    discharging:
      name: "${bms0} discharging"
    online_status:
      name: "${bms0} online status"

  - platform: jk_bms_ble
    jk_bms_ble_id: bms1
    balancing:
      name: "${bms1} balancing"
    charging:
      name: "${bms1} charging"
    discharging:
      name: "${bms1} discharging"
    online_status:
      name: "${bms1} online status"

button:
  - platform: jk_bms_ble
    jk_bms_ble_id: bms0
    retrieve_settings:
      name: "${bms0} retrieve settings"
    retrieve_device_info:
      name: "${bms0} retrieve device info"

  - platform: jk_bms_ble
    jk_bms_ble_id: bms1
    retrieve_settings:
      name: "${bms1} retrieve settings"
    retrieve_device_info:
      name: "${bms1} retrieve device info"

number:
  - platform: jk_bms_ble
    jk_bms_ble_id: bms0
    balance_trigger_voltage:
      name: "${bms0} balance trigger voltage"
    cell_count:
      name: "${bms0} cell count"
    total_battery_capacity:
      name: "${bms0} total battery capacity"
    cell_voltage_overvoltage_protection:
      name: "${bms0} cell voltage overvoltage protection"
    cell_voltage_overvoltage_recovery:
      name: "${bms0} cell voltage overvoltage recovery"
    cell_voltage_undervoltage_protection:
      name: "${bms0} cell voltage undervoltage protection"
    cell_voltage_undervoltage_recovery:
      name: "${bms0} cell voltage undervoltage recovery"
    balance_starting_voltage:
      name: "${bms0} balance starting voltage"
    voltage_calibration:
      name: "${bms0} voltage calibration"
    current_calibration:
      name: "${bms0} current calibration"
    power_off_voltage:
      name: "${bms0} power off voltage"
    max_balance_current:
      name: "${bms0} max balance current"
    max_charge_current:
      name: "${bms0} max charge current"
    max_discharge_current:
      name: "${bms0} max discharge current"

  - platform: jk_bms_ble
    jk_bms_ble_id: bms1
    balance_trigger_voltage:
      name: "${bms1} balance trigger voltage"
    cell_count:
      name: "${bms1} cell count"
    total_battery_capacity:
      name: "${bms1} total battery capacity"
    cell_voltage_overvoltage_protection:
      name: "${bms1} cell voltage overvoltage protection"
    cell_voltage_overvoltage_recovery:
      name: "${bms1} cell voltage overvoltage recovery"
    cell_voltage_undervoltage_protection:
      name: "${bms1} cell voltage undervoltage protection"
    cell_voltage_undervoltage_recovery:
      name: "${bms1} cell voltage undervoltage recovery"
    balance_starting_voltage:
      name: "${bms1} balance starting voltage"
    voltage_calibration:
      name: "${bms1} voltage calibration"
    current_calibration:
      name: "${bms1} current calibration"
    power_off_voltage:
      name: "${bms1} power off voltage"
    max_balance_current:
      name: "${bms1} max balance current"
    max_charge_current:
      name: "${bms1} max charge current"
    max_discharge_current:
      name: "${bms1} max discharge current"

sensor:
  - platform: jk_bms_ble
    jk_bms_ble_id: bms0
    min_cell_voltage:
      name: "${bms0} min cell voltage"
    max_cell_voltage:
      name: "${bms0} max cell voltage"
    min_voltage_cell:
      name: "${bms0} min voltage cell"
    max_voltage_cell:
      name: "${bms0} max voltage cell"
    delta_cell_voltage:
      name: "${bms0} delta cell voltage"
    average_cell_voltage:
      name: "${bms0} average cell voltage"
    cell_voltage_1:
      name: "${bms0} cell voltage 1"
    cell_voltage_2:
      name: "${bms0} cell voltage 2"
    cell_voltage_3:
      name: "${bms0} cell voltage 3"
    cell_voltage_4:
      name: "${bms0} cell voltage 4"
    cell_voltage_5:
      name: "${bms0} cell voltage 5"
    cell_voltage_6:
      name: "${bms0} cell voltage 6"
    cell_voltage_7:
      name: "${bms0} cell voltage 7"
    cell_voltage_8:
      name: "${bms0} cell voltage 8"
    cell_voltage_9:
      name: "${bms0} cell voltage 9"
    cell_voltage_10:
      name: "${bms0} cell voltage 10"
    cell_voltage_11:
      name: "${bms0} cell voltage 11"
    cell_voltage_12:
      name: "${bms0} cell voltage 12"
    cell_voltage_13:
      name: "${bms0} cell voltage 13"
    cell_voltage_14:
      name: "${bms0} cell voltage 14"
    cell_voltage_15:
      name: "${bms0} cell voltage 15"
    cell_voltage_16:
      name: "${bms0} cell voltage 16"
    cell_resistance_1:
      name: "${bms0} cell resistance 1"
    cell_resistance_2:
      name: "${bms0} cell resistance 2"
    cell_resistance_3:
      name: "${bms0} cell resistance 3"
    cell_resistance_4:
      name: "${bms0} cell resistance 4"
    cell_resistance_5:
      name: "${bms0} cell resistance 5"
    cell_resistance_6:
      name: "${bms0} cell resistance 6"
    cell_resistance_7:
      name: "${bms0} cell resistance 7"
    cell_resistance_8:
      name: "${bms0} cell resistance 8"
    cell_resistance_9:
      name: "${bms0} cell resistance 9"
    cell_resistance_10:
      name: "${bms0} cell resistance 10"
    cell_resistance_11:
      name: "${bms0} cell resistance 11"
    cell_resistance_12:
      name: "${bms0} cell resistance 12"
    cell_resistance_13:
      name: "${bms0} cell resistance 13"
    cell_resistance_14:
      name: "${bms0} cell resistance 14"
    cell_resistance_15:
      name: "${bms0} cell resistance 15"
    cell_resistance_16:
      name: "${bms0} cell resistance 16"
    total_voltage:
      name: "${bms0} total voltage"
    current:
      name: "${bms0} current"
    power:
      name: "${bms0} power"
    charging_power:
      name: "${bms0} charging power"
    discharging_power:
      name: "${bms0} discharging power"
    temperature_sensor_1:
      name: "${bms0} temperature sensor 1"
    temperature_sensor_2:
      name: "${bms0} temperature sensor 2"
    power_tube_temperature:
      name: "${bms0} power tube temperature"
    state_of_charge:
      name: "${bms0} state of charge"
    capacity_remaining:
      name: "${bms0} capacity remaining"
    total_battery_capacity_setting:
      name: "${bms0} total battery capacity setting"
    charging_cycles:
      name: "${bms0} charging cycles"
    total_charging_cycle_capacity:
      name: "${bms0} total charging cycle capacity"
    total_runtime:
      name: "${bms0} total runtime"
    balancing_current:
      name: "${bms0} balancing current"
    errors_bitmask:
      name: "${bms0} errors bitmask"

  - platform: jk_bms_ble
    jk_bms_ble_id: bms1
    min_cell_voltage:
      name: "${bms1} min cell voltage"
    max_cell_voltage:
      name: "${bms1} max cell voltage"
    min_voltage_cell:
      name: "${bms1} min voltage cell"
    max_voltage_cell:
      name: "${bms1} max voltage cell"
    delta_cell_voltage:
      name: "${bms1} delta cell voltage"
    average_cell_voltage:
      name: "${bms1} average cell voltage"
    cell_voltage_1:
      name: "${bms1} cell voltage 1"
    cell_voltage_2:
      name: "${bms1} cell voltage 2"
    cell_voltage_3:
      name: "${bms1} cell voltage 3"
    cell_voltage_4:
      name: "${bms1} cell voltage 4"
    cell_voltage_5:
      name: "${bms1} cell voltage 5"
    cell_voltage_6:
      name: "${bms1} cell voltage 6"
    cell_voltage_7:
      name: "${bms1} cell voltage 7"
    cell_voltage_8:
      name: "${bms1} cell voltage 8"
    cell_voltage_9:
      name: "${bms1} cell voltage 9"
    cell_voltage_10:
      name: "${bms1} cell voltage 10"
    cell_voltage_11:
      name: "${bms1} cell voltage 11"
    cell_voltage_12:
      name: "${bms1} cell voltage 12"
    cell_voltage_13:
      name: "${bms1} cell voltage 13"
    cell_voltage_14:
      name: "${bms1} cell voltage 14"
    cell_voltage_15:
      name: "${bms1} cell voltage 15"
    cell_voltage_16:
      name: "${bms1} cell voltage 16"
    cell_resistance_1:
      name: "${bms1} cell resistance 1"
    cell_resistance_2:
      name: "${bms1} cell resistance 2"
    cell_resistance_3:
      name: "${bms1} cell resistance 3"
    cell_resistance_4:
      name: "${bms1} cell resistance 4"
    cell_resistance_5:
      name: "${bms1} cell resistance 5"
    cell_resistance_6:
      name: "${bms1} cell resistance 6"
    cell_resistance_7:
      name: "${bms1} cell resistance 7"
    cell_resistance_8:
      name: "${bms1} cell resistance 8"
    cell_resistance_9:
      name: "${bms1} cell resistance 9"
    cell_resistance_10:
      name: "${bms1} cell resistance 10"
    cell_resistance_11:
      name: "${bms1} cell resistance 11"
    cell_resistance_12:
      name: "${bms1} cell resistance 12"
    cell_resistance_13:
      name: "${bms1} cell resistance 13"
    cell_resistance_14:
      name: "${bms1} cell resistance 14"
    cell_resistance_15:
      name: "${bms1} cell resistance 15"
    cell_resistance_16:
      name: "${bms1} cell resistance 16"
    total_voltage:
      name: "${bms1} total voltage"
    current:
      name: "${bms1} current"
    power:
      name: "${bms1} power"
    charging_power:
      name: "${bms1} charging power"
    discharging_power:
      name: "${bms1} discharging power"
    temperature_sensor_1:
      name: "${bms1} temperature sensor 1"
    temperature_sensor_2:
      name: "${bms1} temperature sensor 2"
    power_tube_temperature:
      name: "${bms1} power tube temperature"
    state_of_charge:
      name: "${bms1} state of charge"
    capacity_remaining:
      name: "${bms1} capacity remaining"
    total_battery_capacity_setting:
      name: "${bms1} total battery capacity setting"
    charging_cycles:
      name: "${bms1} charging cycles"
    total_charging_cycle_capacity:
      name: "${bms1} total charging cycle capacity"
    total_runtime:
      name: "${bms1} total runtime"
    balancing_current:
      name: "${bms1} balancing current"
    errors_bitmask:
      name: "${bms1} errors bitmask"

switch:
#  - platform: jk_bms_ble
#    jk_bms_ble_id: bms0
#    charging:
#      name: "${bms0} charging"
#    discharging:
#      name: "${bms0} discharging"
#    balancer:
#      name: "${bms0} balancer"
#
#  - platform: jk_bms_ble
#    jk_bms_ble_id: bms1
#    charging:
#      name: "${bms1} charging"
#    discharging:
#      name: "${bms1} discharging"
#    balancer:
#      name: "${bms1} balancer"

  - platform: ble_client
    ble_client_id: client0
    name: "${bms0} enable bluetooth connection"
  - platform: ble_client
    ble_client_id: client1
    name: "${bms1} enable bluetooth connection"

text_sensor:
  - platform: jk_bms_ble
    jk_bms_ble_id: bms0
    errors:
      name: "${bms0} errors"
    total_runtime_formatted:
      name: "${bms0} total runtime formatted"

  - platform: jk_bms_ble
    jk_bms_ble_id: bms1
    errors:
      name: "${bms1} errors"
    total_runtime_formatted:
      name: "${bms1} total runtime formatted"

When I flash the device with this config, all I get is some vague fast boot message over and over again in the terminal:

[17:37:19]ESP-ROM:esp32s3-20210327
[17:37:19]Build:Mar 27 2021
[17:37:19]rst:0x7 (TG0WDT_SYS_RST),boot:0x8 (SPI_FAST_FLASH_BOOT)
[17:37:19]Saved PC:0x400454d5
[17:37:19]SPIWP:0xee
[17:37:19]mode:QIO, clock div:1
[17:37:19]load:0x3fce3808,len:0x162c
[17:37:19]ets_loader.c 78 

To me this appeared to be a boot loop. On another forum I found a potential solution by changing the flash mode in the esphome config:

esphome:
  name: ${name}
  comment: ${device_description}
  project:
    name: "syssi.esphome-jk-bms"
    version: 1.5.0
  platformio_options:
    board_build.flash_mode: dio

This at least got rid of the above boot loop, but now I get this output, which simply hangs on the last line and never proceeds - no helpful log output:

[17:47:40]I (103) esp_image: segment 0: paddr=00010020 vaddr=3c0e00I (154) esp_image: segment 1: paddr=00045cd8 vaddr=3fc981d0 size=04334h ( 17204) load
[17:47:40]I (157) esp_image: segment 2: paddr=0004a014 vaddr=40374000 size=06004h ( 24580) load
[17:47:40]I (165) esp_image: segment 3: paddr=00050020 vaddr=42000020 size=dd43ch (906300) map
[17:47:40]I (330) esp_image: segment 4: paddr=0012d464 vaddr=4037a004 size=0e1c0h ( 57792) load
[17:47:40]I (351) boot: Loaded app from partition at offset 0x10000
[17:47:40]I (389) boot: Set actual ota_seq=1 in otadata[0]
[17:47:40]I (390) boot: Disabling RNG early entropy source...
[17:47:40]I (400) cpu_start: Pro cpu up.
[17:47:40]I (400) cpu_start: Starting app cpu, entry point is 0x40375d3c
[17:47:40]I (0) cpu_start: App cpu up.
[17:47:41]I (414) cpu_start: Pro cpu start user code
[17:47:41]I (415) cpu_start: cpu freq: 160000000
[17:47:41]I (415) cpu_start: Application information:
[17:47:41]I (417) cpu_start: Project name:     jk-bms
[17:47:41]I (422) cpu_start: App version:      2023.10.6
[17:47:41]I (427) cpu_start: Compile time:     Nov  8 2023 17:42:06
[17:47:41]I (433) cpu_start: ELF file SHA256:  287202d9812d6a34...
[17:47:41]I (439) cpu_start: ESP-IDF:          4.4.5
[17:47:41]I (444) cpu_start: Min chip rev:     v0.0
[17:47:41]I (449) cpu_start: Max chip rev:     v0.99 
[17:47:41]I (454) cpu_start: Chip rev:         v0.1
[17:47:41]I (458) heap_init: Initializing. RAM available for dynamic allocation:
[17:47:41]I (466) heap_init: At 3FCA3E30 len 000458E0 (278 KiB): D/IRAM
[17:47:41]I (472) heap_init: At 3FCE9710 len 00005724 (21 KiB): STACK/DIRAM
[17:47:41]I (479) heap_init: At 3FCF0000 len 00008000 (32 KiB): DRAM
[17:47:41]I (485) heap_init: At 600FE000 len 00002000 (8 KiB): RTCRAM
[17:47:41]I (492) spi_flash: detected chip: generic
[17:47:41]I (496) spi_flash: flash io: dio
[17:47:41]I (501) sleep: Configure to isolate all GPIO pins in sleep state
[17:47:41]I (507) sleep: Enable automatic switching of GPIO sleep configuration
[17:47:41]I (514) coexist: coexist rom version e7ae62f
[17:47:41]I (519) cpu_start: Starting scheduler on PRO CPU.
[17:47:41]I (0) cpu_start: Starting scheduler on APP CPU.

Anyone have any ideas what's going on?

syssi commented 8 months ago

Please replace the ESP32S3 with a full featured ESP32. I guess this will fix the issue. Unfortunately I don't know the relevant differences of the ESP models to explain the root cause.

giangy11 commented 7 months ago

Hi, for me it's working with esp32-s3 (this model: https://www.waveshare.com/wiki/ESP32-S3-Pico) if you want I can attach here my yaml config