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
403 stars 134 forks source link

Disconnecting from bluetooth #512

Open sarzyk opened 1 week ago

sarzyk commented 1 week ago

![Uploading Screenshot_20240624_133918_Allegro.jpg…]() Hi. I bought this esp32 device:

I make everything like in tutorial but I have a problem. The device randomly disconnected all the time. What could be a reason this situation?

rt1970 commented 23 hours ago

On my ESP32 via BLE too. BMS make frequently a beep...

How can i set MQTT Update-Interval?

My BLE-config for JK-Inverter-BMS PB2A16S15P:

esp32_ble_tracker:
  on_ble_advertise:
    then:
      - lambda: |-
          if (x.get_name().rfind("4041", 0) == 0 || x.get_name().rfind("4041", 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: ${mac_address}
    id: client0
    on_passkey_request:
      then:
        - ble_client.passkey_reply:
            id: client0
            passkey: 1234

jk_bms_ble:
  - ble_client_id: client0
    protocol_version: ${protocol_version}
    throttle: 5s
    id: bms0
syssi commented 22 hours ago

The BMS pushes data every 0.5s. You can use the throttle parameter to skip most of the data:

jk_bms_ble:
  - ble_client_id: client0
    protocol_version: ${protocol_version}
    throttle: 60s

This setting publishes a set of measurements once per minute.

IMO this setting is useless:

    on_passkey_request:
      then:
        - ble_client.passkey_reply:
            id: client0
            passkey: 1234

The BLE module of the BMS is unable to do authentication/encryption.

rt1970 commented 7 hours ago

Thank you. I have delete Passkey. Works too.

I have many notify in my Log:

[09:49:05][D][jk_bms_ble:525]: Unknown168: 00.00.00.00.00.00.00.00.00.00.00.00.00.00 (14)
[09:49:05][D][jk_bms_ble:539]: Unknown189: 0x00 0x64
[09:49:05][D][jk_bms_ble:543]: Unknown192: 0x00
[09:49:05][D][jk_bms_ble:545]: Unknown193: 0x00 0xFF (0x00 0x8D)
[09:49:05][D][jk_bms_ble:547]: Unknown195: 0x66 0x40 (0x21 0x40)
[09:49:05][D][sensor:094]: 'jk-bms heating current': Sending state 0.00000 A with 2 decimals of accuracy
[09:49:05][I][jk_bms_ble:570]:   Emergency switch: off
[09:49:05][D][sensor:094]: 'jk-bms temperature sensor 4': Sending state 18.70000 °C with 1 decimals of accuracy
[09:49:05][D][sensor:094]: 'jk-bms temperature sensor 3': Sending state 18.60000 °C with 1 decimals of accuracy
[09:49:05][D][esp32_ble_client:110]: [0] [C8:47:80:16:8D:CE] ESP_GATTC_NOTIFY_EVT
[09:49:05][D][esp32_ble_client:110]: [0] [C8:47:80:16:8D:CE] ESP_GATTC_NOTIFY_EVT
[09:49:05][D][esp32_ble_client:110]: [0] [C8:47:80:16:8D:CE] ESP_GATTC_NOTIFY_EVT
[09:49:05][D][esp32_ble_client:110]: [0] [C8:47:80:16:8D:CE] ESP_GATTC_NOTIFY_EVT
[09:49:05][D][esp32_ble_client:110]: [0] [C8:47:80:16:8D:CE] ESP_GATTC_NOTIFY_EVT
[09:49:05][D][esp32_ble_client:110]: [0] [C8:47:80:16:8D:CE] ESP_GATTC_NOTIFY_EVT
[09:49:06][D][esp32_ble_client:110]: [0] [C8:47:80:16:8D:CE] ESP_GATTC_NOTIFY_EVT
[09:49:06][W][component:237]: Component esp32_ble took a long time for an operation (666 ms).
[09:49:06][W][component:238]: Components should block for at most 30 ms.
WARNING jk-bms-ble @ 192.168.178.35: Connection error occurred: [Errno 104] Connection reset by peer
INFO Processing unexpected disconnect from ESPHome API for jk-bms-ble @ 192.168.178.35
WARNING Disconnected from API

ESP_GATTC_NOTIFY_EVT are many times in my log of ESPHome

syssi commented 6 hours ago

Please decrese the log level to reduce some load by

logger:
  level: INFO