Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LLT/JBD - JBD BMS very unstable bluetooth connection #777

Closed
Marvo2011 opened this issue Aug 13, 2023 · 44 comments
Closed

LLT/JBD - JBD BMS very unstable bluetooth connection #777

Marvo2011 opened this issue Aug 13, 2023 · 44 comments
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@Marvo2011
Copy link
Contributor

Describe the bug

When I connect a JBD BMS over bluetooth the connection drops randomly, all charger and loads stoped working.

How to reproduce

See log....

Expected behavior

BMS / driver should reconnect, for the moment I have to restart the driver.

Driver version

1.0.20230531 (also latest dev nightly)

Venus OS device type

Raspberry Pi

Venus OS version

3.10~2

BMS type

Smart BMS (LLT, JBD, Overkill Solar)

Cell count

16

Connection type

Bluetooth

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 = 50.0
; MAX_BATTERY_DISCHARGE_CURRENT = 60.0


BLUETOOTH_BMS = LltJbd_Ble A4:C1:37:21:62:96
BLOCK_ON_DISCONNECT = False

Relevant log output

@4000000064d75d423321dddc   File "/usr/lib/python3.8/site-packages/gi/overrides/GLib.py", line 497, in run
@4000000064d75d4233e93904     super(MainLoop, self).run()
@4000000064d75d433387854c   File "/opt/victronenergy/dbus-serialbattery/dbus-serialbattery.py", line 155, in <lambda>
@4000000064d75d433387a874     gobject.timeout_add(battery.poll_interval, lambda: poll_battery(mainloop))
@4000000064d75d433387b814   File "/opt/victronenergy/dbus-serialbattery/dbus-serialbattery.py", line 67, in poll_battery
@4000000064d75d4333880e04     helper.publish_battery(loop)
@4000000064d75d43338819bc   File "/opt/victronenergy/dbus-serialbattery/dbushelper.py", line 361, in publish_battery
@4000000064d75d433389717c     success = self.battery.refresh_data()
@4000000064d75d433389811c   File "/opt/victronenergy/dbus-serialbattery/bms/lltjbd.py", line 292, in refresh_data
@4000000064d75d43338994a4     result = self.read_gen_data()
@4000000064d75d4333899c74   File "/opt/victronenergy/dbus-serialbattery/bms/lltjbd.py", line 382, in read_gen_data
@4000000064d75d433389affc     gen_data = self.read_serial_data_llt(self.command_general)
@4000000064d75d43338a158c   File "/opt/victronenergy/dbus-serialbattery/bms/lltjbd_ble.py", line 165, in read_serial_data_llt
@4000000064d75d43338a2cfc     data = asyncio.run(self.async_read_serial_data_llt(command))
@4000000064d75d43338a3c9c   File "/usr/lib/python3.8/asyncio/runners.py", line 44, in run
@4000000064d75d43338a4c3c     return loop.run_until_complete(main)
@4000000064d75d43338a57f4   File "/usr/lib/python3.8/asyncio/base_events.py", line 603, in run_until_complete
@4000000064d75d43338b175c     self.run_forever()
@4000000064d75d43338b1f2c   File "/usr/lib/python3.8/asyncio/base_events.py", line 570, in run_forever
@4000000064d75d43338b32b4     self._run_once()
@4000000064d75d43338b3a84   File "/usr/lib/python3.8/asyncio/base_events.py", line 1859, in _run_once
@4000000064d75d43338b4a24     handle._run()
@4000000064d75d43338b51f4   File "/usr/lib/python3.8/asyncio/events.py", line 81, in _run
@4000000064d75d43338bb39c     self._context.run(self._callback, *self._args)
@4000000064d75d43338bc33c   File "/opt/victronenergy/dbus-serialbattery/bms/lltjbd_ble.py", line 158, in async_read_serial_data_llt
@4000000064d75d43338bdaac     logger.error(">>> ERROR: No reply - returning", e)
@4000000064d75d43338be664 Message: '>>> ERROR: No reply - returning'
@4000000064d75d43338bf604 Arguments: (BleakDBusError('org.bluez.Error.InProgress', 'In Progress'),)
@4000000064d75d43338c53c4 --- Logging error ---
@4000000064d75d43338c5f7c Traceback (most recent call last):
@4000000064d75d43338c674c   File "/opt/victronenergy/dbus-serialbattery/bms/lltjbd_ble.py", line 152, in async_read_serial_data_llt
@4000000064d75d43338c7ebc     result = await asyncio.wait_for(asyncio.wrap_future(bt_task), 20)
@4000000064d75d43338c8e5c   File "/usr/lib/python3.8/asyncio/tasks.py", line 494, in wait_for
@4000000064d75d43338cf004     return fut.result()
@4000000064d75d43338cf7d4   File "/opt/victronenergy/dbus-serialbattery/bms/lltjbd_ble.py", line 138, in send_command
@4000000064d75d43338da3b4     await self.bt_client.start_notify(BLE_CHARACTERISTICS_RX_UUID, rx_collector)
@4000000064d75d43338db73c   File "/usr/lib/python3.8/site-packages/bleak/__init__.py", line 717, in start_notify
@4000000064d75d43338dcac4     await self._backend.start_notify(characteristic, wrapped_callback, **kwargs)
@4000000064d75d43338dde4c   File "/usr/lib/python3.8/site-packages/bleak/backends/bluezdbus/client.py", line 1003, in start_notify
@4000000064d75d43338e47c4     assert_reply(reply)
@4000000064d75d43338e537c   File "/usr/lib/python3.8/site-packages/bleak/backends/bluezdbus/utils.py", line 22, in assert_reply
@4000000064d75d43338e6704     raise BleakDBusError(reply.error_name, reply.body)
@4000000064d75d43338e76a4 bleak.exc.BleakDBusError: [org.bluez.Error.InProgress] In Progress
@4000000064d75d43338e8644 
@4000000064d75d43338e8a2c During handling of the above exception, another exception occurred:
@4000000064d75d43338eebd4 
@4000000064d75d43338eefbc Traceback (most recent call last):
@4000000064d75d43338efb74   File "/usr/lib/python3.8/logging/__init__.py", line 1085, in emit
@4000000064d75d43338f0b14     msg = self.format(record)
@4000000064d75d43338f16cc   File "/usr/lib/python3.8/logging/__init__.py", line 929, in format
@4000000064d75d43338f266c     return fmt.format(record)
@4000000064d75d43338f2e3c   File "/usr/lib/python3.8/logging/__init__.py", line 668, in format
@4000000064d75d43339089e4     record.message = record.getMessage()
@4000000064d75d433391417c   File "/usr/lib/python3.8/logging/__init__.py", line 373, in getMessage
@4000000064d75d433391511c     msg = msg % self.args
@4000000064d75d4333915cd4 TypeError: not all arguments converted during string formatting
@4000000064d75d433391688c Call stack:
@4000000064d75d433391705c   File "/opt/victronenergy/dbus-serialbattery/dbus-serialbattery.py", line 163, in <module>
@4000000064d75d43339183e4     main()
@4000000064d75d4333918bb4   File "/opt/victronenergy/dbus-serialbattery/dbus-serialbattery.py", line 157, in main
@4000000064d75d433391f144     mainloop.run()
@4000000064d75d433391fcfc   File "/usr/lib/python3.8/site-packages/gi/overrides/GLib.py", line 497, in run
@4000000064d75d4333920c9c     super(MainLoop, self).run()
@4000000064d75d4333921854   File "/opt/victronenergy/dbus-serialbattery/dbus-serialbattery.py", line 155, in <lambda>
@4000000064d75d4333922bdc     gobject.timeout_add(battery.poll_interval, lambda: poll_battery(mainloop))
@4000000064d75d433392899c   File "/opt/victronenergy/dbus-serialbattery/dbus-serialbattery.py", line 67, in poll_battery
@4000000064d75d433392a10c     helper.publish_battery(loop)
@4000000064d75d433392acc4   File "/opt/victronenergy/dbus-serialbattery/dbushelper.py", line 361, in publish_battery
@4000000064d75d433392c04c     success = self.battery.refresh_data()
@4000000064d75d433392cc04   File "/opt/victronenergy/dbus-serialbattery/bms/lltjbd.py", line 292, in refresh_data
@4000000064d75d43339377e4     result = self.read_gen_data()
@4000000064d75d433393839c   File "/opt/victronenergy/dbus-serialbattery/bms/lltjbd.py", line 382, in read_gen_data
@4000000064d75d4333939724     gen_data = self.read_serial_data_llt(self.command_general)
@4000000064d75d433393a6c4   File "/opt/victronenergy/dbus-serialbattery/bms/lltjbd_ble.py", line 165, in read_serial_data_llt
@4000000064d75d433393ba4c     data = asyncio.run(self.async_read_serial_data_llt(command))
@4000000064d75d4333941bf4   File "/usr/lib/python3.8/asyncio/runners.py", line 44, in run
@4000000064d75d4333942b94     return loop.run_until_complete(main)
@4000000064d75d433394374c   File "/usr/lib/python3.8/asyncio/base_events.py", line 603, in run_until_complete
@4000000064d75d4333944ad4     self.run_forever()
@4000000064d75d43339452a4   File "/usr/lib/python3.8/asyncio/base_events.py", line 570, in run_forever
@4000000064d75d433394662c     self._run_once()
@4000000064d75d433394b834   File "/usr/lib/python3.8/asyncio/base_events.py", line 1859, in _run_once
@4000000064d75d433394cbbc     handle._run()
@4000000064d75d433394d38c   File "/usr/lib/python3.8/asyncio/events.py", line 81, in _run
@4000000064d75d433394e32c     self._context.run(self._callback, *self._args)
@4000000064d75d433394eee4   File "/opt/victronenergy/dbus-serialbattery/bms/lltjbd_ble.py", line 158, in async_read_serial_data_llt
@4000000064d75d4333950654     logger.error(">>> ERROR: No reply - returning", e)
@4000000064d75d4333960054 Message: '>>> ERROR: No reply - returning'
@4000000064d75d4333960c0c Arguments: (BleakDBusError('org.bluez.Error.InProgress', 'In Progress'),)
@4000000064d75d4333994c14 
@4000000064d75d43339953e4 #0
@4000000064d75d43339957cc #1
@4000000064d75d4333995bb4 #2
@4000000064d75d4333996384 #3
@4000000064d75d433399676c #4
@4000000064d75d4333996b54 #5
@4000000064d75d4333996f3c #6
@4000000064d75d433399770c #7

Any other information that may be helpful

No response

@Marvo2011 Marvo2011 added the bug Something isn't working label Aug 13, 2023
@mr-manuel
Copy link
Collaborator

Please try also the nightly build from the dev branch.

@Marvo2011
Copy link
Contributor Author

@mr-manuel I have tried it yesterday. Also the same result.

@mr-manuel
Copy link
Collaborator

Also identical logs?

@Marvo2011
Copy link
Contributor Author

Yes log output is identical.

@mr-manuel
Copy link
Collaborator

mr-manuel commented Sep 4, 2023

Please provide the logs in the correct format as documented and requested. This way we cannot help you.

If you don't see the Starting dbus-serialbattery line in your logs, please reboot the Venus OS device or reinstall the driver once.

@mr-manuel
Copy link
Collaborator

Probably related to #720. @idstein maybe you can also take a look at this, if you find time?

@mr-manuel mr-manuel added the help wanted Extra attention is needed label Sep 4, 2023
@mr-manuel mr-manuel changed the title JBD BMS very unstable bluetooth connection LLT/JBD - JBD BMS very unstable bluetooth connection Sep 4, 2023
mr-manuel added a commit to mr-manuel/venus-os_dbus-serialbattery that referenced this issue Sep 4, 2023
@mr-manuel
Copy link
Collaborator

Please try to install the nightly from the dev branch. I just pushed some changes.

@mr-manuel
Copy link
Collaborator

Some more logs for this issue:

2023-09-05 08:33:34.177824500 INFO:SerialBattery:
2023-09-05 08:33:34.177829500 INFO:SerialBattery:Starting dbus-serialbattery
2023-09-05 08:33:34.179688500 INFO:SerialBattery:dbus-serialbattery v1.0.20230905dev
2023-09-05 08:33:34.548151500 INFO:SerialBattery:Init of LltJbd_Ble at E0:9F:2A:xx:xx:xx
2023-09-05 08:33:34.548601500 INFO:SerialBattery:Test of LltJbd_Ble at E0:9F:2A:xx:xx:xx
2023-09-05 08:33:40.794466500 INFO:SerialBattery:Connection established to LltJbd_Ble
2023-09-05 08:33:40.794948500 INFO:SerialBattery:Battery LltJbd_Ble connected to dbus from blee09f2axxxxxx
2023-09-05 08:33:40.795353500 INFO:SerialBattery:========== Settings ==========
2023-09-05 08:33:40.795831500 INFO:SerialBattery:> Connection voltage: 13.07V | Current: -2.72A | SoC: 17.06%
2023-09-05 08:33:40.796247500 INFO:SerialBattery:> Cell count: 4 | Cells populated: 4
2023-09-05 08:33:40.796667500 INFO:SerialBattery:> LINEAR LIMITATION ENABLE: True
2023-09-05 08:33:40.797549500 INFO:SerialBattery:> MAX BATTERY CHARGE CURRENT: 75.0A | MAX BATTERY DISCHARGE CURRENT: 150.0A
2023-09-05 08:33:40.798006500 INFO:SerialBattery:> MAX BATTERY CHARGE CURRENT: 230.0A | MAX BATTERY DISCHARGE CURRENT: 230.0A (read from BMS)
2023-09-05 08:33:40.798421500 INFO:SerialBattery:> CVCM:     True
2023-09-05 08:33:40.798858500 INFO:SerialBattery:> MIN CELL VOLTAGE: 2.9V | MAX CELL VOLTAGE: 3.5V
2023-09-05 08:33:40.799289500 INFO:SerialBattery:> CCCM CV:  True  | DCCM CV:  True
2023-09-05 08:33:40.799713500 INFO:SerialBattery:> CCCM T:   True  | DCCM T:   True
2023-09-05 08:33:40.800232500 INFO:SerialBattery:> CCCM SOC: True  | DCCM SOC: True
2023-09-05 08:33:40.800740500 INFO:SerialBattery:Serial Number/Unique Identifier: 80_272.0Ah
2023-09-05 08:33:40.853056500 INFO:SerialBattery:DeviceInstance = 6
2023-09-05 08:33:40.853660500 INFO:SerialBattery:com.victronenergy.battery.blee09f2axxxxxx
2023-09-05 08:33:41.661966500 INFO:SerialBattery:publish config values = 0
2023-09-05 09:18:06.212244500 ERROR:SerialBattery:>>> ERROR: No reply - returning
2023-09-05 09:18:15.706683500 ERROR:SerialBattery:Exception occurred: BleakDBusError('org.freedesktop.DBus.Error.NoReply', 'Message recipient disconnected from message bus without replying') of type <class 'bleak.exc.BleakDBusError'> in /opt/victronenergy/dbus-serialbattery/bms/lltjbd_ble.py line #176
2023-09-05 09:18:15.752904500 ERROR:SerialBattery:Exception occurred: BleakDBusError('org.freedesktop.DBus.Error.ServiceUnknown', 'The name org.bluez was not provided by any .service files') of type <class 'bleak.exc.BleakDBusError'> in /opt/victronenergy/dbus-serialbattery/bms/lltjbd_ble.py line #176
2023-09-05 09:18:15.783531500 [CHG] Device E0:9F:2A:xx:xx:xx RSSI: -53
2023-09-05 09:18:15.783539500 [CHG] Device E0:9F:2A:xx:xx:xx RSSI: -53
2023-09-05 09:18:15.783543500 [CHG] Device E0:9F:2A:xx:xx:xx RSSI: -53
2023-09-05 09:18:16.730540500 ERROR:SerialBattery:Exception occurred: BleakDBusError('org.freedesktop.DBus.Error.ServiceUnknown', 'The name org.bluez was not provided by any .service files') of type <class 'bleak.exc.BleakDBusError'> in /opt/victronenergy/dbus-serialbattery/bms/lltjbd_ble.py line #176
2023-09-05 09:18:17.730947500 ERROR:SerialBattery:Exception occurred: BleakDBusError('org.freedesktop.DBus.Error.ServiceUnknown', 'The name org.bluez was not provided by any .service files') of type <class 'bleak.exc.BleakDBusError'> in /opt/victronenergy/dbus-serialbattery/bms/lltjbd_ble.py line #176
2023-09-05 09:18:18.731835500 ERROR:SerialBattery:Exception occurred: BleakDBusError('org.freedesktop.DBus.Error.ServiceUnknown', 'The name org.bluez was not provided by any .service files') of type <class 'bleak.exc.BleakDBusError'> in /opt/victronenergy/dbus-serialbattery/bms/lltjbd_ble.py line #176
2023-09-05 09:18:19.732333500 ERROR:SerialBattery:Exception occurred: BleakDBusError('org.freedesktop.DBus.Error.ServiceUnknown', 'The name org.bluez was not provided by any .service files') of type <class 'bleak.exc.BleakDBusError'> in /opt/victronenergy/dbus-serialbattery/bms/lltjbd_ble.py line #176
2023-09-05 09:18:20.737443500 ERROR:SerialBattery:Exception occurred: BleakDBusError('org.freedesktop.DBus.Error.ServiceUnknown', 'The name org.bluez was not provided by any .service files') of type <class 'bleak.exc.BleakDBusError'> in /opt/victronenergy/dbus-serialbattery/bms/lltjbd_ble.py line #176

After that I have to run this commands to get it working again:

# stop bluetooth system service
/etc/init.d/bluetooth stop

# kill all blebattery processes
pkill -f "supervise dbus-blebattery.*"
pkill -f "multilog .* /var/log/dbus-blebattery.*"
pkill -f "python .*/dbus-serialbattery.py .*_Ble"

# start bluetooth system service
/etc/init.d/bluetooth start

@Marvo2011
Copy link
Contributor Author

Marvo2011 commented Sep 5, 2023

Many thanks, I will try it soon. But I must wait for the repair of my MultiPlus. I think it is mostly happens on positive (charging) load. Can you reproduce it?

@mr-manuel
Copy link
Collaborator

Unfortunately not. I can only wait for it to happen and then add some code for error handling.

mr-manuel added a commit to mr-manuel/venus-os_dbus-serialbattery that referenced this issue Sep 5, 2023
@idstein
Copy link
Contributor

idstein commented Sep 6, 2023

Okay, so I now experienced also a very unpleasant connection issue with the BMS. Looking and hcidump output and a simple hcitool lecc <mac> (= BLE connect), I can now state that the JBDBT02 device it self seems to have some sort of blacklistening or block mechanism. I could not re-connect from my VenusOS to the device, but could without issues use from another device a BT BMS app.

So I tried to change the MAC address of the hci0 adapter in my RPI and surprise, it can connect again.

BTW unplugging the dongle from the BMS board or rebooting the entire BMS board does not seem to resolve the issue. There seems to be a hardcoded blacklist timeout of at least 24 hours.

@Marvo2011
Copy link
Contributor Author

Okay, so I now experienced also a very unpleasant connection issue with the BMS. Looking and hcidump output and a simple hcitool lecc <mac> (= BLE connect), I can now state that the JBDBT02 device it self seems to have some sort of blacklistening or block mechanism. I could not re-connect from my VenusOS to the device, but could without issues use from another device a BT BMS app.

So I tried to change the MAC address of the hci0 adapter in my RPI and surprise, it can connect again.

BTW unplugging the dongle from the BMS board or rebooting the entire BMS board does not seem to resolve the issue. There seems to be a hardcoded blacklist timeout of at least 24 hours.

That sounds strange, for me a simple restart of the driver makes a working reconnect.

@pieterjanvz
Copy link

pieterjanvz commented Sep 17, 2023

below the BLE log from my JBD BMS, this is on latest Dev version , other versions gave much more errors:

2023-09-17 10:55:46.391618500
2023-09-17 10:55:46.391623500 INFO:Bluetooth details
2023-09-17 10:55:46.426172500 Device A4:C1:38:C0:53:90 not available
2023-09-17 10:55:51.493111500 Device A4:C1:38:C0:53:90 (public)
2023-09-17 10:55:51.493118500   Alias: Accu 1
2023-09-17 10:55:51.493120500   Paired: no
2023-09-17 10:55:51.493122500   Trusted: no
2023-09-17 10:55:51.493123500   Blocked: no
2023-09-17 10:55:51.493125500   Connected: no
2023-09-17 10:55:51.493127500   LegacyPairing: no
2023-09-17 10:55:51.493129500   RSSI: -61
2023-09-17 10:55:51.494420500
2023-09-17 10:55:53.289267500 INFO:SerialBattery:
2023-09-17 10:55:53.289687500 INFO:SerialBattery:Starting dbus-serialbattery
2023-09-17 10:55:53.290617500 INFO:SerialBattery:dbus-serialbattery v1.0.20230905dev
2023-09-17 10:55:53.732126500 INFO:SerialBattery:Init of LltJbd_Ble at A4:C1:38:C0:53:90
2023-09-17 10:55:53.732546500 INFO:SerialBattery:Test of LltJbd_Ble at A4:C1:38:C0:53:90
2023-09-17 10:55:53.882705500 ERROR:SerialBattery:BleakScanner(): Exception occurred: ValueError('dbus_fast._private.marshaller.Marshaller size changed, may indicate binary incompatibility. Expected 24 from C header, got 20 from PyObject') of type <class 'ValueError'> in /opt/victronenergy/dbus-serialbattery/bms/lltjbd_ble.py line #59
2023-09-17 10:55:58.743707500 ERROR:SerialBattery:>>> ERROR: Unable to connect with BLE device
2023-09-17 10:55:58.746020500 ERROR:SerialBattery:No BMS found at A4:C1:38:C0:53:90
2023-09-17 10:55:58.746445500 ERROR:SerialBattery:ERROR >>> No battery connection at LltJbd_Ble
2023-09-17 10:55:59.636611500
2023-09-17 10:55:59.636744500 INFO:Bluetooth details
2023-09-17 10:55:59.719706500 Attempting to disconnect from A4:C1:38:C0:53:90
2023-09-17 10:55:59.719714500 [CHG] Device FE:7C:93:F9:42:6C RSSI is nil
2023-09-17 10:55:59.719718500 [CHG] Device CD:26:4D:CE:82:AE RSSI is nil
2023-09-17 10:55:59.719721500 [CHG] Device A4:C1:37:10:26:0D RSSI is nil
2023-09-17 10:55:59.719725500 [CHG] Device D4:F1:2E:C1:77:33 RSSI is nil
2023-09-17 10:55:59.719729500 [CHG] Device FD:44:C9:E4:C6:E5 RSSI is nil
2023-09-17 10:55:59.719732500 [CHG] Device A4:C1:38:C0:53:90 RSSI is nil
2023-09-17 10:55:59.719819500 [CHG] Device A4:C1:38:E4:CF:B1 RSSI is nil
2023-09-17 10:55:59.719823500 [CHG] Device A4:C1:38:00:2F:44 RSSI is nil
2023-09-17 10:55:59.719827500 [CHG] Device F5:47:C8:BF:C3:69 RSSI is nil
2023-09-17 10:55:59.719830500 [CHG] Controller B8:27:EB:0E:BC:1D Discovering: no
2023-09-17 10:55:59.719834500 Successful disconnected

@mr-manuel
Copy link
Collaborator

@pieterjanvz can you try to change this line

to

    pip3 install bleak==0.20.2

and then run reinstall-local.sh again?

If you still have the same error add

    pip3 install dbus-fast==1.87.0

below

and then run reinstall-local.sh again.

@pieterjanvz
Copy link

Thanks I now can connect , but as above its not stable , hope this wil be solved soon

@mr-manuel
Copy link
Collaborator

Did you downgrade only bleak or also dbus-fast? This is or a bug in the code or a bug in the module.

@Marvo2011
Copy link
Contributor Author

Today I have received my repaired MultiPlus, I have installed the nightly dev. I try to reproduce the issue and will post the logs.

@Marvo2011
Copy link
Contributor Author

Here the actual log output:

root@raspberrypi2:/data/log/dbus-blebattery.0# cat current 
@400000006509a8a62c16c034 ERROR:SerialBattery:>>> ERROR: Unable to connect with BLE device
@400000006509a8a62c3661dc ERROR:SerialBattery:No BMS found at A4:C1:37:21:62:96
@400000006509a8a62c3f81cc ERROR:SerialBattery:ERROR >>> No battery connection at LltJbd_Ble
@400000006509a8a735a7215c 
@400000006509a8a735aba984 INFO:Bluetooth details
@400000006509a8a7375b8c04 Attempting to disconnect from A4:C1:37:21:62:96
@400000006509a8a7375ba75c Successful disconnected
@400000006509a8ac3a1fd83c Device A4:C1:37:21:62:96 (public)
@400000006509a8ac3a1ffb64 	Alias: Wohnwagen
@400000006509a8ac3a200eec 	Paired: no
@400000006509a8ac3a201aa4 	Trusted: yes
@400000006509a8ac3a202274 	Blocked: no
@400000006509a8ac3a202a44 	Connected: no
@400000006509a8ac3a203214 	LegacyPairing: no
@400000006509a8ac3a2039e4 	UUID: Device Information        (0000180a-0000-1000-8000-00805f9b34fb)
@400000006509a8ac3a45d6cc 
@400000006509a8ae0317d4fc INFO:SerialBattery:
@400000006509a8ae032146f4 INFO:SerialBattery:Starting dbus-serialbattery
@400000006509a8ae033069f4 INFO:SerialBattery:dbus-serialbattery v1.0.20230919dev
@400000006509a8ae1937d944 INFO:SerialBattery:Init of LltJbd_Ble at A4:C1:37:21:62:96
@400000006509a8ae1941995c INFO:SerialBattery:Test of LltJbd_Ble at A4:C1:37:21:62:96
@400000006509a8ae2e8d790c ERROR:SerialBattery:BleakScanner(): Exception occurred: BleakError('No powered Bluetooth adapters found.') of type <class 'bleak.exc.BleakError'> in /opt/victronenergy/dbus-serialbattery/bms/lltjbd_ble.py line #59
@400000006509a8b31a1aea2c ERROR:SerialBattery:>>> ERROR: Unable to connect with BLE device
@400000006509a8b31a1b0584 ERROR:SerialBattery:No BMS found at A4:C1:37:21:62:96
@400000006509a8b31a1b1524 ERROR:SerialBattery:ERROR >>> No battery connection at LltJbd_Ble
@400000006509a8b4207f6794 
@400000006509a8b4208372bc INFO:Bluetooth details
@400000006509a8b4224a1d44 Attempting to disconnect from A4:C1:37:21:62:96
@400000006509a8b4224a389c Successful disconnected
@400000006509a8b924d538dc Device A4:C1:37:21:62:96 (public)
@400000006509a8b924d55434 	Alias: Wohnwagen
@400000006509a8b924d55c04 	Paired: no
@400000006509a8b924d563d4 	Trusted: yes
@400000006509a8b924d567bc 	Blocked: no
@400000006509a8b924d56f8c 	Connected: no
@400000006509a8b924d5775c 	LegacyPairing: no
@400000006509a8b924d57f2c 	UUID: Device Information        (0000180a-0000-1000-8000-00805f9b34fb)
@400000006509a8b9250af6ac 
@400000006509a8ba306d6854 INFO:SerialBattery:
@400000006509a8ba30770544 INFO:SerialBattery:Starting dbus-serialbattery
@400000006509a8ba30864f54 INFO:SerialBattery:dbus-serialbattery v1.0.20230919dev
@400000006509a8bb0b489684 INFO:SerialBattery:Init of LltJbd_Ble at A4:C1:37:21:62:96
@400000006509a8bb0b53392c INFO:SerialBattery:Test of LltJbd_Ble at A4:C1:37:21:62:96
@400000006509a8bb22c396ec ERROR:SerialBattery:BleakScanner(): Exception occurred: BleakError('No powered Bluetooth adapters found.') of type <class 'bleak.exc.BleakError'> in /opt/victronenergy/dbus-serialbattery/bms/lltjbd_ble.py line #59
@400000006509a8c00c306a2c ERROR:SerialBattery:>>> ERROR: Unable to connect with BLE device
@400000006509a8c00c308584 ERROR:SerialBattery:No BMS found at A4:C1:37:21:62:96
@400000006509a8c00c30913c ERROR:SerialBattery:ERROR >>> No battery connection at LltJbd_Ble
@400000006509a8c1151d20e4 
@400000006509a8c1152137c4 INFO:Bluetooth details
@400000006509a8c116dd4f44 Attempting to disconnect from A4:C1:37:21:62:96
@400000006509a8c116dd6a9c Successful disconnected
@400000006509a8c6199b65a4 Device A4:C1:37:21:62:96 (public)
@400000006509a8c6199b7d14 	Alias: Wohnwagen
@400000006509a8c6199b84e4 	Paired: no
@400000006509a8c6199b8cb4 	Trusted: yes
@400000006509a8c6199b909c 	Blocked: no
@400000006509a8c6199b986c 	Connected: no
@400000006509a8c6199ba03c 	LegacyPairing: no
@400000006509a8c6199ba80c 	UUID: Device Information        (0000180a-0000-1000-8000-00805f9b34fb)
@400000006509a8c619c0fea4 
@400000006509a8c72825560c INFO:SerialBattery:
@400000006509a8c72834cb14 INFO:SerialBattery:Starting dbus-serialbattery
@400000006509a8c72849aebc INFO:SerialBattery:dbus-serialbattery v1.0.20230919dev
@400000006509a8c805cfa1fc INFO:SerialBattery:Init of LltJbd_Ble at A4:C1:37:21:62:96
@400000006509a8c805da8edc INFO:SerialBattery:Test of LltJbd_Ble at A4:C1:37:21:62:96
@400000006509a8c81c23163c ERROR:SerialBattery:BleakScanner(): Exception occurred: BleakError('No powered Bluetooth adapters found.') of type <class 'bleak.exc.BleakError'> in /opt/victronenergy/dbus-serialbattery/bms/lltjbd_ble.py line #59

@mr-manuel
Copy link
Collaborator

Did you reboot once?

@Marvo2011
Copy link
Contributor Author

Yes after a reboot, it works a few hours than the issue comes back.

@Marvo2011
Copy link
Contributor Author

Some interesting details:

After reboot:

root@raspberrypi2:~# hciconfig -a
hci0:	Type: Primary  Bus: UART
	BD Address: 43:45:C0:00:1F:AC  ACL MTU: 1021:8  SCO MTU: 64:1
	UP RUNNING 
	RX bytes:6576 acl:145 sco:0 events:255 errors:0
	TX bytes:3985 acl:110 sco:0 commands:154 errors:0
	Features: 0xbf 0xfe 0xcf 0xfe 0xdb 0xff 0x7b 0x87
	Packet type: DM1 DM3 DM5 DH1 DH3 DH5 HV1 HV2 HV3 
	Link policy: RSWITCH SNIFF 
	Link mode: SLAVE ACCEPT 
	Name: 'Raspberry Pi 3 Model B Plus Rev 1.3 HQ0000AAAAA'
	Class: 0x000000
	Service Classes: Unspecified
	Device Class: Miscellaneous, 
	HCI Version: 5.0 (0x9)  Revision: 0x156
	LMP Version: 5.0 (0x9)  Subversion: 0x6119
	Manufacturer: Cypress Semiconductor (305)

After first crash:

root@raspberrypi2:~# hciconfig -a
hci0:	Type: Primary  Bus: UART
	BD Address: 43:45:C0:00:1F:AC  ACL MTU: 1021:8  SCO MTU: 64:1
	DOWN 
	RX bytes:1471 acl:0 sco:0 events:83 errors:0
	TX bytes:1228 acl:0 sco:0 commands:83 errors:0
	Features: 0xbf 0xfe 0xcf 0xfe 0xdb 0xff 0x7b 0x87
	Packet type: DM1 DM3 DM5 DH1 DH3 DH5 HV1 HV2 HV3 
	Link policy: RSWITCH SNIFF 
	Link mode: SLAVE ACCEPT 

I think it's related to the hardware -> Raspberry Pi 3 Model B Plus Rev 1.3

@mr-manuel
Copy link
Collaborator

We had this already in the past. Can you try this routine, if it happen again and see, it it helps without rebooting?

# stop bluetooth system service
/etc/init.d/bluetooth stop
pkill -f "bluetoothd"

# kill bluetooth system stack
rfkill block bluetooth
rfkill unblock bluetooth

# kill all blebattery processes
pkill -f "supervise dbus-blebattery.*"
pkill -f "multilog .* /var/log/dbus-blebattery.*"
pkill -f "python .*/dbus-serialbattery.py .*_Ble.*"

# start bluetooth system service
/etc/init.d/bluetooth start

@Marvo2011
Copy link
Contributor Author

Does not work, only the full reboot.

@Marvo2011
Copy link
Contributor Author

Marvo2011 commented Sep 21, 2023

I find out the following works without a reboot:

# stop bluetooth system service
/etc/init.d/bluetooth stop
pkill -f "bluetoothd"

# kill hciattach
pkill -f "hciattach"

# kill bluetooth system stack
rfkill block bluetooth
rfkill unblock bluetooth

# kill all blebattery processes
pkill -f "supervise dbus-blebattery.*"
pkill -f "multilog .* /var/log/dbus-blebattery.*"
pkill -f "python .*/dbus-serialbattery.py .*_Ble.*"

# restart kernel module
rmmod hci_uart
rmmod btbcm
modprobe hci_uart
modprobe btbcm

# start bluetooth system service
/etc/init.d/bluetooth start

# start hciattach
/usr/bin/hciattach -t 10 /dev/ttyS0 bcm43xx 921600 noflow - &

I will test again if a hciattach restart is sufficient.

Edit: Kernel Log:

ep 21 08:52:18 raspberrypi2 daemon.info bluetoothd[5045]: Bluetooth daemon 5.55
Sep 21 08:52:18 raspberrypi2 daemon.warn bluetoothd[5045]: ../bluez-5.55/src/main.c:parse_controller_config() Key file does not have group “Controller”
Sep 21 08:52:18 raspberrypi2 daemon.warn bluetoothd[5045]: ../bluez-5.55/src/main.c:parse_controller_config() Key file does not have group “Controller”
Sep 21 08:52:18 raspberrypi2 daemon.warn bluetoothd[5045]: ../bluez-5.55/src/main.c:parse_controller_config() Key file does not have group “Controller”
Sep 21 08:52:18 raspberrypi2 daemon.warn bluetoothd[5045]: ../bluez-5.55/src/main.c:parse_controller_config() Key file does not have group “Controller”
Sep 21 08:52:18 raspberrypi2 daemon.warn bluetoothd[5045]: ../bluez-5.55/src/main.c:parse_controller_config() Key file does not have group “Controller”
Sep 21 08:52:18 raspberrypi2 daemon.warn bluetoothd[5045]: ../bluez-5.55/src/main.c:parse_controller_config() Key file does not have group “Controller”
Sep 21 08:52:18 raspberrypi2 daemon.warn bluetoothd[5045]: ../bluez-5.55/src/main.c:parse_controller_config() Key file does not have group “Controller”
Sep 21 08:52:18 raspberrypi2 daemon.warn bluetoothd[5045]: ../bluez-5.55/src/main.c:parse_controller_config() Key file does not have group “Controller”
Sep 21 08:52:18 raspberrypi2 daemon.warn bluetoothd[5045]: ../bluez-5.55/src/main.c:parse_controller_config() Key file does not have group “Controller”
Sep 21 08:52:18 raspberrypi2 daemon.warn bluetoothd[5045]: ../bluez-5.55/src/main.c:parse_controller_config() Key file does not have group “Controller”
Sep 21 08:52:18 raspberrypi2 daemon.warn bluetoothd[5045]: ../bluez-5.55/src/main.c:parse_controller_config() Key file does not have group “Controller”
Sep 21 08:52:18 raspberrypi2 daemon.warn bluetoothd[5045]: ../bluez-5.55/src/main.c:parse_controller_config() Key file does not have group “Controller”
Sep 21 08:52:18 raspberrypi2 daemon.warn bluetoothd[5045]: ../bluez-5.55/src/main.c:parse_controller_config() Key file does not have group “Controller”
Sep 21 08:52:18 raspberrypi2 daemon.warn bluetoothd[5045]: ../bluez-5.55/src/main.c:parse_controller_config() Key file does not have group “Controller”
Sep 21 08:52:18 raspberrypi2 daemon.warn bluetoothd[5045]: ../bluez-5.55/src/main.c:parse_controller_config() Key file does not have group “Controller”
Sep 21 08:52:18 raspberrypi2 daemon.warn bluetoothd[5045]: ../bluez-5.55/src/main.c:parse_controller_config() Key file does not have group “Controller”
Sep 21 08:52:18 raspberrypi2 daemon.warn bluetoothd[5045]: ../bluez-5.55/src/main.c:parse_controller_config() Key file does not have group “Controller”
Sep 21 08:52:18 raspberrypi2 daemon.warn bluetoothd[5045]: ../bluez-5.55/src/main.c:parse_controller_config() Key file does not have group “Controller”
Sep 21 08:52:18 raspberrypi2 daemon.warn bluetoothd[5045]: ../bluez-5.55/src/main.c:parse_controller_config() Key file does not have group “Controller”
Sep 21 08:52:18 raspberrypi2 daemon.warn bluetoothd[5045]: ../bluez-5.55/src/main.c:parse_controller_config() Key file does not have group “Controller”
Sep 21 08:52:18 raspberrypi2 daemon.warn bluetoothd[5045]: ../bluez-5.55/src/main.c:parse_controller_config() Key file does not have group “Controller”
Sep 21 08:52:18 raspberrypi2 daemon.warn bluetoothd[5045]: ../bluez-5.55/src/main.c:parse_controller_config() Key file does not have group “Controller”
Sep 21 08:52:18 raspberrypi2 daemon.warn bluetoothd[5045]: ../bluez-5.55/src/main.c:parse_controller_config() Key file does not have group “Controller”
Sep 21 08:52:18 raspberrypi2 daemon.warn bluetoothd[5045]: ../bluez-5.55/src/main.c:parse_controller_config() Key file does not have group “Controller”
Sep 21 08:52:18 raspberrypi2 daemon.warn bluetoothd[5045]: ../bluez-5.55/src/main.c:parse_controller_config() Key file does not have group “Controller”
Sep 21 08:52:18 raspberrypi2 daemon.warn bluetoothd[5045]: ../bluez-5.55/src/main.c:parse_controller_config() Key file does not have group “Controller”
Sep 21 08:52:18 raspberrypi2 daemon.warn bluetoothd[5045]: ../bluez-5.55/src/main.c:parse_controller_config() Key file does not have group “Controller”
Sep 21 08:52:18 raspberrypi2 daemon.warn bluetoothd[5045]: ../bluez-5.55/src/main.c:parse_controller_config() Key file does not have group “Controller”
Sep 21 08:52:18 raspberrypi2 daemon.info bluetoothd[5045]: Bluetooth management interface 1.18 initialized
Sep 21 08:52:20 raspberrypi2 user.err kernel: [ 1086.155040] Bluetooth: hci0: command 0x1003 tx timeout
Sep 21 08:52:22 raspberrypi2 user.err kernel: [ 1088.235043] Bluetooth: hci0: command 0x1001 tx timeout
Sep 21 08:52:24 raspberrypi2 user.err kernel: [ 1090.315057] Bluetooth: hci0: command 0x1009 tx timeout
Sep 21 08:52:28 raspberrypi2 daemon.err bluetoothd[5045]: Failed to set mode: Failed (0x03)
Sep 21 08:52:28 raspberrypi2 daemon.warn connmand[750]: Bluetooth device /org/bluez/hci0 not enabled Failed
Sep 21 08:53:14 raspberrypi2 daemon.info bluetoothd[5045]: Terminating
Sep 21 08:53:14 raspberrypi2 daemon.info bluetoothd[5045]: Exit

@mr-manuel
Copy link
Collaborator

Sounds great! So we can integrate this in the driver that it restarts the stack in the case of a crash.

@Marvo2011
Copy link
Contributor Author

# kill hciattach
pkill -f "hciattach"

# restart kernel module
rmmod hci_uart
rmmod btbcm
modprobe hci_uart
modprobe btbcm

# start hciattach
/usr/bin/hciattach -t 10 /dev/ttyS0 bcm43xx 921600 noflow - &

Is sufficient, also brings the device in dbus-serialbattery back.
I think its good to search before with ps | grep hciattach to got the correct restart command.

@mr-manuel
Copy link
Collaborator

Could you script that?

@Marvo2011
Copy link
Contributor Author

Yes, I will create a PR

@Marvo2011
Copy link
Contributor Author

Marvo2011 commented Oct 3, 2023

Edit: Sorry have to merge it first....
Edit: Now looks good, please take a look before I will create the PR: Marvo2011@1383b29

@randomname32
Copy link

randomname32 commented Nov 14, 2023

# kill hciattach
pkill -f "hciattach"

# restart kernel module
rmmod hci_uart
rmmod btbcm
modprobe hci_uart
modprobe btbcm

# start hciattach
/usr/bin/hciattach -t 10 /dev/ttyS0 bcm43xx 921600 noflow - &

I have the same issue with Bluetooth randomly being down on my Raspberry Pi 3 Model B Plus Rev 1.3.
This solution worked for me. Thanks!

Louisvdw pushed a commit that referenced this issue Nov 25, 2023
* Update reinstall-local.sh: Fixed charge current parameter

Update reinstall-local.sh: Corrected charge current parameter for  initial config.ini

* Exclude devices from driver startup
This prevents blocking the serial port

* implement callback function for update

* fix comments to reflect new logic

* update changelog

* set soc=100% when charge mode changes to float, apply exponential smoothing on current readout

* remove scan for devices

the scan for devices and check if the BMS to test is present doesn't add value
if the device is not within range (or the MAC is wrong), then the subsequent start_scraping call will either fail or fail to produce usable data

* JKBMS_BLE driver fixes

* added Bluetooth signal strenght, increased debug

* Optimized reinstallation procedure
- Changed: Optimized restart sequence for the bluetooth installation
- Changed: Run serial part first and then bluetooth part. This allows the serial driver to get operative faster
- Removed: $DRIVERNAME variable for clearer paths
- Removed: Bluetooth system driver restart, since the devices get disconnected by the service before starting the dbus-serialbatterydriver

* Improved Jkbms_Ble error handling

* optimized disable procedure

* small fixes

* save custom name and make it restart persistant
#100

* changed unique identifier from string to function
function can be overridden by BMS battery class

* fix typo

* fix Sinowealth not loading
#702

* fix unique identifier function

* enable BMS over config, if disabled by default
Now you can also add more then one BMS for BMS_TYPE

* show battery port in log

* ANT BMS fixes
Fixed that other devices are recognized as ANT BMS

* Sinowealth BMS fixes
Fixed that other devices are recognized as Sinowealth BMS

* improved publish_battery error handling
switched from error count to seconds

* Improve Battery Voltage Handling in Linear Absorption Mode

* Refactor change time() to int(time()) for consistency in max_voltage_start_time and tDiff calculation
* Refactor battery voltage calculations for efficiency and clarity
* Remove penalty_buffer
* Reset max_voltage_start_time wenn we going to bulk(dynamic) mode

* updated changelog

* fix reply processing

* Reduce the big inrush current, if the CVL jumps
from Bulk/Absorbtion to Float
fix #659

* Check returned data lenght for Seplos BMS

Be stricter about the return data we accept, might fix the problem of grid meters accidently being recognized as a Seplos

* Validate current, voltage, capacity and SoC for all BMS
This prevents that a device, which is no BMS, is detected as BMS

* removed double check

* bump version

* fix validation if None

* updated changelog

* proposal to #659 formatted :)

* bugfix proposal to #659

* refactor setting float charge_mode

* fix type error, removed bluetooth cronjob

* updated changelog

* fix rs485 write communication errors by inserting sleeps, add debug print for charge mode and fix crash on write soc failures

* fix write problem on set_soc. also changed the switch charge/discharge function, just in case

* debug msg

* Bluetooth optimizations

* Fixes by @peterohman
#505 (comment)

* fix #712

* fix meaningless time to go values

* fix meaningless time to go values

* Duration of transition to float depends on number of cells

* Float transition - Voltage drop per second

* Update hlpdatabms4s.py

* Validate setting of FLOAT_CELL_VOLTAGE and avoid misconfiguration

* consider utils.LINEAR_RECALCULATION_EVERY to refresh CVL

* cleanup

* consider utils.LINEAR_RECALCULATION_EVERY to refresh CVL

* small refactor, introduced set_cvl_linear function to set CVL only once every LINEAR_RECALCULATION_EVERY seconds

* fix typo

* updated changelog

* remove debug msg

* remove debug msg

* undo debug change

* Daly BMS make auto reset soc configurable

* added debug and error information for CVL

* fix proposal for #733 (#735)

* Added: Tollerance to enter float voltage once the timer is triggered

* Add bulk voltage
Load to bulk voltage every x days to reset the SoC to 100% for some BMS

* JKBMS disable high voltage warning on bulk
reenable after bulk was completed

* fixed error

* disable high voltage warning for all BMS
when charging to bulk voltage

* fix error and change default value
measurementToleranceVariation from 0.025 to 0.5 else in OffGrid mode max voltage is always kept

* Added temperature names to dbus/mqtt

* Use current avg of last 300 cycles for TTG & TTS

* Calculate only positive Time-to-SoC points

* added current average of last 5 minutes

* make CCL and DCL more clear

* fix small error

* bugfix: LLTJBD BMS SOC different in Xiaoxiang app and dbus-serialbattery

* black formatting

* JDB BMS - Control FETs for charge, discharge and disable / enable balancer (#761)

* feature: Allow to control charge / discharge FET
* feature: Allow to enable / disable balancer

* bugfix: Cycle Capacity is in 10 mAh

Fixes SoC with factor 100 * 100% percentage

* JBD BMS show balancer state in GUI page IO (#763)

* Bump version

* Fix typos

* Smaller fixes
- fixes #792 (comment)

* Removed comments from utils.py
This should make more clear that there are no values to change

* Updated changelog

* possible fix for LLT/JBS connection problems
#769
#777

* bugfix: LLT/JBD BMS general packet data size check

* improved reinstall and disable script

* LLT/JBD BMS - Improved error handling and automatical driver restart
in case of error. Should fix:
- #730
- #769
- #777

* Fixed Building wheel for dbus-fast won't finish on weak systems
Fixes #785

* Support for Daly CAN Bus (#169)

* support for Daly CAN Bus
* fix constructor args
* revert port, needs fix
* add can filters
* comment logger

Some changes are still needed to work with the latest version. They will follow in a next PR.

---------

Co-authored-by: Samuel Brucksch <samuel@iternio.com>
Co-authored-by: Manuel <mr-manuel@outlook.it>

* JKBMS BLE - Introduction of automatic SOC reset (HW Version 11) (#736)

* Introduction of automatic SOC reset for JK BMS (HW Version 11)
* Fixed value mapping
* Rework of the code to make it simpler to use without additional configuration.
Moved execution of SOC reset. It's now executed while changing from "Float" to "Float Transition".
* Implementation of suggested changes
Persist initial BMS OVP and OVPR settings
Make use of max_cell_voltage to calculate trigger value for OVP alert

* Added: Daly CAN and JKBMS CAN

* added CAN bms to installation script
optimized CAN drivers

* smaller fixes

* Trigger JK BLE SOC reset when using Step Mode

* Moved trigger_soc_reset()

* fixes LLT/JBD SOC > 100%
#769

* changed VOLTAGE_DROP behaviour

* Fix JKBMS not starting if BMS manuf. date is empty

* corrected bulk, absorption and soc reset terms

* fix typo

* add JKBMS_BLE debugging data

* fix small error

* added logging to config

* add sleep before starting driver
prevents lot of timeouts after reinstalling the driver, since the restart is now much faster than before

* changed post install info

* fix error

* Daly BMS fixed embedded null byte
#837

* added info for SoC reset to default config file

* fix for #716
#716

* fix for #716 and JKBMS model recognition
#716

* optimized logging

* fix JKBMS recognition

* added debugging

* fixes #716
#716

---------

Co-authored-by: Holger Schultheiß <hoschult@web.de>
Co-authored-by: Stefan Seidel <lkml@stefanseidel.info>
Co-authored-by: Bernd Stahlbock <6627385+transistorgit@users.noreply.github.com>
Co-authored-by: seidler2547 <github@stefanseidel.info>
Co-authored-by: ogurevich <50322596+ogurevich@users.noreply.github.com>
Co-authored-by: wollew <wollew@users.noreply.github.com>
Co-authored-by: Oleg Gurevich <oleg@gurevich.de>
Co-authored-by: peterohman <psub@fieber.se>
Co-authored-by: Strawder, Paul <paul@coach-ai.com>
Co-authored-by: Paul Strawder <paulidstein@gmail.com>
Co-authored-by: Samuel Brucksch <SamuelBrucksch@users.noreply.github.com>
Co-authored-by: Samuel Brucksch <samuel@iternio.com>
Co-authored-by: ArendsM <136503378+ArendsM@users.noreply.github.com>
Co-authored-by: Meik Arends <github@arends.info>
@idstein
Copy link
Contributor

idstein commented Dec 4, 2023

Tried that solution on my RPI4 fails unfortunately. The hciattach fails for me with a timeout.

@Marvo2011
Copy link
Contributor Author

I think it's hardware / raspberry firmware related. I will try to use a usb bluetooth device for a better connection.

@mr-manuel
Copy link
Collaborator

I think it's a software bug of bleak. We had this a year ago and it doesn't changed on using an external USB adapter.

@idstein
Copy link
Contributor

idstein commented Dec 5, 2023

Honestly, I think it is a RPI / firmware issue. Once I encountered it, the only way to fix it on my RPI4 was to restart the entire systems several times (not like 2-3x, more like 5+). Also to my understanding there are several remapping issues known with RPI4 on UART ports and BT serial port.

@mr-manuel
Copy link
Collaborator

Here you can find more detailed info #372

@Marvo2011
Copy link
Contributor Author

I got it working with an USB bluetooth module. There are some needed requirements, the usb module must support BLE (bluetooth version > 4.0). Then some changes to bluetooth setting from the pi.

# hciconfig -a
hci0:	Type: Primary  Bus: USB
	BD Address: XX:XX:XX:XX:XX:XX  ACL MTU: 1021:5  SCO MTU: 255:11
	UP RUNNING INQUIRY 
	RX bytes:11233162 acl:498440 sco:0 events:350109 errors:0
	TX bytes:5036196 acl:332323 sco:0 commands:14255 errors:0
	Features: 0xff 0xff 0xff 0xfe 0xdb 0xfd 0x7b 0x87
	Packet type: DM1 DM3 DM5 DH1 DH3 DH5 HV1 HV2 HV3 
	Link policy: RSWITCH HOLD SNIFF PARK 
	Link mode: SLAVE ACCEPT 
	Name: 'BlueZ 5.55'
	Class: 0x000000
	Service Classes: Unspecified
	Device Class: Miscellaneous, 
	HCI Version: 5.1 (0xa)  Revision: 0xca9
	LMP Version: 5.1 (0xa)  Subversion: 0x8a6b
	Manufacturer: Realtek Semiconductor Corporation (93)

I will try it over some days, when it's stable I will create some code which can setup the needed requirements to the pi settings by enabled it in the config.ini.

@Marvo2011
Copy link
Contributor Author

@mr-manuel please see pull request #890

@idstein can you try if it also stable for you?
@randomname32 can you try if it also stable for you?

@randomname32
Copy link

I just did a manual test by running

root@raspberrypi2:~# hciconfig hci0 down
root@raspberrypi2:~# hciconfig -a
hci0:	Type: Primary  Bus: UART
	BD Address: 43:45:C0:00:1F:AC  ACL MTU: 1021:8  SCO MTU: 64:1
	DOWN 
	RX bytes:165339 acl:5681 sco:0 events:3952 errors:0
	TX bytes:63034 acl:3431 sco:0 commands:933 errors:0
	Features: 0xbf 0xfe 0xcf 0xfe 0xdb 0xff 0x7b 0x87
	Packet type: DM1 DM3 DM5 DH1 DH3 DH5 HV1 HV2 HV3 
	Link policy: RSWITCH SNIFF 
	Link mode: SLAVE ACCEPT 

And then waiting for the code from @Marvo2011 to bring BT up again.
BT comes back up indeed. (Raspberry 3B+ with internal Bluetooth)

But the connection to the JBD doesn't get established directly afterwards. So the general problem of dropped connection still persists :-/
The connection came back 13 minutes later.

Here's the log of the manual test with hciconfig hci0 down. Please note that I modified the python code to output more logging (all the lines starting with ####). And I put more sleep commands between the shell commands. So the line references you see in the logfile don't match the code here on github.

Around 22:03:57 it looks like there are 2 threads running at the same time, where one is doing the reset and the other is trying to connect to the BMS. This doesn't seem to be useful I guess.

output of "tail -F -n 100 /data/log/dbus-blebattery.*/current | tai64nlocal"
2023-12-13 22:03:17.466078500 Device A4:C1:37:52:3E:9D (public)
2023-12-13 22:03:17.466084500 	Alias: JBD-AP21S002
2023-12-13 22:03:17.466087500 	Paired: no
2023-12-13 22:03:17.466088500 	Trusted: yes
2023-12-13 22:03:17.466090500 	Blocked: no
2023-12-13 22:03:17.466092500 	Connected: no
2023-12-13 22:03:17.466094500 	LegacyPairing: no
2023-12-13 22:03:17.466096500 	UUID: Device Information        (0000180a-0000-1000-8000-00805f9b34fb)
2023-12-13 22:03:17.472243500 
2023-12-13 22:03:18.626321500 INFO:SerialBattery:
2023-12-13 22:03:18.627048500 INFO:SerialBattery:Starting dbus-serialbattery
2023-12-13 22:03:18.628251500 INFO:SerialBattery:dbus-serialbattery v1.0.20230921dev
2023-12-13 22:03:19.006293500 ERROR:SerialBattery:###### reading hciattach via ps -ww
2023-12-13 22:03:19.085133500 INFO:SerialBattery:Init of LltJbd_Ble at A4:C1:37:52:3E:9D
2023-12-13 22:03:19.085140500 INFO:SerialBattery:Test of LltJbd_Ble at A4:C1:37:52:3E:9D
2023-12-13 22:03:19.470260500 ERROR:SerialBattery:###### Reset of hci_uart stack... Reconnecting to: A4:C1:37:52:3E:9D
2023-12-13 22:03:19.470968500 ERROR:SerialBattery:###### pkill -f hciattach
2023-12-13 22:03:24.094955500 ERROR:SerialBattery:>>> ERROR: Unable to connect with BLE device
2023-12-13 22:03:24.097285500 ERROR:SerialBattery:No BMS found at A4:C1:37:52:3E:9D
2023-12-13 22:03:24.097726500 ERROR:SerialBattery:ERROR >>> No battery connection at LltJbd_Ble
2023-12-13 22:03:24.532606500 ERROR:SerialBattery:###### rmmod
2023-12-13 22:03:29.671563500 ERROR:SerialBattery:###### modprobe
2023-12-13 22:03:34.735265500 ERROR:SerialBattery:###### exit
2023-12-13 22:03:35.002376500 
2023-12-13 22:03:35.002640500 INFO:Bluetooth details
2023-12-13 22:03:35.023819500 No default controller available
2023-12-13 22:03:40.070866500 
2023-12-13 22:03:41.171141500 INFO:SerialBattery:
2023-12-13 22:03:41.171825500 INFO:SerialBattery:Starting dbus-serialbattery
2023-12-13 22:03:41.172934500 INFO:SerialBattery:dbus-serialbattery v1.0.20230921dev
2023-12-13 22:03:41.558386500 ERROR:SerialBattery:###### reading hciattach via ps -ww
2023-12-13 22:03:41.631735500 ERROR:SerialBattery:###### reading hciattach did not succeed. Executing from file
2023-12-13 22:03:41.631743500 ERROR:SerialBattery:###### execute: /usr/bin/hciattach -t 10 /dev/ttyS0 bcm43xx 921600 noflow -
2023-12-13 22:03:51.641486500 Initialization timed out.
2023-12-13 22:03:51.641491500 bcm43xx_init
2023-12-13 22:03:51.642708500 ERROR:SerialBattery:###### sleep 5 seconds
2023-12-13 22:03:56.651875500 INFO:SerialBattery:Init of LltJbd_Ble at A4:C1:37:52:3E:9D
2023-12-13 22:03:56.651882500 INFO:SerialBattery:Test of LltJbd_Ble at A4:C1:37:52:3E:9D
2023-12-13 22:03:57.009526500 ERROR:SerialBattery:###### Reset of hci_uart stack... Reconnecting to: A4:C1:37:52:3E:9D
2023-12-13 22:03:57.010289500 ERROR:SerialBattery:###### pkill -f hciattach
2023-12-13 22:04:01.664373500 ERROR:SerialBattery:>>> ERROR: Unable to connect with BLE device
2023-12-13 22:04:01.664381500 ERROR:SerialBattery:No BMS found at A4:C1:37:52:3E:9D
2023-12-13 22:04:01.664385500 ERROR:SerialBattery:ERROR >>> No battery connection at LltJbd_Ble
2023-12-13 22:04:02.065338500 ERROR:SerialBattery:###### rmmod
2023-12-13 22:04:07.215980500 ERROR:SerialBattery:###### modprobe
2023-12-13 22:04:12.276487500 ERROR:SerialBattery:###### exit
2023-12-13 22:04:12.541584500 
2023-12-13 22:04:12.541867500 INFO:Bluetooth details
2023-12-13 22:04:12.562292500 No default controller available
2023-12-13 22:04:17.600245500 
2023-12-13 22:04:18.760214500 INFO:SerialBattery:
2023-12-13 22:04:18.760921500 INFO:SerialBattery:Starting dbus-serialbattery
2023-12-13 22:04:18.761979500 INFO:SerialBattery:dbus-serialbattery v1.0.20230921dev
2023-12-13 22:04:19.180545500 ERROR:SerialBattery:###### reading hciattach via ps -ww
2023-12-13 22:04:19.253008500 ERROR:SerialBattery:###### reading hciattach did not succeed. Executing from file
2023-12-13 22:04:19.253016500 ERROR:SerialBattery:###### execute: /usr/bin/hciattach -t 10 /dev/ttyS0 bcm43xx 921600 noflow -
2023-12-13 22:04:20.252350500 bcm43xx_init
2023-12-13 22:04:20.252356500 Set Controller UART speed to 921600 bit/s
2023-12-13 22:04:20.252359500 Flash firmware /lib/firmware/brcm/BCM4345C0.hcd
2023-12-13 22:04:20.252362500 Set Controller UART speed to 921600 bit/s
2023-12-13 22:04:20.252365500 Device setup complete
2023-12-13 22:04:20.258176500 ERROR:SerialBattery:###### sleep 5 seconds
2023-12-13 22:04:25.264339500 INFO:SerialBattery:Init of LltJbd_Ble at A4:C1:37:52:3E:9D
2023-12-13 22:04:25.264732500 INFO:SerialBattery:Test of LltJbd_Ble at A4:C1:37:52:3E:9D
2023-12-13 22:04:30.276496500 ERROR:SerialBattery:>>> ERROR: Unable to connect with BLE device
2023-12-13 22:04:30.279005500 ERROR:SerialBattery:No BMS found at A4:C1:37:52:3E:9D
2023-12-13 22:04:30.279497500 ERROR:SerialBattery:ERROR >>> No battery connection at LltJbd_Ble
2023-12-13 22:04:33.387849500 ERROR:SerialBattery:BleakClient(): Exception occurred: BleakDBusError('org.bluez.Error.Failed', 'Software caused connection abort') of type <class 'bleak.exc.BleakDBusError'> in /opt/victronenergy/dbus-serialbattery/bms/lltjbd_ble.py line #109
2023-12-13 22:04:33.687293500 
2023-12-13 22:04:33.687399500 INFO:Bluetooth details
2023-12-13 22:04:33.723427500 Attempting to disconnect from A4:C1:37:52:3E:9D
2023-12-13 22:04:33.723434500 Successful disconnected
2023-12-13 22:04:38.771556500 Device A4:C1:37:52:3E:9D (public)
2023-12-13 22:04:38.771562500 	Alias: JBD-AP21S002
2023-12-13 22:04:38.771564500 	Paired: no
2023-12-13 22:04:38.771566500 	Trusted: yes
2023-12-13 22:04:38.771568500 	Blocked: no
2023-12-13 22:04:38.771570500 	Connected: no
2023-12-13 22:04:38.771572500 	LegacyPairing: no
2023-12-13 22:04:38.771574500 	UUID: Device Information        (0000180a-0000-1000-8000-00805f9b34fb)
2023-12-13 22:04:38.775333500 
2023-12-13 22:04:39.873030500 INFO:SerialBattery:
2023-12-13 22:04:39.873460500 INFO:SerialBattery:Starting dbus-serialbattery
2023-12-13 22:04:39.874466500 INFO:SerialBattery:dbus-serialbattery v1.0.20230921dev
2023-12-13 22:04:40.250392500 ERROR:SerialBattery:###### reading hciattach via ps -ww
2023-12-13 22:04:40.320662500 INFO:SerialBattery:Init of LltJbd_Ble at A4:C1:37:52:3E:9D
2023-12-13 22:04:40.321135500 INFO:SerialBattery:Test of LltJbd_Ble at A4:C1:37:52:3E:9D
2023-12-13 22:04:43.358310500 ERROR:SerialBattery:BleakClient(): Exception occurred: BleakDBusError('org.bluez.Error.Failed', 'Software caused connection abort') of type <class 'bleak.exc.BleakDBusError'> in /opt/victronenergy/dbus-serialbattery/bms/lltjbd_ble.py line #109
2023-12-13 22:04:45.333093500 ERROR:SerialBattery:>>> ERROR: Unable to connect with BLE device
2023-12-13 22:04:45.335466500 ERROR:SerialBattery:No BMS found at A4:C1:37:52:3E:9D
2023-12-13 22:04:45.335925500 ERROR:SerialBattery:ERROR >>> No battery connection at LltJbd_Ble

... one eternity later ...

2023-12-13 22:16:41.078213500 ERROR:SerialBattery:BleakClient(): Exception occurred: BleakDBusError('org.bluez.Error.Failed', 'Software caused connection abort') of type <class 'bleak.exc.BleakDBusError'> in /opt/victronenergy/dbus-serialbattery/bms/lltjbd_ble.py line #109
2023-12-13 22:16:44.085467500 ERROR:SerialBattery:>>> ERROR: Unable to connect with BLE device
2023-12-13 22:16:44.087690500 ERROR:SerialBattery:No BMS found at A4:C1:37:52:3E:9D
2023-12-13 22:16:44.088139500 ERROR:SerialBattery:ERROR >>> No battery connection at LltJbd_Ble
2023-12-13 22:16:44.368568500 
2023-12-13 22:16:44.368684500 INFO:Bluetooth details
2023-12-13 22:16:44.372223500 [CHG] Device A4:C1:37:52:3E:9D RSSI: -59
2023-12-13 22:16:44.414327500 Attempting to disconnect from A4:C1:37:52:3E:9D
2023-12-13 22:16:44.414334500 Successful disconnected
2023-12-13 22:16:49.463191500 Device A4:C1:37:52:3E:9D (public)
2023-12-13 22:16:49.463198500 	Alias: JBD-AP21S002
2023-12-13 22:16:49.463200500 	Paired: no
2023-12-13 22:16:49.463202500 	Trusted: yes
2023-12-13 22:16:49.463203500 	Blocked: no
2023-12-13 22:16:49.463205500 	Connected: no
2023-12-13 22:16:49.463207500 	LegacyPairing: no
2023-12-13 22:16:49.463209500 	UUID: Device Information        (0000180a-0000-1000-8000-00805f9b34fb)
2023-12-13 22:16:49.464432500 
2023-12-13 22:16:50.551060500 INFO:SerialBattery:
2023-12-13 22:16:50.551471500 INFO:SerialBattery:Starting dbus-serialbattery
2023-12-13 22:16:50.552380500 INFO:SerialBattery:dbus-serialbattery v1.0.20230921dev
2023-12-13 22:16:50.935373500 ERROR:SerialBattery:###### reading hciattach via ps -ww
2023-12-13 22:16:51.006741500 INFO:SerialBattery:Init of LltJbd_Ble at A4:C1:37:52:3E:9D
2023-12-13 22:16:51.007212500 INFO:SerialBattery:Test of LltJbd_Ble at A4:C1:37:52:3E:9D
2023-12-13 22:16:58.876022500 INFO:SerialBattery:Connection established to LltJbd_Ble
2023-12-13 22:16:58.876495500 INFO:SerialBattery:Battery LltJbd_Ble connected to dbus from blea4c137523e9d
2023-12-13 22:16:58.876896500 INFO:SerialBattery:========== Settings ==========
2023-12-13 22:16:58.877372500 INFO:SerialBattery:> Connection voltage: 57.77V | Current: 0.0A | SoC: 12.46%
2023-12-13 22:16:58.877787500 INFO:SerialBattery:> Cell count: 18 | Cells populated: 18
2023-12-13 22:16:58.878223500 INFO:SerialBattery:> LINEAR LIMITATION ENABLE: True
2023-12-13 22:16:58.878666500 INFO:SerialBattery:> MAX BATTERY CHARGE CURRENT: 50.0A | MAX BATTERY DISCHARGE CURRENT: 60.0A
2023-12-13 22:16:58.879097500 INFO:SerialBattery:> MAX BATTERY CHARGE CURRENT: 100.0A | MAX BATTERY DISCHARGE CURRENT: 100.0A (read from BMS)
2023-12-13 22:16:58.879508500 INFO:SerialBattery:> CVCM:     True
2023-12-13 22:16:58.881609500 INFO:SerialBattery:> MIN CELL VOLTAGE: 2.9V | MAX CELL VOLTAGE: 3.45V
2023-12-13 22:16:58.881616500 INFO:SerialBattery:> CCCM CV:  True  | DCCM CV:  True
2023-12-13 22:16:58.881986500 INFO:SerialBattery:> CCCM T:   True  | DCCM T:   True
2023-12-13 22:16:58.882602500 INFO:SerialBattery:> CCCM SOC: True  | DCCM SOC: True
2023-12-13 22:16:58.883180500 INFO:SerialBattery:Serial Number/Unique Identifier: 52_280.0Ah
2023-12-13 22:16:58.930026500 INFO:SerialBattery:DeviceInstance = 2
2023-12-13 22:16:58.930662500 INFO:SerialBattery:com.victronenergy.battery.blea4c137523e9d
2023-12-13 22:17:00.699714500 INFO:SerialBattery:publish config values = 1

@Marvo2011
Copy link
Contributor Author

@randomname32 Yes we now it takes a lot of time to bring it back. I pushed code for usage of an usb module, can you test this? #890

@mr-manuel
Copy link
Collaborator

@randomname32 I have a PR for this in the queue, where the battery doesn't disconnect it the cell voltages are in the middle area.

@randomname32
Copy link

@randomname32 Yes we now it takes a lot of time to bring it back. I pushed code for usage of an usb module, can you test this? #890

I now tested a Bluetooth USB dongle on the RPi. I did not use the code from your PR, but I did the required changes manually (dtoverlay=disable-bt in u-boot/config.txt). My dbus-serialbattery version is v1.0.20231128dev (did a fresh install before testing).

I noticed 2 things:

  • the connection to the BMS was established immediately. With the internal BT it took a lot of tries until the connection succeeded
  • After I ran hciconfig hci0 down and a few seconds later hciconfig hci0 up, the connection recovered within less than minute, without any failed attempts.

I will have an eye on this and see if I get random connection issues or the bt device being down.

@Marvo2011
Copy link
Contributor Author

@randomname32 Yes we now it takes a lot of time to bring it back. I pushed code for usage of an usb module, can you test this? #890

I now tested a Bluetooth USB dongle on the RPi. I did not use the code from your PR, but I did the required changes manually (dtoverlay=disable-bt in u-boot/config.txt). My dbus-serialbattery version is v1.0.20231128dev (did a fresh install before testing).

I noticed 2 things:

  • the connection to the BMS was established immediately. With the internal BT it took a lot of tries until the connection succeeded
  • After I ran hciconfig hci0 down and a few seconds later hciconfig hci0 up, the connection recovered within less than minute, without any failed attempts.

I will have an eye on this and see if I get random connection issues or the bt device being down.

Nice sounds good, for me it's stable for 5 days now.

@Marvo2011
Copy link
Contributor Author

#890 with usb bluetooth module fixed it.

@randomname32
Copy link

For me, the bluetooth connection has also been stable for 5 days now.
I just got 2 error messages in the logfile, that are probably unrelated to bluetooth:

2023-12-16 01:34:21.947465500 ERROR:SerialBattery:Exception occurred: ZeroDivisionError('float division by zero') of type <class 'ZeroDivisionError'> in /opt/victronenergy/dbus-serialbattery/dbushelper.py line #894
2023-12-17 12:48:35.014719500 ERROR:SerialBattery:Exception occurred: ZeroDivisionError('float division by zero') of type <class 'ZeroDivisionError'> in /opt/victronenergy/dbus-serialbattery/dbushelper.py line #894

Louisvdw pushed a commit that referenced this issue Feb 28, 2024
* fix Sinowealth not loading
#702

* fix unique identifier function

* enable BMS over config, if disabled by default
Now you can also add more then one BMS for BMS_TYPE

* show battery port in log

* ANT BMS fixes
Fixed that other devices are recognized as ANT BMS

* Sinowealth BMS fixes
Fixed that other devices are recognized as Sinowealth BMS

* improved publish_battery error handling
switched from error count to seconds

* Improve Battery Voltage Handling in Linear Absorption Mode

* Refactor change time() to int(time()) for consistency in max_voltage_start_time and tDiff calculation
* Refactor battery voltage calculations for efficiency and clarity
* Remove penalty_buffer
* Reset max_voltage_start_time wenn we going to bulk(dynamic) mode

* updated changelog

* fix reply processing

* Reduce the big inrush current, if the CVL jumps
from Bulk/Absorbtion to Float
fix #659

* Check returned data lenght for Seplos BMS

Be stricter about the return data we accept, might fix the problem of grid meters accidently being recognized as a Seplos

* Validate current, voltage, capacity and SoC for all BMS
This prevents that a device, which is no BMS, is detected as BMS

* removed double check

* bump version

* fix validation if None

* updated changelog

* proposal to #659 formatted :)

* bugfix proposal to #659

* refactor setting float charge_mode

* fix type error, removed bluetooth cronjob

* updated changelog

* fix rs485 write communication errors by inserting sleeps, add debug print for charge mode and fix crash on write soc failures

* fix write problem on set_soc. also changed the switch charge/discharge function, just in case

* debug msg

* Bluetooth optimizations

* Fixes by @peterohman
#505 (comment)

* fix #712

* fix meaningless time to go values

* fix meaningless time to go values

* Duration of transition to float depends on number of cells

* Float transition - Voltage drop per second

* Update hlpdatabms4s.py

* Validate setting of FLOAT_CELL_VOLTAGE and avoid misconfiguration

* consider utils.LINEAR_RECALCULATION_EVERY to refresh CVL

* cleanup

* consider utils.LINEAR_RECALCULATION_EVERY to refresh CVL

* small refactor, introduced set_cvl_linear function to set CVL only once every LINEAR_RECALCULATION_EVERY seconds

* fix typo

* updated changelog

* remove debug msg

* remove debug msg

* undo debug change

* Daly BMS make auto reset soc configurable

* added debug and error information for CVL

* fix proposal for #733 (#735)

* Added: Tollerance to enter float voltage once the timer is triggered

* Add bulk voltage
Load to bulk voltage every x days to reset the SoC to 100% for some BMS

* JKBMS disable high voltage warning on bulk
reenable after bulk was completed

* fixed error

* disable high voltage warning for all BMS
when charging to bulk voltage

* fix error and change default value
measurementToleranceVariation from 0.025 to 0.5 else in OffGrid mode max voltage is always kept

* Added temperature names to dbus/mqtt

* Use current avg of last 300 cycles for TTG & TTS

* Calculate only positive Time-to-SoC points

* added current average of last 5 minutes

* make CCL and DCL more clear

* fix small error

* bugfix: LLTJBD BMS SOC different in Xiaoxiang app and dbus-serialbattery

* black formatting

* JDB BMS - Control FETs for charge, discharge and disable / enable balancer (#761)

* feature: Allow to control charge / discharge FET
* feature: Allow to enable / disable balancer

* bugfix: Cycle Capacity is in 10 mAh

Fixes SoC with factor 100 * 100% percentage

* JBD BMS show balancer state in GUI page IO (#763)

* Bump version

* Fix typos

* Smaller fixes
- fixes #792 (comment)

* Removed comments from utils.py
This should make more clear that there are no values to change

* Updated changelog

* possible fix for LLT/JBS connection problems
#769
#777

* bugfix: LLT/JBD BMS general packet data size check

* improved reinstall and disable script

* LLT/JBD BMS - Improved error handling and automatical driver restart
in case of error. Should fix:
- #730
- #769
- #777

* Fixed Building wheel for dbus-fast won't finish on weak systems
Fixes #785

* Support for Daly CAN Bus (#169)

* support for Daly CAN Bus
* fix constructor args
* revert port, needs fix
* add can filters
* comment logger

Some changes are still needed to work with the latest version. They will follow in a next PR.

---------

Co-authored-by: Samuel Brucksch <samuel@iternio.com>
Co-authored-by: Manuel <mr-manuel@outlook.it>

* JKBMS BLE - Introduction of automatic SOC reset (HW Version 11) (#736)

* Introduction of automatic SOC reset for JK BMS (HW Version 11)
* Fixed value mapping
* Rework of the code to make it simpler to use without additional configuration.
Moved execution of SOC reset. It's now executed while changing from "Float" to "Float Transition".
* Implementation of suggested changes
Persist initial BMS OVP and OVPR settings
Make use of max_cell_voltage to calculate trigger value for OVP alert

* Added: Daly CAN and JKBMS CAN

* added CAN bms to installation script
optimized CAN drivers

* smaller fixes

* Trigger JK BLE SOC reset when using Step Mode

* Moved trigger_soc_reset()

* fixes LLT/JBD SOC > 100%
#769

* changed VOLTAGE_DROP behaviour

* Fix JKBMS not starting if BMS manuf. date is empty

* corrected bulk, absorption and soc reset terms

* fix typo

* add JKBMS_BLE debugging data

* fix small error

* Some changes for lost bluetooth connection / hci_uart stack restart

* added logging to config

* add sleep before starting driver
prevents lot of timeouts after reinstalling the driver, since the restart is now much faster than before

* changed post install info

* fix error

* Daly BMS fixed embedded null byte
#837

* added info for SoC reset to default config file

* fix for #716
#716

* fix for #716 and JKBMS model recognition
#716

* optimized logging

* fix JKBMS recognition

* added debugging

* fixes #716
#716

* Bind device instance to unique_identifier
#718

* added data types to battery class
disabled unused variables

* save current charge state
#840

* correct file permissions

* updated changelog

* added periodic saveChargeDetails

* fix some small errors

* fix issue with ruuvi tags
When there are hundreds of unused ruuvi tags in the settings list that where added because thei where nearby the driver does not start correctly. These stale entries are disabled on the driver startup.
The issue was already filed to Victron developers

* CVL with i-controller instead of penaltysum

* cvl_controller: switch to choose PenaltySum or ICOntroller + documentation

* docu enhancement

* Add setting and install logic for usb bluetooth module

* round temperatures

* changed battery disconnect behaviour

* Fixes #891
#891

* updated changelog

* Add bluetooth device note to config.default.ini

* Fix typo in bluetooth note in config.default.ini

* fixed error in new cvl_controller

* fixed float division by zero and code optimization

* Restart MAX_VOLTAGE_TIME_SEC if cell diff > CELL_VOLTAGE_DIFF_KEEP_MAX_VOLTAGE_TIME_RESTART

* Calculation of the SOC based on coloumb-counting (#868)

* Calculation of the SOC in the driver based on coloumb-counting

* soc_calc: add current correction before integration

* soc_calc: correction map for current

* Soc_calc: CorrectionMap, switch to turn on/off correction, selectable initial value

* soc_calc: Bugfix

* soc_calc: Bugfix

* store soc in dbus for restart

* store soc in dbus for restart (formatted)

* store soc in dbus for restart (bugfix)

* save soc_calc only after change > 1.0

* store soc in dbus for restart (bugfix)

* logger does not work this way. do not know why

* writing and reading to dbus works

* Removed options: SOC_CALC_CURRENT_CORRECTION, SOC_CALC_RESET_VALUE_ON_RESTART, SOC_CALC_INIT_VALUE
sort soc_calc alphabetically

* fixed comments

* Updated changelog, small fixes

* Changed: PUBLISH_CONFIG_VALUES from 0/1 to True/False

* Changed: Code optimizations
- Changed some variables to be more clear
- Added comments for easier code understanding

* Calculated SOC: Added two decimals, added BMS SOC for MQTT & Node-RED

* Updated changelog, small fixes

* Changed: PUBLISH_CONFIG_VALUES from 0/1 to True/False

* Changed: Code optimizations
- Changed some variables to be more clear
- Added comments for easier code understanding

* Calculated SOC: Added two decimals, added BMS SOC for MQTT & Node-RED

* Fix #898
#898

* Changed: Fix issue loading settings from dbus

* Added nightly install option
makes it easier for users to pretest fixes

* Changed: more detailed error output when an exception happens

* Possible fix for #912
#912

* Fixes #919
#919

* Changed: Exit script with error, if port excluded
else the serialstarter stops at the dbus-serialbattery

* Fixed some smaller errors

* Updated pre-release workflow

* Fix JK BMS connection restart when bluetooth fails.

This fix installs a new thread to monitor the state of the original
scraping thread.
If scraping thread dies, it verifies that it did not because the
scraping was intentionally stopped by calling stop_scrapping.
When restarting the scrapper, it first calls the bluetooth
reset lambda function that was passed in the class contructor, such that
bluetooth is ready to make a proper connection.

* Fixes #916
#916

* Added Venus OS version to logfile

* Fix #840
#840

* Small code formatting fixes

* Optimized reinstall script. Restart GUI only on changes.

* Display debugging data in GUI when DEBUG enabled

* Install script now shows repositories and version numbers

* Update daly_can.py

Fixing #950 for DalyBMS

* Update jkbms_can.py

Fixing #950 for Jk BMS

* Fix black lint check

* Fixes #970
#970

* Fixed some errors in restoring values from dbus settings

* Moved sleep on start for all BMS

* Update config description

* Reworked a part of the default config

* fix typo in stopping services when reinstalling

* Fix Time-to-SoC and Time-to-Go calculation

* Add changelog info

* Round sum and diff voltage

* Temperature limitation variables where changed

* SoC limitation variables where changed

* Added error messages

* Remove unneeded code

* Reset SoC to 0% if empty

* Add GUIv2 for dbus-serialbattery

* Check free space before installing

* Added new GUIv2 version

* Removed Python 2 compatibility

* Changelog update

* Code cleanup
- Removed: get_temperatures()
- Removed: update_last_seen()

* Bluetooth code optimizations

* Fixed some JKBMS BLE not starting
#819

* Check if packages are already installed before install

* Fixed some SOC calculation errors

* Fixed None SOC on driver start

* Do not show and allow button change when callback is missing for:
- ForceChargingOff
- ForceDischargingOff
- TurnBalancingOff

* Check if a device instance is already used by creating a PID file

* Log and execute SOC reset to 100% or 0% only once

* Update GitHub workflow and issue templates

* Fixed LLT/JBD BMS with only on temperature sensor #791
#971

* Fix warning on reinstall

* Fix missing IO control for JBDBMS #992
#992

* Prepare for removing dev branch

---------

Co-authored-by: ogurevich <50322596+ogurevich@users.noreply.github.com>
Co-authored-by: Bernd Stahlbock <6627385+transistorgit@users.noreply.github.com>
Co-authored-by: wollew <wollew@users.noreply.github.com>
Co-authored-by: Oleg Gurevich <oleg@gurevich.de>
Co-authored-by: peterohman <psub@fieber.se>
Co-authored-by: Strawder, Paul <paul@coach-ai.com>
Co-authored-by: Paul Strawder <paulidstein@gmail.com>
Co-authored-by: Samuel Brucksch <SamuelBrucksch@users.noreply.github.com>
Co-authored-by: Samuel Brucksch <samuel@iternio.com>
Co-authored-by: ArendsM <136503378+ArendsM@users.noreply.github.com>
Co-authored-by: Meik Arends <github@arends.info>
Co-authored-by: Marvo2011 <Marvin.Edeler@gmail.com>
Co-authored-by: cflenker <christian.flenker@gmx.de>
Co-authored-by: cflenker <125555670+cflenker@users.noreply.github.com>
Co-authored-by: Cupertino Miranda <cupertinomiranda@gmail.com>
Co-authored-by: Martin Polehla <p0l0us@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

5 participants