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
480 stars 161 forks source link

ESP32-C3 compile error #166

Closed JesperThorup closed 2 years ago

JesperThorup commented 2 years ago

Trying to use the Lolin Wemos C3 Mini to use the bluetooth, but i'm getting this error on compile:

/data/cache/platformio/packages/toolchain-riscv32-esp/bin/../lib/gcc/riscv32-esp-elf/8.4.0/../../../../riscv32-esp-elf/bin/ld: /data/jk-bms/.pioenvs/jk-bms/src/esphome/components/ble_client/ble_client.o: in functionesphome::ble_client::BLEClient::connect()': /config/esphome/.esphome/build/jk-bms/src/esphome/components/ble_client/ble_client.cpp:87: undefined reference to esp_ble_gattc_open' /data/cache/platformio/packages/toolchain-riscv32-esp/bin/../lib/gcc/riscv32-esp-elf/8.4.0/../../../../riscv32-esp-elf/bin/ld: /data/jk-bms/.pioenvs/jk-bms/src/esphome/components/esp32_ble_tracker/esp32_ble_tracker.o: in functionesphome::esp32_ble_tracker::ESP32BLETracker::startscan(bool)': /config/esphome/.esphome/build/jk-bms/src/esphome/components/esp32_ble_tracker/esp32_ble_tracker.cpp:231: undefined reference to esp_ble_gap_set_scan_params' /data/cache/platformio/packages/toolchain-riscv32-esp/bin/../lib/gcc/riscv32-esp-elf/8.4.0/../../../../riscv32-esp-elf/bin/ld: /config/esphome/.esphome/build/jk-bms/src/esphome/components/esp32_ble_tracker/esp32_ble_tracker.cpp:234: undefined reference toesp_ble_gap_start_scanning' /data/cache/platformio/packages/toolchain-riscv32-esp/bin/../lib/gcc/riscv32-esp-elf/8.4.0/../../../../riscv32-esp-elf/bin/ld: /data/jk-bms/.pioenvs/jk-bms/src/esphome/components/esp32_ble_tracker/esp32_ble_tracker.o: in function esphome::esp32_ble_tracker::ESP32BLETracker::loop()': /config/esphome/.esphome/build/jk-bms/src/esphome/components/esp32_ble_tracker/esp32_ble_tracker.cpp:98: undefined reference toesp_ble_gap_stop_scanning' collect2: error: ld returned 1 exit status *** [/data/jk-bms/.pioenvs/jk-bms/firmware.elf] Error 1`

Does enyone know what that means?

syssi commented 2 years ago

Could you provide your configuration yaml? I would like to know the board section of your configuration to be able to reproduce the issue.

JesperThorup commented 2 years ago

@syssi sure thing...

https://pastebin.com/YTej174c

JesperThorup commented 2 years ago

@syssi Got it working on another board and connected using bluetooth, but all values are 0...

[21:28:07][I][jk_bms_ble:296]: Request status notification [21:28:07][D][jk_bms_ble:1154]: Write register: AA.55.90.EB.96.00.00.00.00.00.00.00.00.00.00.00.00.00.00.10 (20) [21:28:07][C][jk_bms_ble.switch:010]: JkBmsBle Switch 'jk-bms balancer'

[21:28:07][C][ble_switch:035]: BLE Client Switch 'jk-bms enable bluetooth connection'

[21:28:07][C][esp32_ble_tracker:717]: BLE Tracker: [21:28:07][C][esp32_ble_tracker:718]: Scan Duration: 300 s [21:28:07][C][esp32_ble_tracker:719]: Scan Interval: 320.0 ms [21:28:07][C][esp32_ble_tracker:720]: Scan Window: 30.0 ms [21:28:07][C][esp32_ble_tracker:721]: Scan Type: ACTIVE [21:28:07][C][ble_client:035]: BLE Client: [21:28:07][C][ble_client:036]: Address: c8:47:8c:ea:68:14

[21:28:07][C][mdns:095]: Hostname: jk-bms [21:28:07][C][ota:085]: Over-The-Air Updates: [21:28:07][C][ota:086]: Address: 10.0.0.119:3232 [21:28:07][C][api:138]: API Server: [21:28:07][C][api:139]: Address: 10.0.0.119:6053 [21:28:07][C][api:143]: Using noise encryption: NO [21:28:07][I][jk_bms_ble:974]: Settings frame (300 bytes): [21:28:07][D][jk_bms_ble:1001]: Unknown6: 58 02 00 00 (0.000000) [21:28:07][I][jk_bms_ble:1010]: Cell count: 0 [21:28:07][I][jk_bms_ble:1013]: Power off voltage: 0.000000 V [21:28:07][D][jk_bms_ble:1024]: Unknown74: 0.000000 [21:28:07][I][jk_bms_ble:1032]: Start balance voltage: -nan V [21:28:07][D][jk_bms_ble:1035]: Unknown102: -nan [21:28:07][I][jk_bms_ble:1038]: Trigger Delta Voltage: 0.000000 V [21:28:07][I][jk_bms_ble:1041]: Max. balance current: 0.000000 A [21:28:07][D][switch:037]: 'jk-bms balancer': Sending state ON [21:28:07][I][jk_bms_ble:1045]: ADC Vref: unknown V [21:28:08][D][sensor:127]: 'jk-bms cell voltage 1': Sending state 0.00000 V with 3 decimals of accuracy [21:28:08][D][sensor:127]: 'jk-bms cell voltage 2': Sending state 0.00000 V with 3 decimals of accuracy [21:28:08][D][sensor:127]: 'jk-bms cell voltage 3': Sending state 0.00000 V with 3 decimals of accuracy [21:28:08][D][sensor:127]: 'jk-bms cell voltage 4': Sending state 0.00000 V with 3 decimals of accuracy [21:28:08][D][sensor:127]: 'jk-bms cell voltage 5': Sending state 0.00000 V with 3 decimals of accuracy [21:28:08][D][sensor:127]: 'jk-bms cell voltage 6': Sending state 0.00000 V with 3 decimals of accuracy [21:28:08][D][sensor:127]: 'jk-bms cell voltage 7': Sending state 0.00000 V with 3 decimals of accuracy [21:28:08][D][sensor:127]: 'jk-bms cell voltage 8': Sending state 0.00000 V with 3 decimals of accuracy [21:28:08][D][sensor:127]: 'jk-bms cell voltage 9': Sending state 0.00000 V with 3 decimals of accuracy [21:28:08][D][sensor:127]: 'jk-bms cell voltage 10': Sending state 0.00000 V with 3 decimals of accuracy [21:28:08][D][sensor:127]: 'jk-bms cell voltage 11': Sending state 0.00000 V with 3 decimals of accuracy [21:28:08][D][sensor:127]: 'jk-bms cell voltage 12': Sending state 0.00000 V with 3 decimals of accuracy [21:28:08][D][sensor:127]: 'jk-bms cell voltage 13': Sending state 0.00000 V with 3 decimals of accuracy [21:28:08][D][sensor:127]: 'jk-bms cell voltage 14': Sending state 0.00000 V with 3 decimals of accuracy [21:28:08][D][sensor:127]: 'jk-bms cell voltage 15': Sending state 0.00000 V with 3 decimals of accuracy [21:28:08][D][sensor:127]: 'jk-bms cell voltage 16': Sending state 0.00000 V with 3 decimals of accuracy [21:28:08][D][sensor:127]: 'jk-bms min cell voltage': Sending state 0.00000 V with 3 decimals of accuracy [21:28:08][D][sensor:127]: 'jk-bms max cell voltage': Sending state 0.00000 V with 3 decimals of accuracy [21:28:08][D][sensor:127]: 'jk-bms max voltage cell': Sending state 1.00000 with 0 decimals of accuracy [21:28:08][D][sensor:127]: 'jk-bms min voltage cell': Sending state 23.00000 with 0 decimals of accuracy [21:28:08][D][sensor:127]: 'jk-bms total voltage': Sending state 0.00000 V with 2 decimals of accuracy [21:28:08][D][sensor:127]: 'jk-bms average cell voltage': Sending state 0.00000 V with 3 decimals of accuracy [21:28:08][D][sensor:127]: 'jk-bms delta cell voltage': Sending state 0.00000 V with 3 decimals of accuracy [21:28:08][D][jk_bms_ble:737]: Unknown210: 00 03 00 00 (always 0x00 0x00 0x00 0x00) [21:28:08][D][jk_bms_ble:740]: Unknown214: 3C FE A3 01 (0xFF 0xFF: 24 cells?) [21:28:08][D][jk_bms_ble:743]: Unknown218: 00 [21:28:08][D][jk_bms_ble:746]: Unknown219: 00 [21:28:08][D][binary_sensor:036]: 'jk-bms balancing': Sending state OFF [21:28:08][D][text_sensor:067]: 'jk-bms operation status': Sending state 'Idle' [21:28:08][D][jk_bms_ble:754]: Unknown221: 00 [21:28:08][D][sensor:127]: 'jk-bms balancing current': Sending state 0.00000 A with 2 decimals of accuracy [21:28:08][D][jk_bms_ble:761]: Unknown226: 00 00 00 00 00 00 00 (always 0x00...0x00?) [21:28:08][D][jk_bms_ble:765]: Unknown233: 00 00 00 00 (0.000000) [21:28:08][D][jk_bms_ble:769]: Unknown237: 00 00 00 00 (always 0x40 0x00 0x00 0x00?) [21:28:08][D][sensor:127]: 'jk-bms total runtime': Sending state 0.00000 s with 0 decimals of accuracy [21:28:08][D][text_sensor:067]: 'jk-bms total runtime formatted': Sending state '' [21:28:08][D][jk_bms_ble:783]: Unknown290: 00 00 00 00 (always 0x00 0x00 0x00 0x00?) [21:28:08][D][jk_bms_ble:786]: Unknown294: 00 00 00 00 [21:28:08][D][jk_bms_ble:789]: Unknown298: 00 [21:28:10][D][api:102]: Accepted ::FFFF:192.168.0.111 [21:28:10][D][api.connection:861]: Home Assistant 2022.8.4 (::FFFF:192.168.0.111): Connected successfully [21:28:13][D][sensor:127]: 'jk-bms cell voltage 1': Sending state 0.00000 V with 3 decimals of accuracy [21:28:13][D][sensor:127]: 'jk-bms cell voltage 2': Sending state 0.00000 V with 3 decimals of accuracy [21:28:13][D][sensor:127]: 'jk-bms cell voltage 3': Sending state 0.00000 V with 3 decimals of accuracy [21:28:13][D][sensor:127]: 'jk-bms cell voltage 4': Sending state 0.00000 V with 3 decimals of accuracy [21:28:13][D][sensor:127]: 'jk-bms cell voltage 5': Sending state 0.00000 V with 3 decimals of accuracy [21:28:13][D][sensor:127]: 'jk-bms cell voltage 6': Sending state 0.00000 V with 3 decimals of accuracy [21:28:13][D][sensor:127]: 'jk-bms cell voltage 7': Sending state 0.00000 V with 3 decimals of accuracy [21:28:13][D][sensor:127]: 'jk-bms cell voltage 8': Sending state 0.00000 V with 3 decimals of accuracy [21:28:13][D][sensor:127]: 'jk-bms cell voltage 9': Sending state 0.00000 V with 3 decimals of accuracy [21:28:13][D][sensor:127]: 'jk-bms cell voltage 10': Sending state 0.00000 V with 3 decimals of accuracy [21:28:13][D][sensor:127]: 'jk-bms cell voltage 11': Sending state 0.00000 V with 3 decimals of accuracy [21:28:13][D][sensor:127]: 'jk-bms cell voltage 12': Sending state 0.00000 V with 3 decimals of accuracy [21:28:13][D][sensor:127]: 'jk-bms cell voltage 13': Sending state 0.00000 V with 3 decimals of accuracy [21:28:13][D][sensor:127]: 'jk-bms cell voltage 14': Sending state 0.00000 V with 3 decimals of accuracy [21:28:13][D][sensor:127]: 'jk-bms cell voltage 15': Sending state 0.00000 V with 3 decimals of accuracy [21:28:13][D][sensor:127]: 'jk-bms cell voltage 16': Sending state 0.00000 V with 3 decimals of accuracy [21:28:13][D][sensor:127]: 'jk-bms min cell voltage': Sending state 0.00000 V with 3 decimals of accuracy [21:28:13][D][sensor:127]: 'jk-bms max cell voltage': Sending state 0.00000 V with 3 decimals of accuracy [21:28:13][D][sensor:127]: 'jk-bms max voltage cell': Sending state 1.00000 with 0 decimals of accuracy [21:28:13][D][sensor:127]: 'jk-bms min voltage cell': Sending state 23.00000 with 0 decimals of accuracy [21:28:13][D][sensor:127]: 'jk-bms total voltage': Sending state 0.00000 V with 2 decimals of accuracy [21:28:13][D][sensor:127]: 'jk-bms average cell voltage': Sending state 0.00000 V with 3 decimals of accuracy [21:28:13][D][sensor:127]: 'jk-bms delta cell voltage': Sending state 0.00000 V with 3 decimals of accuracy [21:28:13][D][jk_bms_ble:737]: Unknown210: 00 03 00 00 (always 0x00 0x00 0x00 0x00) [21:28:13][D][jk_bms_ble:740]: Unknown214: 71 FE A3 01 (0xFF 0xFF: 24 cells?) [21:28:13][D][jk_bms_ble:743]: Unknown218: 00 [21:28:13][D][jk_bms_ble:746]: Unknown219: 00 [21:28:13][D][text_sensor:067]: 'jk-bms operation status': Sending state 'Idle' [21:28:13][D][jk_bms_ble:754]: Unknown221: 00 [21:28:13][D][sensor:127]: 'jk-bms balancing current': Sending state 0.00000 A with 2 decimals of accuracy [21:28:13][D][jk_bms_ble:761]: Unknown226: 00 00 00 00 00 00 00 (always 0x00...0x00?) [21:28:13][D][jk_bms_ble:765]: Unknown233: 00 00 00 00 (0.000000) [21:28:13][D][jk_bms_ble:769]: Unknown237: 00 00 00 00 (always 0x40 0x00 0x00 0x00?) [21:28:13][D][sensor:127]: 'jk-bms total runtime': Sending state 0.00000 s with 0 decimals of accuracy [21:28:13][D][text_sensor:067]: 'jk-bms total runtime formatted': Sending state '' [21:28:13][D][jk_bms_ble:783]: Unknown290: 00 00 00 00 (always 0x00 0x00 0x00 0x00?) [21:28:13][D][jk_bms_ble:786]: Unknown294: 00 00 00 00 [21:28:13][D][jk_bms_ble:789]: Unknown298: 00

syssi commented 2 years ago

It looks like you have flashed the example for the Heltec smart balancer. Please use the esp32-ble-example.yaml instead to talk to a JK-BMS.

syssi commented 2 years ago

If you are using the esp32-ble-example.yaml already please increase the log level by:

logger:
  level: VERY_VERBOSE
  logs:
    scheduler: DEBUG
    component: DEBUG
    esp32_ble_tracker: DEBUG
    sensor: DEBUG

and provide another log capture. I'm interested in the 300 bytes raw frames (the response of the BMS).

JesperThorup commented 2 years ago

@syssi This is the output with more logging:

https://pastebin.com/6ykSwRWK

syssi commented 2 years ago

Please use protocol_version: JK02 and try again.

syssi commented 2 years ago

It looks like you have used the esp32-ble-jk04-example.yaml as starting point. This is the example configuration for hardware version 4 of the JK-BMS. Please try esp32-ble-example.yaml as starting point.

JesperThorup commented 2 years ago

It works!! :) Thanks..

syssi commented 2 years ago

If you want to use the ESP32-C3 you have to change the board section slightly to re-enable BLE 4.2 feature of the ESP-IDF framework:

esp32:
  board: esp32-c3-devkitm-1
  framework:
    type: esp-idf
    version: latest
    sdkconfig_options:
      CONFIG_BT_BLE_42_FEATURES_SUPPORTED: y