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
471 stars 160 forks source link

bluetooth connection attempt loops #269

Closed Septain21 closed 1 year ago

Septain21 commented 1 year ago

Hello

my esp32 is looping on bluetooth connection attempts with my JKBMS. Once out of 100 he connects to it then it's gone again...

What to do ?

Thx

syssi commented 1 year ago

What's the distance between the ESP and the BMS?

Septain21 commented 1 year ago

2 meters

Septain21 commented 1 year ago

can this error message have something to do with it I am on RPI4 and Home assistant

Capture d’écran 2023-03-05 à 21 12 08
syssi commented 1 year ago

Please check the dmesg output of the host. It looks like the out of memory killer did stop the compiler.

Septain21 commented 1 year ago

I don't understand how to do. I'm on an RPI 4 with 4Gb of memory. Do I have to stop integrations in order to leave power for the process to be finalized?

Septain21 commented 1 year ago

Or Do I check sudo dmesg on my rpi ?

syssi commented 1 year ago

The error at your terminal isn't very verbose. It just says "The compiler was killed by something". If it's the out of memory killer of your Linux kernel you should find something about it in the output of sudo dmesg. Is you ESPHome build setup dockerized? Is the ESPHome container probably limited to 1GB memory? The build process requires around 2GB.

Septain21 commented 1 year ago

Hello

Can I show sudo dmesg log here? I am in supervised version with HA

syssi commented 1 year ago

Yes. Feel free to post some logs. This will help a lot! :-)

Septain21 commented 1 year ago

OK this is very long

syssi commented 1 year ago

These lines confirm my assumption:

[14017.113342] oom-kill:constraint=CONSTRAINT_NONE,nodemask=(null),cpuset=docker-edd7c8a36bacf70407b0d20e476355a5838324423d1a1980d710ca706bcbe5fa.scope,mems_allowed=0,global_oom,task_memcg=/system.slice/docker-edd7c8a36bacf70407b0d20e476355a5838324423d1a1980d710ca706bcbe5fa.scope,task=cc1plus,pid=39459,uid=0
[14017.113406] Out of memory: Killed process 39459 (cc1plus) total-vm:369848kB, anon-rss:342560kB, file-rss:516kB, shmem-rss:0kB, UID:0 pgtables:744kB oom_score_adj:200

The cc1plus process was killed by the out of memory killer.

Septain21 commented 1 year ago

oops what to do?

I notice that the bluetooth module of the ESP32 cannot connect to the JKBMS and that the JKBMS through this is no longer detected by other devices. It becomes visible again when I electrically unplug the ESP32. As if this one blocked him.

syssi commented 1 year ago

Yes. The BMS supports just one simultaneous BLE connection. If the Android App is running the ESP32 won't connect anymore and vice versa.

syssi commented 1 year ago

Any news?

Septain21 commented 1 year ago

I don't give up and I fight...

Here are my latest logs:

INFO Reading configuration /config/esphome/jkbms.yaml... INFO Updating https://github.com/syssi/esphome-jk-bms.git@main WARNING The selected Arduino framework version is not the recommended one. If there are connectivity or build issues please remove the manual version. WARNING The selected Arduino framework version is not the recommended one. If there are connectivity or build issues please remove the manual version. INFO Starting log output from jk-bms.local using esphome API INFO Successfully connected to jk-bms.local [13:48:27][I][app:102]: ESPHome version 2023.4.0-dev compiled on Mar 12 2023, 18:40:28 [13:48:27][I][app:104]: Project syssi.esphome-jk-bms version 1.3.0

[13:48:27][C][wifi:362]: Local MAC: 3C:E9:0E:4C:XX:XX [13:48:27][C][wifi:363]: SSID: 'WiFi-Repeater'[redacted] [13:48:27][C][wifi:364]: IP Address: 192.168.0.135 [13:48:27][C][wifi:369]: Signal strength: -56 dB ▂▄▆█

[13:48:27][C][logger:294]: Level: DEBUG [13:48:27][C][logger:295]: Log Baud Rate: 115200 [13:48:27][C][logger:296]: Hardware UART: UART0

[13:48:27][C][jk_bms_ble:055]: Minimum Cell Voltage 'jk-bms min cell voltage' [13:48:27][C][jk_bms_ble:056]: Unit of Measurement: 'V' [13:48:27][C][jk_bms_ble:056]: Accuracy Decimals: 3 [13:48:27][C][jk_bms_ble:057]: Minimum Voltage Cell 'jk-bms min voltage cell' [13:48:27][C][jk_bms_ble:057]: State Class: 'measurement' [13:48:27][C][jk_bms_ble:057]: Unit of Measurement: '' [13:48:27][C][jk_bms_ble:058]: Accuracy Decimals: 0 [13:48:27][C][jk_bms_ble:059]: Accuracy Decimals: 3 [13:48:27][C][jk_bms_ble:060]: Average Cell Voltage 'jk-bms average cell voltage' [13:48:27][C][jk_bms_ble:060]: Device Class: 'voltage' [13:48:27][C][jk_bms_ble:060]: State Class: 'measurement' [13:48:27][C][jk_bms_ble:060]: Unit of Measurement: 'V' [13:48:27][C][jk_bms_ble:060]: Accuracy Decimals: 3 WARNING jk-bms.local: Connection error occurred: Traceback (most recent call last): File "/usr/local/lib/python3.9/dist-packages/aioesphomeapi/connection.py", line 537, in send_message_await_response_complex await fut asyncio.exceptions.CancelledError

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/usr/local/lib/python3.9/dist-packages/aioesphomeapi/connection.py", line 537, in send_message_await_response_complex await fut File "/usr/local/lib/python3.9/dist-packages/async_timeout/init.py", line 129, in aexit self._do_exit(exc_type) File "/usr/local/lib/python3.9/dist-packages/async_timeout/init.py", line 212, in _do_exit raise asyncio.TimeoutError asyncio.exceptions.TimeoutError

The above exception was the direct cause of the following exception:

Traceback (most recent call last): File "/usr/local/lib/python3.9/dist-packages/aioesphomeapi/connection.py", line 320, in _keep_alive_loop await self._ping() File "/usr/local/lib/python3.9/dist-packages/aioesphomeapi/connection.py", line 645, in _ping await self.send_message_await_response(PingRequest(), PingResponse) File "/usr/local/lib/python3.9/dist-packages/aioesphomeapi/connection.py", line 554, in send_message_await_response res = await self.send_message_await_response_complex( File "/usr/local/lib/python3.9/dist-packages/aioesphomeapi/connection.py", line 539, in send_message_await_response_complex raise TimeoutAPIError( aioesphomeapi.core.TimeoutAPIError: Timeout waiting for response for <class 'api_pb2.PingRequest'> after 10.0s INFO Disconnected from ESPHome API for jk-bms.local WARNING Disconnected from API

And sometimes :

INFO Reading configuration /config/esphome/jkbms.yaml... INFO Updating https://github.com/syssi/esphome-jk-bms.git@main WARNING The selected Arduino framework version is not the recommended one. If there are connectivity or build issues please remove the manual version. WARNING The selected Arduino framework version is not the recommended one. If there are connectivity or build issues please remove the manual version. INFO Starting log output from jk-bms.local using esphome API INFO Successfully connected to jk-bms.local [13:50:15][I][app:102]: ESPHome version 2023.4.0-dev compiled on Mar 12 2023, 18:40:28 [13:50:15][I][app:104]: Project syssi.esphome-jk-bms version 1.3.0

[13:50:15][C][wifi:362]: Local MAC: 3C:E9:0E:4C:XX:XX [13:50:15][C][wifi:363]: SSID: 'WiFi-Repeater'[redacted]

[13:50:15][C][logger:294]: Level: DEBUG [13:50:15][C][logger:295]: Log Baud Rate: 115200 [13:50:15][C][jk_bms_ble:056]: Unit of Measurement: 'V' [13:50:15][C][jk_bms_ble:056]: Accuracy Decimals: 3 [13:50:15][C][jk_bms_ble:057]: Minimum Voltage Cell 'jk-bms min voltage cell' [13:50:15][C][jk_bms_ble:057]: State Class: 'measurement' [13:50:15][C][jk_bms_ble:060]: Average Cell Voltage 'jk-bms average cell voltage' [13:50:15][C][jk_bms_ble:060]: Device Class: 'voltage' [13:50:15][C][jk_bms_ble:060]: State Class: 'measurement' [13:50:15][C][jk_bms_ble:060]: Unit of Measurement: 'V' [13:50:15][C][jk_bms_ble:063]: Accuracy Decimals: 3 [13:50:15][C][jk_bms_ble:064]: Cell Voltage 4 'jk-bms cell voltage 4' [13:50:15][C][jk_bms_ble:064]: Device Class: 'voltage' [13:50:15][C][jk_bms_ble:064]: State Class: 'measurement' [13:50:15][C][jk_bms_ble:067]: State Class: 'measurement' [13:50:15][C][jk_bms_ble:067]: Unit of Measurement: 'V' [13:50:15][C][jk_bms_ble:067]: Accuracy Decimals: 3 [13:50:15][C][jk_bms_ble:068]: Cell Voltage 8 'jk-bms cell voltage 8' [13:50:15][C][jk_bms_ble:068]: Device Class: 'voltage' [13:50:15][C][jk_bms_ble:071]: Cell Voltage 11 'jk-bms cell voltage 11' [13:50:15][C][jk_bms_ble:071]: Device Class: 'voltage' [13:50:15][C][jk_bms_ble:071]: State Class: 'measurement' [13:50:15][C][jk_bms_ble:071]: Unit of Measurement: 'V' [13:50:15][C][jk_bms_ble:071]: Accuracy Decimals: 3 [13:50:15][C][jk_bms_ble:074]: Accuracy Decimals: 3 [13:50:15][C][jk_bms_ble:075]: Cell Voltage 15 'jk-bms cell voltage 15' [13:50:15][C][jk_bms_ble:075]: Device Class: 'voltage' [13:50:15][C][jk_bms_ble:075]: State Class: 'measurement' [13:50:15][C][jk_bms_ble:078]: State Class: 'measurement' [13:50:15][C][jk_bms_ble:079]: Cell Voltage 19 'jk-bms cell voltage 19' [13:50:16][C][jk_bms_ble:079]: Device Class: 'voltage' [13:50:16][C][jk_bms_ble:082]: State Class: 'measurement' [13:50:16][C][jk_bms_ble:082]: Unit of Measurement: 'V' [13:50:16][C][jk_bms_ble:082]: Accuracy Decimals: 3 [13:50:16][C][jk_bms_ble:085]: Unit of Measurement: 'Ω' [13:50:17][C][jk_bms_ble:085]: Accuracy Decimals: 3 [13:50:17][C][jk_bms_ble:086]: Cell Resistance 2 'jk-bms cell resistance 2' [13:50:17][C][jk_bms_ble:086]: State Class: 'measurement' [13:50:17][C][jk_bms_ble:086]: Unit of Measurement: 'Ω'

[13:50:17][C][jk_bms_ble.switch:099]: Restore Mode: restore defaults to OFF [13:50:17][C][jk_bms_ble.switch:076]: JkBmsBle Switch 'jk-bms balancer'

[13:50:17][C][jk_bms_ble.switch:099]: Restore Mode: restore defaults to OFF [13:50:17][C][ble_switch:076]: BLE Client Switch 'jk-bms enable bluetooth connection' [13:50:17][C][restart:076]: Restart Switch 'jkbms-esp32'

[13:50:17][C][restart:099]: Restore Mode: restore defaults to OFF [13:50:17][C][esp32_ble:214]: ESP32 BLE: [13:50:17][C][esp32_ble_tracker:591]: BLE Tracker: [13:50:17][C][esp32_ble_tracker:592]: Scan Duration: 300 s [13:50:17][C][esp32_ble_tracker:593]: Scan Interval: 320.0 ms [13:50:17][C][esp32_ble_tracker:594]: Scan Window: 30.0 ms [13:50:17][C][ble_client:027]: BLE Client: [13:50:17][C][ble_client:028]: Address: C8:47:8C:F6:XX:XX

[13:50:17][C][mdns:109]: Hostname: jk-bms [13:50:17][C][ota:093]: Over-The-Air Updates: [13:50:19][C][ota:094]: Address: jk-bms.local:3232 [13:50:19][C][api:138]: API Server: [13:50:19][W][jk_bms_ble:362]: [C8:47:8C:F6:XX:XX] Not connected [13:50:23][W][jk_bms_ble:362]: [C8:47:8C:F6:XX:XX] Not connected [13:50:28][W][jk_bms_ble:362]: [C8:47:8C:F6:XX:XX] Not connected [13:50:33][W][jk_bms_ble:362]: [C8:47:8C:F6:XX:XX] Not connected [13:50:38][W][jk_bms_ble:362]: [C8:47:8C:F6:XX:XX] Not connected

austin202220 commented 1 year ago

Clean the build files and also update your config: change the framework version to 'recommended' instead of latest

esp32: board: esp32dev framework: type: esp-idf version: recommended