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

Sometime the esp32 lost BT connection #499

Open testpaul999 opened 2 months ago

testpaul999 commented 2 months ago

Hi,

sometime the esp32 will lost his BT connection to the BMS. So I have found this code to reset the esp32

online_status:
      name: "status online"                   
      id: bms0_status
      on_release:
        if:
          condition:
            for:
              time: 2min
              condition:
                binary_sensor.is_off: bms0_status
          then:
            - switch.toggle: esp_reset

but this won’t work I see at the logscreen (web ui) that the esp32 try to reconnect but this are not successful. What I must change here to monitor the BT connection himself?

regards

syssi commented 2 months ago

What do you mean by "it doesn't work"? Does the ESP reboot but the BLE connection cannot be established again because the BMS rejects the new connection?

testpaul999 commented 2 months ago

What do you mean by "it doesn't work"? Does the ESP reboot but the BLE connection cannot be established again because the BMS rejects the new connection?

Sorry, the reboot sims not work. The connectivity los are more them 4h and not 2min. IMG_4592

testpaul999 commented 1 month ago

No this issue occurs again

Message
21:35:48    [I] [esp-idf:000]   
W (708261604) BT_HCI: hcif disc complete: hdl 0x0, rsn 0x3e
21:35:48    [I] [esp-idf:000]   
W (708261721) BT_HCI: hcif disc complete: hdl 0x0, rsn 0x3e
21:35:48    [I] [esp-idf:000]   
W (708261829) BT_HCI: hcif disc complete: hdl 0x0, rsn 0x3e
21:35:49    [I] [esp-idf:000]   
W (708262248) BT_APPL: gattc_conn_cb: if=3 st=0 id=3 rsn=0x3e
21:35:49    [I] [esp-idf:000]   
W (708262256) BT_HCI: hcif disc complete: hdl 0x0, rsn 0x3e
21:35:49    [W] [esp32_ble_client:143]  
[0] [C8:47:80:07:A0:CC] Connection failed, status=133
21:35:51    [W] [jk_bms_ble:238]    
[C8:47:80:07:A0:CC] Not connected
21:35:53    [I] [esp-idf:000]   
E (708266160) BT_BTM: BTM_BleScan scan not ac
21:35:53    [I] [esp-idf:000]   
W (708266166) BT_APPL:  bta_dm_ble_scan stop scan failed, status
21:35:53    [I] [esp32_ble_client:067]  
[0] [C8:47:80:07:A0:CC] 0x00 Attempting BLE connection
21:35:53    [I] [esp-idf:000]   
W (708266644) BT_HCI: hcif disc complete: hdl 0x0, rsn 0x3e
21:35:54    [I] [esp-idf:000]   
W (708268021) BT_HCI: hcif disc complete: hdl 0x0, rsn 0x3e
21:35:55    [I] [esp-idf:000]   
W (708268441) BT_HCI: hcif disc complete: hdl 0x0, rsn 0x3e
21:35:55    [I] [esp-idf:000]   
W (708268548) BT_APPL: gattc_conn_cb: if=3 st=0 id=3 rsn=0x3e
21:35:55    [I] [esp-idf:000]   
W (708268552) BT_HCI: hcif disc complete: hdl 0x0, rsn 0x3e
21:35:55    [W] [esp32_ble_client:143]  
[0] [C8:47:80:07:A0:CC] Connection failed, status=133
21:35:56    [W] [jk_bms_ble:238]    
[C8:47:80:07:A0:CC] Not connected
21:36:00    [I] [esp-idf:000]   
E (708273079) BT_BTM: BTM_BleScan scan not ac
21:36:00    [I] [esp-idf:000]   
W (708273083) BT_APPL:  bta_dm_ble_scan stop scan failed, status
21:36:00    [I] [esp32_ble_client:067]  
[0] [C8:47:80:07:A0:CC] 0x00 Attempting BLE connection
21:36:00    [I] [esp-idf:000]   
W (708273272) BT_HCI: hcif disc complete: hdl 0x0, rsn 0x3e
21:36:00    [I] [esp-idf:000]   
W (708273365) BT_HCI: hcif disc complete: hdl 0x0, rsn 0x3e
21:36:00    [I] [esp-idf:000]   
W (708273482) BT_HCI: hcif disc complete: hdl 0x0, rsn 0x3e
21:36:00    [I] [esp-idf:000]   
W (708273572) BT_APPL: gattc_conn_cb: if=3 st=0 id=3 rsn=0x3e
21:36:00    [I] [esp-idf:000]   
W (708273576) BT_HCI: hcif disc complete: hdl 0x0, rsn 0x3e
21:36:00    [W] [esp32_ble_client:143]  
[0] [C8:47:80:07:A0:CC] Connection failed, status=133
21:36:00    [I] [esp32_ble_client:067]  

a manual reset esp32 works fine but not the automatic one.

regards

syssi commented 1 month ago

This is probably the most important part of your log:

Connection failed, status=133

It looks like something of the BLE connection get cached and isn't invalidated on reconnects. If you reboot the device it works because of the empty cache.

testpaul999 commented 1 month ago

Ok and what can I/we do here? The way between jk-bms and esp32 are 40cm… If we can fix the root question about the reset esp32 it my works for me 🤷🏻‍♂️

regards