Louisvdw / dbus-serialbattery

Battery Monitor driver for serial battery in VenusOS GX systems
MIT License
541 stars 165 forks source link

JKBMS BLE unstable #768

Closed githubfrance closed 1 year ago

githubfrance commented 1 year ago

Describe the bug

Hi, "With a USB connection, everything is OK. Thank you again for this excellent work. However, the number of USB ports is not sufficient to my project, so I have to use the BLE connection for the batteries. As you can see below, the Raspberry Pi detects both batteries. I have added the two MAC addresses in config.ini and reinstalled the latest version. The battery data is collected once, but then nothing happens. Did I forget something?"

How to reproduce

Steps to reproduce the behavior:

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Expected behavior

Same behavior as connected to USB

Driver version

1.0.20230531

Venus OS device type

Raspberry Pi

Venus OS version

V3.0.1

BMS type

JKBMS / Heltec BMS

Cell count

4

Connection type

Please select

Config file

[DEFAULT]

; If you want to add custom values/settings, then check the values/settings you want to change in "config.default.ini"
; and insert them below to persist future driver updates.

; Example (remove the semicolon ";" to uncomment and activate the value/setting):
MAX_BATTERY_CHARGE_CURRENT = 60.0
MAX_BATTERY_DISCHARGE_CURRENT = 200.0

MIN_CELL_VOLTAGE   = 2.900
MAX_CELL_VOLTAGE   = 3.550
FLOAT_CELL_VOLTAGE = 3.450

;Device C8:47:8C:ED:06:11 JKBMS-Heating
;Device C8:47:8C:EE:29:AF JKBMS-DISPLAY

;Discovered device  c8:47:8c:ed:06:11
;Discovered device  c8:47:8c:ee:29:af

BLUETOOTH_BMS = Jkbms_Ble C8:47:8C:ED:06:11, Jkbms_Ble C8:47:8C:EE:29:AF
BLOCK_ON_DISCONNECT = False
TIME_TO_GO_ENABLE = True
BMS_TYPE = Jkbms

Relevant log output

@4000000064c6110804d7400c Missing device address argument
@4000000064c6110936b3884c INFO:SerialBattery:Starting dbus-serialbattery
@4000000064c6110936c23dec INFO:SerialBattery:dbus-serialbattery v1.0.20230531
@4000000064c6110d18ef721c INFO:SerialBattery:Init of Jkbms_Ble at C8:47:8C:ED:06:11
@4000000064c6110d18fb12ac INFO:SerialBattery:Test of Jkbms_Ble at C8:47:8C:ED:06:11
@4000000064c611230e439a8c ERROR:SerialBattery:ERROR >>> No battery connection at Jkbms_Ble
@4000000064c611230ed5ef7c 
@4000000064c611230ed60ebc connect and scrape on address: C8:47:8C:ED:06:11
@4000000064c611230ed61a74 btloop
@4000000064c611230ed62244 reconnect
@4000000064c611230ed6262c Exiting bt-loop
@4000000064c611231fe59c7c Missing device address argument
@4000000064c61124362efab4 INFO:SerialBattery:Starting dbus-serialbattery
@4000000064c61124363f0814 INFO:SerialBattery:dbus-serialbattery v1.0.20230531
@4000000064c6112510619c74 INFO:SerialBattery:Init of Jkbms_Ble at C8:47:8C:ED:06:11
@4000000064c6112510689984 INFO:SerialBattery:Test of Jkbms_Ble at C8:47:8C:ED:06:11
@4000000064c6112a26ec12bc ERROR:SerialBattery:No Jkbms_Ble found at C8:47:8C:ED:06:11
@4000000064c6112a26f7bf04 ERROR:SerialBattery:ERROR >>> No battery connection at Jkbms_Ble
@4000000064c6112a26fb5ccc 
@4000000064c6112a38dadcec Missing device address argument
@4000000064c6112c0430d67c INFO:SerialBattery:Starting dbus-serialbattery
@4000000064c6112c0442cc24 INFO:SerialBattery:dbus-serialbattery v1.0.20230531
@4000000064c6112c1902abfc INFO:SerialBattery:Init of Jkbms_Ble at C8:47:8C:ED:06:11
@4000000064c6112c190cfc9c INFO:SerialBattery:Test of Jkbms_Ble at C8:47:8C:ED:06:11
@4000000064c611440d83f024 ERROR:SerialBattery:ERROR >>> No battery connection at Jkbms_Ble
@4000000064c611440d875f0c 
@4000000064c611440d8766dc connect and scrape on address: C8:47:8C:ED:06:11
@4000000064c611440d877294 btloop
@4000000064c611440d877a64 reconnect
@4000000064c611440d878234 Exiting bt-loop
@4000000064c611441d8ac844 Missing device address argument
@4000000064c6114523524e14 INFO:SerialBattery:Starting dbus-serialbattery
@4000000064c611452360638c INFO:SerialBattery:dbus-serialbattery v1.0.20230531
@4000000064c6114536d36874 INFO:SerialBattery:Init of Jkbms_Ble at C8:47:8C:ED:06:11
@4000000064c6114536df2844 INFO:SerialBattery:Test of Jkbms_Ble at C8:47:8C:ED:06:11
@4000000064c6114b12de8b24 ERROR:SerialBattery:No Jkbms_Ble found at C8:47:8C:ED:06:11
@4000000064c6114b12e6dc0c ERROR:SerialBattery:ERROR >>> No battery connection at Jkbms_Ble
@4000000064c6114b12e9d5c4 
@4000000064c6114b22ff57cc Missing device address argument
@4000000064c6114c3194777c INFO:SerialBattery:Starting dbus-serialbattery
@4000000064c6114c31a392ac INFO:SerialBattery:dbus-serialbattery v1.0.20230531
@4000000064c6114d0a51de5c INFO:SerialBattery:Init of Jkbms_Ble at C8:47:8C:ED:06:11
@4000000064c6114d0a596424 INFO:SerialBattery:Test of Jkbms_Ble at C8:47:8C:ED:06:11
@4000000064c6115c2e3b599c ERROR:SerialBattery:ERROR >>> No battery connection at Jkbms_Ble
@4000000064c6115c2e3ed43c 
@4000000064c6115c2e3edc0c connect and scrape on address: C8:47:8C:ED:06:11
@4000000064c6115c2e3eebac btloop
@4000000064c6115c2e3eef94 reconnect
@4000000064c6115c2e3ef764 Exiting bt-loop
@4000000064c6115d035320ac Missing device address argument
@4000000064c6115e0bf43804 INFO:SerialBattery:Starting dbus-serialbattery
@4000000064c6115e0c0366bc INFO:SerialBattery:dbus-serialbattery v1.0.20230531
@4000000064c6115e20e921fc INFO:SerialBattery:Init of Jkbms_Ble at C8:47:8C:ED:06:11
@4000000064c6115e20f00f6c INFO:SerialBattery:Test of Jkbms_Ble at C8:47:8C:ED:06:11
@4000000064c6116337232e54 ERROR:SerialBattery:No Jkbms_Ble found at C8:47:8C:ED:06:11
@4000000064c6116337bca764 ERROR:SerialBattery:ERROR >>> No battery connection at Jkbms_Ble
@4000000064c6116337bcc6a4 
@4000000064c611640c4fe0dc Missing device address argument
@4000000064c611640c50466c [CHG] Device D3:DF:3D:AF:B3:C6 RSSI: -91
@4000000064c6116514db8404 INFO:SerialBattery:Starting dbus-serialbattery
@4000000064c6116514eb4efc INFO:SerialBattery:dbus-serialbattery v1.0.20230531
@4000000064c6116528d5b664 INFO:SerialBattery:Init of Jkbms_Ble at C8:47:8C:ED:06:11
@4000000064c6116528dc9fec INFO:SerialBattery:Test of Jkbms_Ble at C8:47:8C:ED:06:11
@4000000064c6116b037f60cc ERROR:SerialBattery:[org.bluez.Error.Failed] No discovery started
@4000000064c6116b03880b8c ERROR:SerialBattery:ERROR >>> No battery connection at Jkbms_Ble
@4000000064c6116b038bbcdc 
@4000000064c6116b189ee504 Missing device address argument
@4000000064c6116c2204fa0c INFO:SerialBattery:Starting dbus-serialbattery
@4000000064c6116c22149624 INFO:SerialBattery:dbus-serialbattery v1.0.20230531
@4000000064c6116c363d5a64 INFO:SerialBattery:Init of Jkbms_Ble at C8:47:8C:ED:06:11
@4000000064c6116c3645c2bc INFO:SerialBattery:Test of Jkbms_Ble at C8:47:8C:ED:06:11
@4000000064c61172110fa33c ERROR:SerialBattery:No Jkbms_Ble found at C8:47:8C:ED:06:11
@4000000064c6117211189c1c ERROR:SerialBattery:ERROR >>> No battery connection at Jkbms_Ble
@4000000064c61172111be3f4 
@4000000064c61172214b6a24 Missing device address argument
@4000000064c61173361807b4 INFO:SerialBattery:Starting dbus-serialbattery
@4000000064c61173362cb894 INFO:SerialBattery:dbus-serialbattery v1.0.20230531
@4000000064c611741298f2bc INFO:SerialBattery:Init of Jkbms_Ble at C8:47:8C:ED:06:11
@4000000064c6117412a51c04 INFO:SerialBattery:Test of Jkbms_Ble at C8:47:8C:ED:06:11
@4000000064c6117d306021e4 INFO:SerialBattery:Jkbms_Ble found!
@4000000064c6117d306bce2c INFO:SerialBattery:BAT: JKBMS 11.XW 4 cells (20230408)
@4000000064c6117d307ee0fc INFO:SerialBattery:Connection established to Jkbms_Ble
@4000000064c6117d30866e94 INFO:SerialBattery:Battery Jkbms_Ble connected to dbus from c8478ced0611
@4000000064c6117d308ce6d4 INFO:SerialBattery:========== Settings ==========
@4000000064c6117d3094746c INFO:SerialBattery:> Connection voltage: 13.95V | Current: 74.6A | SoC: 100%
@4000000064c6117d309b811c INFO:SerialBattery:> Cell count: 4 | Cells populated: 4
@4000000064c6117d30a29d6c INFO:SerialBattery:> LINEAR LIMITATION ENABLE: True
@4000000064c6117d30aa0bc4 INFO:SerialBattery:> MAX BATTERY CHARGE CURRENT: 60.0A | MAX BATTERY DISCHARGE CURRENT: 200.0A
@4000000064c6117d30b12814 INFO:SerialBattery:> MAX BATTERY CHARGE CURRENT: 150.0A | MAX BATTERY DISCHARGE CURRENT: 200.0A (read from BMS)
@4000000064c6117d30b8196c INFO:SerialBattery:> CVCM:     True
@4000000064c6117d30c2a0bc INFO:SerialBattery:> MIN CELL VOLTAGE: 2.9V | MAX CELL VOLTAGE: 3.55V
@4000000064c6117d30c9f3bc INFO:SerialBattery:> CCCM CV:  True  | DCCM CV:  True
@4000000064c6117d30d11bc4 INFO:SerialBattery:> CCCM T:   True  | DCCM T:   True
@4000000064c6117d30d83bfc INFO:SerialBattery:> CCCM SOC: True  | DCCM SOC: True
@4000000064c6117d30dee704 INFO:SerialBattery:Serial Number/Unique Identifier: 3020744361
@4000000064c6117d334213f4 INFO:SerialBattery:DeviceInstance = 4
@4000000064c6117d334534bc INFO:SerialBattery:com.victronenergy.battery.c8478ced0611
@4000000064c6117d335238c4 INFO:SerialBattery:BAT: JKBMS 11.XW 4 cells (20230408)
@4000000064c6117d3538716c INFO:SerialBattery:publish config values = 1
@4000000064c612650ef73704 INFO:SerialBattery:Jkbms_Ble: Bluetooth died
@4000000064c612650efffd1c INFO:SerialBattery:Reset of Bluetooth triggered
@4000000064c612650f079e3c INFO:SerialBattery:Scraping ended, issuing sys-commands
@4000000064c61267154a5b04 Starting bluetooth: bluetoothd.
@4000000064c612671681601c INFO:SerialBattery:Bluetooth should have been restarted
@4000000064c612671786646c Traceback (most recent call last):
@4000000064c6126717871434   File "/opt/victronenergy/dbus-serialbattery/dbushelper.py", line 361, in publish_battery
@4000000064c61267178727bc     success = self.battery.refresh_data()
@4000000064c6126717873374   File "/opt/victronenergy/dbus-serialbattery/bms/jkbms_ble.py", line 162, in refresh_data
@4000000064c61267178746fc     self.jk.start_scraping()
@4000000064c6126717874ecc   File "/opt/victronenergy/dbus-serialbattery/bms/jkbms_brn.py", line 366, in start_scraping
@4000000064c612671789238c     self.bt_thread.start()
@4000000064c6126717892f44   File "/usr/lib/python3.8/threading.py", line 848, in start
@4000000064c6126717893ee4     raise RuntimeError("threads can only be started once")
@4000000064c6126717894e84 RuntimeError: threads can only be started once
@4000000064c61267178b7d1c 
@4000000064c61267178b84ec connect and scrape on address: C8:47:8C:ED:06:11
@4000000064c61267178b90a4 btloop
@4000000064c61267178b9874 reconnect
@4000000064c61267178b9c5c 
@4000000064c61267178ba044 btloop
@4000000064c61267178ba814 reconnect
@4000000064c61267178babfc 
@4000000064c61267178bb3cc btloop
@4000000064c61267178bb7b4 reconnect
@4000000064c61267178bbf84 Exiting bt-loop
@4000000064c612672bce1a8c Missing device address argument
@4000000064c6126836da6d54 INFO:SerialBattery:Starting dbus-serialbattery
@4000000064c6126836ede1cc INFO:SerialBattery:dbus-serialbattery v1.0.20230531
@4000000064c6126910312634 INFO:SerialBattery:Init of Jkbms_Ble at C8:47:8C:ED:06:11
@4000000064c6126910389874 INFO:SerialBattery:Test of Jkbms_Ble at C8:47:8C:ED:06:11
@4000000064c61322095e3f2c ERROR:SerialBattery:[org.freedesktop.DBus.Error.NoReply] Message recipient disconnected from message bus without replying
@4000000064c6132209667c8c ERROR:SerialBattery:ERROR >>> No battery connection at Jkbms_Ble
@4000000064c61322096a2ddc 
@4000000064c613c722918e54 Missing device address argument
@4000000064c613c829eb4514 INFO:SerialBattery:Starting dbus-serialbattery
@4000000064c613c829f9fe9c INFO:SerialBattery:dbus-serialbattery v1.0.20230531
@4000000064c613c9024a6b0c INFO:SerialBattery:Init of Jkbms_Ble at C8:47:8C:ED:06:11
@4000000064c613c902513554 INFO:SerialBattery:Test of Jkbms_Ble at C8:47:8C:ED:06:11
@4000000064c6184b398113b4 Terminated
@4000000064c6184c09bf6a2c Missing device address argument
@4000000064c6184d15fe41b4 INFO:SerialBattery:Starting dbus-serialbattery
@4000000064c6184d160e723c INFO:SerialBattery:dbus-serialbattery v1.0.20230531
@4000000064c6184d2b3f115c INFO:SerialBattery:Init of Jkbms_Ble at C8:47:8C:ED:06:11
@4000000064c6184d2b47c3ec INFO:SerialBattery:Test of Jkbms_Ble at C8:47:8C:ED:06:11
@4000000064c6185108cf60f4 ERROR:SerialBattery:[org.freedesktop.DBus.Error.NoReply] Message recipient disconnected from message bus without replying
@4000000064c6185108d82324 ERROR:SerialBattery:ERROR >>> No battery connection at Jkbms_Ble
@4000000064c6185108dbcca4

Any other information that may be helpful

No response

mr-manuel commented 1 year ago

provide the logs in the correct form

See https://louisvdw.github.io/dbus-serialbattery/troubleshoot/#serial-bms-connection, I copied the important notice over here for you:

💡 If you are opening an issue or posting your logs somewhere please make sure you execute the complete commands to get the logs, including tai64nlocal. Without readable timestamps we cannot help you.

Have you tried the latest nightly from the dev branch?

See https://github.com/Louisvdw/dbus-serialbattery/issues/765#issuecomment-1656802054

mr-manuel commented 1 year ago

By the way: You don‘t have to create a new issue and close this one. You can edit it or add the correct information as a comment.

githubfrance commented 1 year ago

Hi, Perhaps I found a way to get the JKBMS connected via BLE. I tuned off the BMSs and the Raspberry then started again the tow batteries, and the Raspberry. This time, I could get the batteries on the venus.

Screenshot 2023-07-30 at 13 11 21

After a while the RUUVY came back to the Venus.

Screenshot 2023-07-30 at 13 12 50

After one hour run the batteries remains active on Venus OS Will reproduce this procedure to see it is the right way. Bests Patrick

githubfrance commented 1 year ago

Bad luck, the batteries were unconnected after a while without any action on the batteries nor the VenosOS.

Screenshot 2023-07-30 at 14 42 53
mr-manuel commented 1 year ago

Unfortunately I don't know why you don't get it, but this is not that what was requested. Probably a language barrier. Try to read again https://github.com/Louisvdw/dbus-serialbattery/issues/768#issuecomment-1657097367.

I also don't know where you picked up tail -F -n 100 /data/log/dbus-ble-sensors/current | grep dbus-ble-sensors | tai64nlocal. This has nothing to do with this driver.

Anyway only one Bluetooth device can be connected at the same time to the BMS.

githubfrance commented 1 year ago

Hi, this time the log file are as you wan, with the time stamp :-)

bat1.log bat0.log

mr-manuel commented 1 year ago

I still don't know, if you tried the nightly from the dev branch...

Somehow the service files are not generated correctly. Did you get any error message on installing?

Post the output of cat /service/dbus-blebattery.*/run. Maybe it's services instead of service, can't check right now.

githubfrance commented 1 year ago

Hi I had no errors on the installation

root@raspberrypi2:~# cat /service/dbus-blebattery.0/run
#!/bin/sh
exec 2>&1
bluetoothctl disconnect
python /opt/victronenergy/dbus-serialbattery/dbus-serialbattery.py Jkbms_Ble C8:47:8C:ED:06:11

root@raspberrypi2:~# cat /service/dbus-blebattery.1/run
#!/bin/sh
exec 2>&1
bluetoothctl disconnect
python /opt/victronenergy/dbus-serialbattery/dbus-serialbattery.py Jkbms_Ble C8:47:8C:EE:29:AF
root@raspberrypi2:~# /etc/init.d/bluetooth start
Starting bluetooth: bluetoothd.
githubfrance commented 1 year ago

I just reinstalled it 👍 wget -O /tmp/install.sh https://raw.githubusercontent.com/Louisvdw/dbus-serialbattery/master/etc/dbus- serialbattery/install.sh --2023-07-31 08:49:14-- https://raw.githubusercontent.com/Louisvdw/dbus-serialbattery/master/etc/dbus-serialbattery/instal l.sh Resolving raw.githubusercontent.com... 185.199.110.133, 185.199.111.133, 185.199.108.133, ... Connecting to raw.githubusercontent.com|185.199.110.133|:443... connected. HTTP request sent, awaiting response... 200 OK Length: 4889 (4.8K) [text/plain] Saving to: ‘/tmp/install.sh’

/tmp/install.sh 100%[===================================================>] 4.77K --.-KB/s in 0.002s

2023-07-31 08:49:15 (3.01 MB/s) - ‘/tmp/install.sh’ saved [4889/4889]

root@raspberrypi2:~# root@raspberrypi2:~# bash /tmp/install.sh

1) latest release (recommended) 3) nightly build 5) quit 2) specific version 4) local tar file Select which version you want to install and enter the corresponding number [1]: 1 Selected: latest release (recommended)

Found 2 Bluetooth BMS in the config file!

Installing required packages... Downloading https://updates.victronenergy.com/feeds/venus/release/packages/dunfell/all/Packages.gz. Updated source 'all'. Downloading https://updates.victronenergy.com/feeds/venus/release/packages/dunfell/cortexa7hf-neon-vfpv4/Packages.gz. Updated source 'cortexa7hf-neon-vfpv4'. Downloading https://updates.victronenergy.com/feeds/venus/release/packages/dunfell/raspberrypi2/Packages.gz. Updated source 'raspberrypi2'. No packages installed or removed. Requirement already satisfied: bleak in /usr/lib/python3.8/site-packages (0.20.2) Requirement already satisfied: async-timeout<5,>=3.0.0; python_version < "3.11" in /usr/lib/python3.8/site-packages (from bleak) (4.0.2) Requirement already satisfied: dbus-fast<2.0.0,>=1.83.0; platform_system == "Linux" in /usr/lib/python3.8/site-packages (from bleak) (1.87.5) Packages installed.

Installing Jkbms_Ble C8:47:8C:ED:06:11 as dbus-blebattery.0 Installing Jkbms_Ble C8:47:8C:EE:29:AF as dbus-blebattery.1 Stopping bluetooth: bluetoothd. Starting bluetooth: bluetoothd.

SERIAL battery connection: The installation is complete. You don't have to do anything more.

BLUETOOTH battery connection: There are a few more steps to complete installation.

1. Please add the Bluetooth BMS to the config file "/data/etc/dbus-serialbattery/config.ini" by adding "BLUETOOTH_BMS":
   Example with 1 BMS: BLUETOOTH_BMS = Jkbms_Ble C8:47:8C:00:00:00
   Example with 3 BMS: BLUETOOTH_BMS = Jkbms_Ble C8:47:8C:00:00:00, Jkbms_Ble C8:47:8C:00:00:11, Jkbms_Ble C8:47:8C:00:00:22
   If your Bluetooth BMS are nearby you can show the MAC address with "bluetoothctl devices".

2. Make sure to disable Settings -> Bluetooth in the remote console/GUI to prevent reconnects every minute.

3. Re-run "/data/etc/dbus-serialbattery/reinstall-local.sh", if the Bluetooth BMS were not added to the "config.ini" before.

ATTENTION!
If you changed the default connection PIN of your BMS, then you have to pair the BMS first using OS tools like the "bluetoothctl".
See https://wiki.debian.org/BluetoothUser#Using_bluetoothctl for more details.

CUSTOM SETTINGS: If you want to add custom settings, then check the settings you want to change in "/data/etc/dbus-serialbattery/config.default.ini" and add them to "/data/etc/dbus-serialbattery/config.ini" to persist future driver updates.

githubfrance commented 1 year ago

Batteries are back again image

Will et you know if it is stable or not

githubfrance commented 1 year ago

Strange, the Ruuvy Tag are disconnected a short time after the re-installation. Perhaps compatibility issues between the Ruuvy BLE program and yours. image

mr-manuel commented 1 year ago

Why are you installing the latest release, if I told you over 10x to install the nightly version from the dev branch?

Did you read the after install notes?

  1. Make sure to disable Settings -> Bluetooth in the remote console/GUI to prevent reconnects every minute.

Therefore it may not work with your sensors.

githubfrance commented 1 year ago

Hi, Bluetooth was always disabled image

I just installed the dev branch image

Both JKBMSs and RUUVIs are back again. I will keep you informed in case any instabilities Many thanks I already support $$ you and will do it again right now Paypall 50$, Despite the occasionally "aggressive" tone used, sometimes the end user may not be very attentive to the instructions :-) and this has nothing to do with the language barrier :-)

mr-manuel commented 1 year ago

Sometimes it's really annoing, if you spend 100+ hours for a good driver documentation and nobody is reading it. Thank you for your appreciation!

mr-manuel commented 1 year ago

It‘s running fine now?

githubfrance commented 1 year ago

Hi, Thank you for asking, yes every thing is OK, stable and works fine. Grat Work.

Baxter117 commented 1 year ago

Hi, Are the fixes which maked the connection stable in the dev-nightly already dropped into the master branch ?

in early august I had the same issue as here discussed with stability problems in the master, which fixed also by using the dev-nightly branch. But I hoped I could turn back to master some day :)

Thank you for the impressive work !

mr-manuel commented 1 year ago

Hi, no the changes are not merged into the master yet. First we have to fix some issues.