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

install BLE battery as local independent service #502

Merged
merged 5 commits into from
Apr 13, 2023

Conversation

seidler2547
Copy link
Contributor

No description provided.

@seidler2547 seidler2547 marked this pull request as ready for review March 29, 2023 06:41
@seidler2547
Copy link
Contributor Author

I also changed the Serial "port" to use the BLE address, I guess that would be important to make multiple BLE BME work, althought I can't really test it.

@pos-ei-don
Copy link

I have several jk bms to test. If you help me, I can test this on a fresh venusos Installation.

@seidler2547
Copy link
Contributor Author

I have several jk bms to test. If you help me, I can test this on a fresh venusos Installation.

Oh cool. That would be great. I guess testing two serial and two Bluetooth BMS would be ideal test case. I don't think it's difficult. Just do the normal install, then edit the installble.sh to have two lines with the two MAC addresses, run it (or reboot) and it should work.

@mr-manuel
Copy link
Collaborator

mr-manuel commented Mar 29, 2023

To install you can execute:

cd /tmp

wget https://github.com/seidler2547/dbus-serialbattery/archive/refs/heads/jkbms_ble.zip
unzip jkbms_ble.zip

mv /data/etc/dbus-serialbattery /data/etc/dbus-serialbattery_$(date +%Y%m%d_%H%M%S)
cp -rf /tmp/dbus-serialbattery-jkbms_ble/etc/dbus-serialbattery/ /data/etc

chmod +x /data/etc/dbus-serialbattery/*.sh
chmod +x /data/etc/dbus-serialbattery/*.py
chmod +x /data/etc/dbus-serialbattery/service/run
chmod +x /data/etc/dbus-serialbattery/service/log/run

bash /data/etc/dbus-serialbattery/installble.sh

@pos-ei-don
Copy link

Thank you both!!

How can i debug it? I don't see any new devices in the victron console.

I found a process like this with alternating the mac adress from the BMS 1 + 2

python /data/etc/dbus-serialbattery/dbus-serialbattery.py Jkbms_Ble C8:47:8C:E8:02:62

do i have to pair the BMS with the rpi first?
I think i read somewhere about this, but cannot find it currently.

@pos-ei-don
Copy link

@mr-manuel Thank you, this helped a lot!

Just this line

cp -rf /tmp/venus-os_dbus-serialbattery-jkbms_ble/etc/dbus-serialbattery/ /data/etc

needs to be changed to

cp -rf /tmp/dbus-serialbattery-jkbms_ble/etc/dbus-serialbattery/ /data/etc

@mr-manuel
Copy link
Collaborator

Oh, yes thats correct. Thanks! Forgot it to change, since I copied it from my repo.

@pos-ei-don
Copy link

pos-ei-don commented Mar 29, 2023

Ok, found the old thread:

executed

bluetoothctl scan on
pair xx:x1
pair xx:x2

which worked! But still no new device in venusos shows up.
I found out that i still saw

python /data/etc/dbus-serialbattery/dbus-serialbattery.py Jkbms_Ble C8:47:8C:XX

Processes with old MAC-Adresses (from another BMS which i currently cannot pair).
I changed the settings and restarted, but this process was still there. So i rebooted to
get rid of this which worked.

Still cannot see any new devices and no new logfile.
Please advice me what to try next.


## DO NOT TOUCH THIS ##
install_service() {
mkdir -p /service/dbus-blebattery-$1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure about that, but is /service the correct folder for this? If i remember correctly in recent versions of venusos this is overwritten on every reboot?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this is correct. It's being recreated via /data/rc.local

@seidler2547
Copy link
Contributor Author

@pos-ei-don I think you don't really need the individual steps. If you're installing it on a new system it should be installed more or less using the official install instructions, it's important that the reinstalllocal or installlocal script is run so that it will create the service properly.

To install you can execute:

bash /data/etc/dbus-serialbattery/installble.sh

So the last step needs to be bash /data/etc/dbus-serialbattery/reinstalllocal.sh

@mr-manuel
Copy link
Collaborator

bluetoothctl scan on
pair xx:x1
pair xx:x2

@pos-ei-don this is only needed, if you are not using the default PIN of the JKBMS.

@pos-ei-don
Copy link

@seidler2547
But why isn it working here then? Can I see Logs?
The process seems to run, but its not adding a new device in victronos

@pos-ei-don
Copy link

bluetoothctl scan on
pair xx:x1
pair xx:x2

@pos-ei-don this is only needed, if you are not using the default PIN of the JKBMS.

I did not change the default pin!
But doing this should not disturb, should it?

What can I try next?

@seidler2547
Copy link
Contributor Author

@seidler2547 But why isn it working here then? Can I see Logs? The process seems to run, but its not adding a new device in victronos

The logs should be in /var/log/dbus-blebattery-0

@seidler2547
Copy link
Contributor Author

bluetoothctl scan on
pair xx:x1
pair xx:x2

@pos-ei-don this is only needed, if you are not using the default PIN of the JKBMS.

I did not change the default pin! But doing this should not disturb, should it?

What can I try next?

I think I didn't pair, but I did trust it.

@seidler2547
Copy link
Contributor Author

The other option to debug is to remove the lines from the installable script and just start it manually on the command line.

@pos-ei-don
Copy link

OK. Do I have to disable the BT Service in the console to "free" the Bluetooth Adapter for your Script?

@mr-manuel
Copy link
Collaborator

@seidler2547 But why isn it working here then? Can I see Logs? The process seems to run, but its not adding a new device in victronos

The logs should be in /var/log/dbus-blebattery-0

I'm not sure about that, since during the service creation (https://github.com/Louisvdw/dbus-serialbattery/blob/2a65d6c0fbcea030d52b6d0854a8b6536fa26900/etc/dbus-serialbattery/installble.sh) the creation for the log is missing. You should also add

    mkdir -p /service/dbus-blebattery-$1/log
    echo "#!/bin/sh" > /service/dbus-blebattery-$1/log/run
    echo "exec 2>&1" >> /service/dbus-blebattery-$1/log/run
    echo "exec multilog t s25000 n4 /var/log/dbus-blebattery-$1" >> /service/dbus-blebattery-$1/log/run
    chmod 755 /service/dbus-blebattery-$1/log/run

and then reboot.

@seidler2547
Copy link
Contributor Author

The other option to debug is to remove the lines from the installable script and just start it manually on the command line.

OK. Do I have to disable the BT Service in the console to "free" the Bluetooth Adapter for your Script?

It's advisable. Otherwise it reconnects a lot.

@pos-ei-don
Copy link

pos-ei-don commented Mar 29, 2023

I'm not sure about that, since during the service creation (https://github.com/Louisvdw/dbus-serialbattery/blob/2a65d6c0fbcea030d52b6d0854a8b6536fa26900/etc/dbus-serialbattery/installble.sh) the creation for the log is missing. You should also add

I executed these lines! Thank you!

The log just contains:
@40000000642459aa36e97114 *** CCGX booted (0) ***
@4000000064245b6635a9f01c *** CCGX booted (0) ***

so no big difference currently.
A bluetooth scan finds the devices.

[bluetooth]# scan on
Discovery started
[CHG] Controller E4:5F:01:09:34:## Discovering: yes
[NEW] Device C8:47:8C:E5:D3:## Bat3
[NEW] Device C8:47:8C:E8:1F:## Bat1
[NEW] Device C8:47:8C:E8:12:## Bat2

I now also trusted all 3.

@seidler2547
Copy link
Contributor Author

@mr-manuel great, thanks. I added the logging and added one more log message.

@pos-ei-don the part with echo "exec 2>&1" >> /service/dbus-blebattery-$1/log/run needs to read echo "exec 2>&1" >> /service/dbus-blebattery-$1/run - I fixed that in my latest commit.

@pos-ei-don
Copy link

I found this in the processlist.
Does this help?


 ps |grep ble
  720 root      4604 S    /usr/libexec/bluetooth/bluetoothd -E -f /etc/bluetooth/ble.conf
  991 root      1600 S    readproctitle service errors: ... 24, in <module>     from jkbms_ble import Jkbms_Ble   File "/data/etc/dbus-serialbatter
 1093 root      1612 S    supervise dbus-ble-sensors
 1718 root      1612 S    supervise dbus-blebattery-0

@pos-ei-don
Copy link

pos-ei-don commented Mar 29, 2023

I get this when i run it manually.
Scan-On did find this device as shown above.
ANy further things i can try?

/service/dbus-blebattery-0/run
Device C8:47:8C:E5:D3:## not available
Traceback (most recent call last):
  File "/data/etc/dbus-serialbattery/dbus-serialbattery.py", line 24, in <module>
    from jkbms_ble import Jkbms_Ble
  File "/data/etc/dbus-serialbattery/jkbms_ble.py", line 4, in <module>
    from jkbms_brn import JkBmsBle
  File "/data/etc/dbus-serialbattery/jkbms_brn.py", line 2, in <module>
    from bleak import BleakScanner, BleakClient
ModuleNotFoundError: No module named 'bleak'

Edit: I Updated to the version from 0a2adb2

@seidler2547
Copy link
Contributor Author

Oh, yes, you'll have to run

opkg update
opkg install python3-misc python3-pip
pip3 install bleak

These commands are also in installlocal.sh

@seidler2547
Copy link
Contributor Author

seidler2547 commented Mar 29, 2023

@pos-ei-don although I'm not sure anymore if the opkg part is correct, I used

opkg install  python3-pip python3-modules

but I don't know if either -misc or -modules is actually needed.

@seidler2547 seidler2547 mentioned this pull request Mar 29, 2023
@pos-ei-don
Copy link

python3-pip

was already installed.

pip3 install bleak

worked.

opkg install python3-pip
No packages installed or removed.
root@venusos:~# pip3
pip3    pip3.8
root@venusos226:~# pip3 install bleak
Collecting bleak
....

After that, the device got created,
the script ended with this error
but the Device still recives updates

~# /service/dbus-blebattery-0/run
Attempting to disconnect from C8:47:8C:E5:D3:## 
[CHG] Device C8:47:8C:E5:D3:## ServicesResolved: no
Successful disconnected
INFO:SerialBattery:Starting dbus-serialbattery
INFO:SerialBattery:dbus-serialbattery v0.14b3ble
INFO:SerialBattery:init of jkbmsble at C8:47:8C:E5:D3:##
INFO:SerialBattery:test of jkbmsble at C8:47:8C:E5:D3:##
connect and scrape on address: C8:47:8C:E5:D3:##
btloop


INFO:SerialBattery:JK BMS found!
INFO:SerialBattery:Connection established to Jkbms_Ble
INFO:SerialBattery:Battery Jkbms BLE connected to dbus from c8478ce5d3##
INFO:SerialBattery:=== Settings ===
INFO:SerialBattery:> Connection voltage NoneV | current NoneA | SOC None%
INFO:SerialBattery:> Cell count None | cells populated 0
INFO:SerialBattery:> CCCM SOC True | DCCM SOC True
INFO:SerialBattery:> CCCM CV True | DCCM CV True
INFO:SerialBattery:> CCCM T True | DCCM T True
INFO:SerialBattery:> MIN_CELL_VOLTAGE 2.9V | MAX_CELL_VOLTAGE 3.45V
Traceback (most recent call last):
  File "/data/etc/dbus-serialbattery/dbus-serialbattery.py", line 125, in <module>
    main()
  File "/data/etc/dbus-serialbattery/dbus-serialbattery.py", line 110, in main
    helper = DbusHelper(battery)
  File "/data/etc/dbus-serialbattery/dbushelper.py", line 36, in __init__
    self._dbusservice = VeDbusService(
  File "/opt/victronenergy/dbus-systemcalc-py/ext/velib_python/vedbus.py", line 77, in __init__
    self._dbusname = dbus.service.BusName(servicename, self._dbusconn, do_not_queue=True)
  File "/usr/lib/python3.8/site-packages/dbus/service.py", line 144, in __new__
    raise NameExistsException(name)
dbus.exceptions.NameExistsException: Bus name already exists: com.victronenergy.battery.c8478ce5d3##
Exiting bt-loop
Exception ignored in: <function VeDbusService.__del__ at 0xb64eb418>
Traceback (most recent call last):
  File "/opt/victronenergy/dbus-systemcalc-py/ext/velib_python/vedbus.py", line 93, in __del__
    if self._dbusname:
AttributeError: 'VeDbusService' object has no attribute '_dbusname'

Do I get the "NameExistsException" because this device is also connected by 485RS?
My other Cell-Packs connected per USB are created with this driver.

@seidler2547
Copy link
Contributor Author

@pos-ei-don I think now you're getting this error because you're running it manually but it was already started automatically.

@seidler2547
Copy link
Contributor Author

Do you say the device is visible in the Victron GUI now? Then everything works as expected. You should not run the script manually anymore, the logs for the service are in /var/log/dbus-blebattery-0/current

@pos-ei-don
Copy link

THankl you!!
Readding a second BLE-BMS does not seem to work.
Here is the manual start output!
To avoid errors because of the automatic-start, I will reboot now!

/service/dbus-blebattery-0/run
Attempting to disconnect from C8:47:8C:E5:D3:##
[CHG] Device C8:47:8C:E5:D3:## ServicesResolved: no
Successful disconnected
INFO:SerialBattery:Starting dbus-serialbattery
INFO:SerialBattery:dbus-serialbattery v0.14b3ble
INFO:SerialBattery:init of jkbmsble at C8:47:8C:E5:D3:##
INFO:SerialBattery:test of jkbmsble at C8:47:8C:E5:D3:##
connect and scrape on address: C8:47:8C:E5:D3:##
btloop
ERROR:SerialBattery:ERROR >>> No battery connection at Jkbms_Ble
Exiting bt-loop

@seidler2547
Copy link
Contributor Author

seidler2547 commented Mar 29, 2023

If you have two BMS you want to connect to using BLE you need to change the number after install_service (in installble.sh):

install_service 0 Jkbms_Ble C8:47:8C:E5:D3:##
install_service 1 Jkbms_Ble C8:47:8C:E8:1F:##

(note that the second line has 1). Then the logs for this service are in /var/log/dbus-blebattery-1/current

@pos-ei-don
Copy link

THankl you!! Readding a second BLE-BMS does not seem to work. Here is the manual start output! To avoid errors because of the automatic-start, I will reboot now!

/service/dbus-blebattery-0/run
Attempting to disconnect from C8:47:8C:E5:D3:##
[CHG] Device C8:47:8C:E5:D3:## ServicesResolved: no
Successful disconnected
INFO:SerialBattery:Starting dbus-serialbattery
INFO:SerialBattery:dbus-serialbattery v0.14b3ble
INFO:SerialBattery:init of jkbmsble at C8:47:8C:E5:D3:##
INFO:SerialBattery:test of jkbmsble at C8:47:8C:E5:D3:##
connect and scrape on address: C8:47:8C:E5:D3:##
btloop
ERROR:SerialBattery:ERROR >>> No battery connection at Jkbms_Ble
Exiting bt-loop

Yess!! I saw them when starting it manually!
BUT:.. Reboot did not work, the gui is not comming up. SSH still works, but Log is empty.
I try to disable the device from autostart for now

@pos-ei-don
Copy link

install_service 0 Jkbms_Ble C8:47:8C:E5:D3:##
install_service 1 Jkbms_Ble C8:47:8C:E8:1F:##

I had this!!
Autostart with a single BMS works, with a second does not work.

@pos-ei-don
Copy link

The log is somehow "empty".

 tail /var/log/dbus-blebattery-/current
@40000000642459aa36e97114 *** CCGX booted (0) ***
@4000000064245b6635a9f01c *** CCGX booted (0) ***
@4000000064245e0531ab1c5c *** CCGX booted (0) ***
@400000006424698c32a2b32c *** CCGX booted (0) ***
@4000000064246a3b303c1754 *** CCGX booted (0) ***
@4000000064246b843958a03c *** CCGX booted (0) ***
@4000000064246be600cf09f4 *** CCGX booted (0) ***

So currently I'd say it works with 1 JK-BMS, but not with two.

@seidler2547
Copy link
Contributor Author

Hmm okay, that's strange. But to be honest, it could be how the BLE stack or how python-bleak works or is used. Here I'm a bit out of my depth. But did you say when you have only one on autostart and start the other one manually it works?

@seidler2547
Copy link
Contributor Author

seidler2547 commented Mar 29, 2023

Is it really /var/log/dbus-blebattery-/current ? Because it is missing the 1 then... Let me double-check the code there.

... can't find anything obvious, but I might be missing something.

@pos-ei-don
Copy link

Is it really /var/log/dbus-blebattery-/current ? Because it is missing the 1 then... Let me double-check the code there.

Ah... all 3 exists. Here is the rest

 tail /var/log/dbus-blebattery-0/current -n 30 | tai64nlocal &&  tail /var/log/dbus-blebattery-1/current -n 30 | tai64nlocal
2023-03-29 16:47:48.286239500 INFO:SerialBattery:BAT: JKBMS 10.XW 16 cells
2023-03-29 16:47:48.343795500 INFO:SerialBattery:DeviceInstance = 7
2023-03-29 16:47:48.344112500 INFO:SerialBattery:Changed DeviceInstance = 7
2023-03-29 16:48:28.044563500 *** CCGX booted (0) ***
2023-03-29 16:49:05.554415500 Attempting to disconnect from C8:47:8C:E8:1F:## 
2023-03-29 16:49:05.554421500 Successful disconnected
2023-03-29 16:49:13.835808500 INFO:SerialBattery:Starting dbus-serialbattery
2023-03-29 16:49:13.836168500 INFO:SerialBattery:dbus-serialbattery v0.14b3ble
2023-03-29 16:49:13.837342500 INFO:SerialBattery:init of jkbmsble at C8:47:8C:E8:1F:## 
2023-03-29 16:49:13.837642500 INFO:SerialBattery:test of jkbmsble at C8:47:8C:E8:1F:## 
2023-03-29 16:52:24.824124500 *** CCGX booted (0) ***
2023-03-29 16:53:02.868799500 Attempting to disconnect from C8:47:8C:E8:1F:## 
2023-03-29 16:53:02.868805500 Successful disconnected
2023-03-29 16:53:10.144618500 INFO:SerialBattery:Starting dbus-serialbattery
2023-03-29 16:53:10.144623500 INFO:SerialBattery:dbus-serialbattery v0.14b3ble
2023-03-29 16:53:10.144626500 INFO:SerialBattery:init of jkbmsble at C8:47:8C:E8:1F:## 
2023-03-29 16:53:10.144629500 INFO:SerialBattery:test of jkbmsble at C8:47:8C:E8:1F:## 
2023-03-29 16:53:22.333731500 INFO:SerialBattery:## BMS found!
2023-03-29 16:53:22.334273500 INFO:SerialBattery:Connection established to Jkbms_Ble
2023-03-29 16:53:22.336385500 INFO:SerialBattery:Battery Jkbms BLE connected to dbus from c8478ce81f04
2023-03-29 16:53:22.336391500 INFO:SerialBattery:=== Settings ===
2023-03-29 16:53:22.336394500 INFO:SerialBattery:> Connection voltage NoneV | current NoneA | SOC None%
2023-03-29 16:53:22.336397500 INFO:SerialBattery:> Cell count None | cells populated 0
2023-03-29 16:53:22.336400500 INFO:SerialBattery:> CCCM SOC True | DCCM SOC True
2023-03-29 16:53:22.338906500 INFO:SerialBattery:> CCCM CV True | DCCM CV True
2023-03-29 16:53:22.338911500 INFO:SerialBattery:> CCCM T True | DCCM T True
2023-03-29 16:53:22.338914500 INFO:SerialBattery:> MIN_CELL_VOLTAGE 2.9V | MAX_CELL_VOLTAGE 3.45V
2023-03-29 16:53:22.464630500 INFO:SerialBattery:DeviceInstance = 7
2023-03-29 16:53:22.464635500 INFO:SerialBattery:com.victronenergy.battery.c8478ce81f04
2023-03-29 16:53:22.464638500 INFO:SerialBattery:BAT: JKBMS 10.XW 16 cells
2023-03-29 16:51:22.741571500 INFO:SerialBattery:test of jkbmsble at C8:47:8C:E8:12:## 
2023-03-29 16:51:37.541524500 ERROR:SerialBattery:ERROR >>> No battery connection at Jkbms_Ble
2023-03-29 16:51:37.541529500 connect and scrape on address: C8:47:8C:E8:12:## 
2023-03-29 16:51:37.541532500 btloop
2023-03-29 16:51:38.114284500 Exiting bt-loop
2023-03-29 16:51:38.290699500 Attempting to disconnect from C8:47:8C:E8:12:## 
2023-03-29 16:51:38.290704500 Successful disconnected
2023-03-29 16:51:39.169257500 INFO:SerialBattery:Starting dbus-serialbattery
2023-03-29 16:51:39.169262500 INFO:SerialBattery:dbus-serialbattery v0.14b3ble
2023-03-29 16:51:39.169265500 INFO:SerialBattery:init of jkbmsble at C8:47:8C:E8:12:## 
2023-03-29 16:51:39.169268500 INFO:SerialBattery:test of jkbmsble at C8:47:8C:E8:12:## 
2023-03-29 16:51:44.435070500 ERROR:SerialBattery:## BMS found at C8:47:8C:E8:12:## 
2023-03-29 16:51:44.435381500 ERROR:SerialBattery:ERROR >>> No battery connection at Jkbms_Ble
2023-03-29 16:51:44.598705500 Attempting to disconnect from C8:47:8C:E8:12:## 
2023-03-29 16:51:44.598710500 Successful disconnected
2023-03-29 16:51:45.478876500 INFO:SerialBattery:Starting dbus-serialbattery
2023-03-29 16:51:45.479413500 INFO:SerialBattery:dbus-serialbattery v0.14b3ble
2023-03-29 16:51:45.480624500 INFO:SerialBattery:init of jkbmsble at C8:47:8C:E8:12:## 
2023-03-29 16:51:45.481026500 INFO:SerialBattery:test of jkbmsble at C8:47:8C:E8:12:## 
2023-03-29 16:52:00.268135500 ERROR:SerialBattery:ERROR >>> No battery connection at Jkbms_Ble
2023-03-29 16:52:00.268140500 connect and scrape on address: C8:47:8C:E8:12:## 
2023-03-29 16:52:00.268143500 btloop
2023-03-29 16:52:10.371331500 Exiting bt-loop
2023-03-29 16:52:10.543650500 Attempting to disconnect from C8:47:8C:E8:12:## 
2023-03-29 16:52:10.543655500 Successful disconnected
2023-03-29 16:52:11.440859500 INFO:SerialBattery:Starting dbus-serialbattery
2023-03-29 16:52:11.441201500 INFO:SerialBattery:dbus-serialbattery v0.14b3ble
2023-03-29 16:52:11.442209500 INFO:SerialBattery:init of jkbmsble at C8:47:8C:E8:12:## 
2023-03-29 16:52:11.442482500 INFO:SerialBattery:test of jkbmsble at C8:47:8C:E8:12:## 
2023-03-29 16:52:24.834129500 *** CCGX booted (0) ***

@seidler2547
Copy link
Contributor Author

Okay, then I have the strong suspicion that the culprit is the actual BLE code then. Maybe there's a fundamental change needed in how the service communicates with the device (i.e. releasing it every time to let other processes communicate with other BMSs). But I feel that's somehow out of scope for this PR.

@pos-ei-don
Copy link

Ok, I just wanted to help testing. Feel free to contact me again if i can test anything or help further!
Thank you a lot for all your work!

@pos-ei-don
Copy link

Ah, but iI just want to add that the driver also stopped adding batteries connected by serial.
The only battery for me that currently works with exactly this version of the driver is only one BLE battery.
The others are ignored.

See the log

tail /var/log/dbus-serialbattery.ttyUSB5/current  | tai64nlocal
2023-03-29 10:33:11.071956500 *** CCGX booted (0) ***
2023-03-29 13:52:14.161629500 *** CCGX booted (0) ***
2023-03-29 15:30:41.098633500 *** CCGX booted (0) ***
2023-03-29 15:38:05.125970500 *** CCGX booted (0) ***
2023-03-29 15:49:16.058907500 *** CCGX booted (0) ***
2023-03-29 16:38:27.069433500 *** CCGX booted (0) ***
2023-03-29 16:41:22.036068500 *** CCGX booted (0) ***
2023-03-29 16:46:51.178837500 *** CCGX booted (0) ***
2023-03-29 16:48:28.261498500 *** CCGX booted (0) ***
2023-03-29 16:52:25.026673500 *** CCGX booted (0) ***

For me its not a big deal, I only use the virtual mqtt-battery driver from @mr-manuel , so i don't need this!

@baranator
Copy link
Contributor

@pos-ei-don although I'm not sure anymore if the opkg part is correct, I used

opkg install  python3-pip python3-modules

but I don't know if either -misc or -modules is actually needed.

-misc was needed in my case; otherwise i got some weird errors and nothing worked. -modules is not necessary

@baranator
Copy link
Contributor

Ah, but iI just want to add that the driver also stopped adding batteries connected by serial. The only battery for me that currently works with exactly this version of the driver is only one BLE battery. The others are ignored.

See the log

tail /var/log/dbus-serialbattery.ttyUSB5/current  | tai64nlocal
2023-03-29 10:33:11.071956500 *** CCGX booted (0) ***
2023-03-29 13:52:14.161629500 *** CCGX booted (0) ***
2023-03-29 15:30:41.098633500 *** CCGX booted (0) ***
2023-03-29 15:38:05.125970500 *** CCGX booted (0) ***
2023-03-29 15:49:16.058907500 *** CCGX booted (0) ***
2023-03-29 16:38:27.069433500 *** CCGX booted (0) ***
2023-03-29 16:41:22.036068500 *** CCGX booted (0) ***
2023-03-29 16:46:51.178837500 *** CCGX booted (0) ***
2023-03-29 16:48:28.261498500 *** CCGX booted (0) ***
2023-03-29 16:52:25.026673500 *** CCGX booted (0) ***

For me its not a big deal, I only use the virtual mqtt-battery driver from @mr-manuel , so i don't need this!

that is some weird behaviour...

Only one battery is possible independent of attachment via ble or serial -> so it's possibly no problem with ble-code itself but some problem with concurrecy of multiple runs of dbus-serialbattery.py? But there were multiple instances of that script before when someone attached more than one serialdongle and that worked, didn't it?

How did /var/log/dbus-blebattery-/current got created - is it a relict of manual running the script outside the service without args?

And why is the log almost completely empty? the first thing dbus-serialbattery.py should (unconditionally) do after being called is logger.info("dbus-serialbattery v" + str(DRIVER_VERSION) + DRIVER_SUBVERSION) ....this does not appear in the logs. so maybe still some hidden (import-?) error happens and prevents the code from executing?

@seidler2547
Copy link
Contributor Author

Ah, but iI just want to add that the driver also stopped adding batteries connected by serial. The only battery for me that currently works with exactly this version of the driver is only one BLE battery. The others are ignored.

See the log

tail /var/log/dbus-serialbattery.ttyUSB5/current  | tai64nlocal
2023-03-29 10:33:11.071956500 *** CCGX booted (0) ***
2023-03-29 13:52:14.161629500 *** CCGX booted (0) ***
2023-03-29 15:30:41.098633500 *** CCGX booted (0) ***
2023-03-29 15:38:05.125970500 *** CCGX booted (0) ***
2023-03-29 15:49:16.058907500 *** CCGX booted (0) ***
2023-03-29 16:38:27.069433500 *** CCGX booted (0) ***
2023-03-29 16:41:22.036068500 *** CCGX booted (0) ***
2023-03-29 16:46:51.178837500 *** CCGX booted (0) ***
2023-03-29 16:48:28.261498500 *** CCGX booted (0) ***
2023-03-29 16:52:25.026673500 *** CCGX booted (0) ***

For me its not a big deal, I only use the virtual mqtt-battery driver from @mr-manuel , so i don't need this!

Did you ever run installlocal.sh ? Because if not then the serial part didn't get installed.

@pos-ei-don
Copy link

Did you ever run installlocal.sh ? Because if not then the serial part didn't get installed.

Maybe not, it did all the steps i got to test this build.
Unfortunately I already removed this testdevice.
But I can recreate it if there is something new to test.
Should we move the "Enable multiple BLE-Devices" issue to a sepperate Tracker?

@pos-ei-don
Copy link

I just found out, that 2 BLE-Batteries work!!!
It was just an error, a Cellphone automatically connected to one BMS, so this driver failed in my test.

Now it seems to work well if all Devices answer fast enough at boot time!!
It seems that if at reboot time a Cellphone is connected to a BMS, this will never be added to the Victron Console.
I think it should permanently scan if the Device is available, maybe it should even add all configured Devices to
Victron and show them as disconnected?!?
If I configure 3 BLE BMSes, and the second is not available, the third does not get added aswell.

@seidler2547
Copy link
Contributor Author

@pos-ei-don that's very good to know. I agree it would be a good thing to have the devices be always registered since we give it the BLE address.

However, I recently checked the dbus messages on my system and I saw all the BLE messages printed there. So I have a suspicion that it might be possible to forego the use of python-bleak and use the built-in Bluetooth implementation by listening to dbus messages and decoding them accordingly. That would have the additional benefit of not needing to manually add the BLE addresses because they should just show up in the device scan.

@mr-manuel
Copy link
Collaborator

It seems that if at reboot time a Cellphone is connected to a BMS, this will never be added to the Victron Console.

Only one device at the same time can be connected to a JKBMS.

@pos-ei-don
Copy link

It seems that if at reboot time a Cellphone is connected to a BMS, this will never be added to the Victron Console.

Only one device at the same time can be connected to a JKBMS.

I understand. But it would be nice if the driver tries it again later, when I disconnect es the cellphone. I sum the values from these bms on a secondary venusos Installation in NodeRed and send those calculate values to you mqtt Aggregated battery device on the Main venusos. To get the correct sum of "maximum Charge current", I need to know all connected BMS.
I have also a feature request: it would be nice to have the possibillity within the console to "disconnect" a bms from it, for a certain time. This is needed for the case that you have to change a setting in the bms and you need to connect the cellphone for changing a value (p. Ex. Balance voltage)

@mr-manuel
Copy link
Collaborator

The ble driver prior this PR tries to connect over and over again. As soon as the ble device is ready it connects, Seems to behave different with this PR?

The disconnection is not that easy. I noted also when I only restarted the driver, it did not connect anymore to the BMS, since somehow a connection is still open. I had to restart the driver and the bluetooth service. See https://github.com/mr-manuel/venus-os_dbus-serialbattery/blob/jkbms_ble/etc/dbus-serialbattery/restart-driver-and-ble.sh

In general you should not have to change very often the settings. I haven't changed them for over a year. If you have to, you can

  1. Reboot your Venus OS and connect to the battery you need during reboot
  2. Stop bluetooth service /etc/init.d/bluetooth stop, connect to the BMS you need with the app and then start the bluetooth service again /etc/init.d/bluetooth start

@seidler2547
Copy link
Contributor Author

@mr-manuel that's why I put a disconnect statement in the service file. That works for me.

@pos-ei-don I think the driver will retry. The logic isn't different to before: it tries to connect. If that doesn't work, it exits. Then, the service managr will restart the service and it'll try again.

@mr-manuel mr-manuel merged commit 5065083 into Louisvdw:jkbms_ble Apr 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants