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

Bluetooth-Support for JK BMS #372

Merged
merged 18 commits into from
Jan 9, 2023
Merged

Bluetooth-Support for JK BMS #372

merged 18 commits into from
Jan 9, 2023

Conversation

baranator
Copy link
Contributor

This fork adds BLE-support for some JK BMS systems. I splitted this in two repositories: One for the dbus-serialbattery binding itself and one for a universal jkbms-python library. As that one is not officially published yet, you have to manually download it to the dbus-serialbattery-directory to make things work:

wget https://raw.githubusercontent.com/baranator/jkbms_brntr/master/src/jkbms_brntr/jkbms.py -O /data/etc/dbus-serialbattery/jkbms_brn.py

also python-bleak must be installed for BLE-support:

opkg install python3-pip python3-modules
pip3 install bleak

later those actions should be automated and only the really necessary python modules installed.

@baranator baranator marked this pull request as draft December 28, 2022 13:09
@baranator
Copy link
Contributor Author

Things seem to work already, if start-serialbattery.sh is called manually, but i cannot get the service to run - maybe my whole installation got broken while testing and try&errror.

Meanwhile i found out, that you do not need to install the whole python3-modules package, but only python3-misc for bleak being installable by pip

@baranator baranator mentioned this pull request Dec 30, 2022
3 tasks
@baranator
Copy link
Contributor Author

baranator commented Dec 30, 2022

Freshly reinstalled Venus 2.92 and i cannot get the service up again. No service-file exists in /service no logs are created in /var/log/.... This also affects the unforked installation via sh installrelease.sh
Is this a general problem?

nvm... this was a file-permission problem; after chmod 777 before createbuild.sh service starts as exspected.

@baranator
Copy link
Contributor Author

two more notes:

  • for now, though not used, an usb-serialdongle must be attached to the venus os as dbus-serialbattery needs a serialdevice to bring its service up
  • in the web ui Settings/Bluetooth should be disabled, otherwise it interferes with the bluetooth connection to the jkbms and you get a reconnect and the corresponding two beeps every minute (works though)

@baranator
Copy link
Contributor Author

baranator commented Jan 2, 2023

tested things for a couple of days. There seem to be stability problems with the raspberry pis internal bluetooth when used together with internal wifi: After a couple of hours the bluetooth dies and is not even shown in bluetoothctl anymore. After reboot everythings works again. I have no idea if there is a way in venus os to completely reset the bluetooth stack?!

(see: raspberrypi/linux#1552 and https://forum.fhem.de/index.php?topic=70179.0 )

I will test this with an external wifi-card.

@baranator
Copy link
Contributor Author

tried with an external wifi-dongle an an dtoverlay=disable-wifi in /u-boot/config.txt but nothing changed; The other way around (builtin wifi & external bt-dongle) does not work for now (missing kernel modules?)

I had no success in resetting the internal bluetooth without a reboot. I tried un- and reloading kernel-modules bluetooth and btbcm, as in combination with sh /etc/init.d/bluetooth restart

@baranator
Copy link
Contributor Author

got my bt-usb-dongle running by manually installing rtl8761b firmware as described here (extract to /lib/firmware/rtl_bt/).

Lets see if this fixes the bt-stability problems....

@howetech
Copy link

howetech commented Jan 3, 2023

Great to see you are making progress on this.

Just a note that I'm currently using bluetooth and wifi together on a Raspberry Pi 3a running Venus OS 2.92 so they can both work at the same time. I am only using the bluetooth for a Ruuvi temp sensor so not sure if this makes any difference.

I'm very keen to use this once it is stable. I've got 2 batteries with JK BMS which will be much easier to monitor with bluetooth, rather than having to use RS485 adapters and wiring to the rasbpi.

@baranator
Copy link
Contributor Author

baranator commented Jan 4, 2023

Just a note that I'm currently using bluetooth and wifi together on a Raspberry Pi 3a running Venus OS 2.92 so they can both work at the same time. I am only using the bluetooth for a Ruuvi temp sensor so not sure if this makes any difference.

Strange. Maybe this simply not every rpi3 is affected by this behaviour? Or maybe it's a matter of amount of transferred data that somehow somewhere causes a buffer overflow after time? I would assume that a single tempsensor sends much less data than the bms (~300Bytes every second).

Whatever. I don't want to sound prematurely optimistic, but with the external bt-dongle everything is running since 23 hours now - with the internal i couldn't get more more than 15hours in various attempts...So if it crashes on internat bt, using an external usb-bt could be a solution (although i would still prefer making it run without additional hardware, at least by doing some kind of reset without rebooting in case of failure )

@baranator
Copy link
Contributor Author

i'll put this bluetooth issue as "works for now" aside for now.

@Louisvdw :
I think the most essential stuff is working now. Therefore for the next steps towards integration I / we need to discuss a few points:

  • Integration: Shall the bluetooth-functionality (already) be an essential part of dbus-serialbattery or rather manually be activated by a flag to installrelease.sh / installlocal.sh ? I personally would prefer the second approach at least as long as this is not tested by multiple people. Something like installrelease.sh --with-jkbmsble
  • Installation: I would add the mentioned above, necessary opkg- and pip-commands, as well as (as long as my universal jkbms-lib is not in the pip-repos) a wget for the jkbms_brn.py-File to installlocal.sh (or rather reinstalllocal? dunno?)
  • Startup and necessity for usb-serial-dongle: I'm not sure how exactly the service is brought up and if there is any (easy) way to make it run, when somebody just wants to use the ble-connection and does not have a usb-serial-dongle.

@Louisvdw Louisvdw changed the base branch from master to jkbms_ble January 4, 2023 18:09
@Louisvdw
Copy link
Owner

Louisvdw commented Jan 4, 2023

My suggestion would be that I can create a beta build for this. Users can then install this through the normal commands using a spesific version install. Then we can get feedback and once any issues is fixed we can merge that into master.
I have created the jkbms_ble branch and changed this PR against that one.

Perhaps to make it a bit easier you can add a copy of the jkbms_brn.py to this repo and add that reference to the buildfiles.lst so that it will be included in the build. You also need to add jkbms_ble.py to the buildfiles.lst
Then just add the opkg and pip3 commands to installrelease.sh with the --with-jkbmsble should be sufficient for now. That would help with versioning if the reference still has some changes coming.

I am not sure about the serial dongle vs ble-connection. There is a service called serial-starter that polls for any changes to the serial ports and then starts all the drivers registered with it. This is how the serialbattery gets started. I'm not sure if the bluetooth services is something completely seperate, but we might need to test that.

@baranator
Copy link
Contributor Author

baranator commented Jan 6, 2023

My suggestion would be that I can create a beta build for this. Users can then install this through the normal commands using a spesific version install. Then we can get feedback and once any issues is fixed we can merge that into master. I have created the jkbms_ble branch and changed this PR against that one.

okay, sounds fine. will do that.

Perhaps to make it a bit easier you can add a copy of the jkbms_brn.py to this repo and add that reference to the buildfiles.lst so that it will be included in the build. You also need to add jkbms_ble.py to the buildfiles.lst Then just add the opkg and pip3 commands to installrelease.sh with the --with-jkbmsble should be sufficient for now. That would help with versioning if the reference still has some changes coming.

i'm fine with that too. But i think i will not implement that flag (for now) but make the ble default in the beta-build. As i've seen in @ppuetsch #393 PR, there is some work going in separating stuff into config files. Maybe there one could also enable/disable the ble support. This should make the handling easier, otherwise i would somehow need to tinker some weird awk/sed-stuff to remove the ble-lines from utils.py during installation. I will have a closer look on this later.

I am not sure about the serial dongle vs ble-connection. There is a service called serial-starter that polls for any changes to the serial ports and then starts all the drivers registered with it. This is how the serialbattery gets started. I'm not sure if the bluetooth services is something completely seperate, but we might need to test that.

The bluetooth-service itself is running on venus os per default. From there on you simply can access it anytime via the bleak library. So at the moment i simply used serial-starter as an entry-point only, completely ignore all details about the specific serial port and call the necessary bleak-commands in my library. That works but 1) needs an serial-dongle connected even it is not used at all 2) it's not THAT aesthetic in terms of code-quality :D

… if no bt-device is available during test_connection
@baranator baranator marked this pull request as ready for review January 6, 2023 22:44
@mr-manuel
Copy link
Collaborator

Is it already possible to insert the connection pin somewhere or is the default pin 1234 used?

@baranator
Copy link
Contributor Author

Is it already possible to insert the connection pin somewhere or is the default pin 1234 used?

to be honest: I'm not sure how bluetooth-auth ist handled these days and in BLE especially. I didn't specify a pin anywhere - so either no pin is needed at all or bleak guesses some default pins. Will try that out later.

@mr-manuel
Copy link
Collaborator

mr-manuel commented Feb 9, 2023

@Louisvdw could you please sync the changes from the master branch with the jkbms_ble branch or do you prefer that I open a pull request?

@testpaul999
Copy link

@Louisvdw
Have install this test version and get this issue with a new jk-bms version 11.x
E27A75AB-E689-4AC3-AE8A-3FBEFE0389EF

root@raspberrypi4:/data/etc/dbus-serialbattery# ./start-serialbattery.sh
UTC-2023.02.10-07:40:56 Starting dbus-serialbattery.py on
INFO:SerialBattery:Starting dbus-serialbattery
INFO:SerialBattery:dbus-serialbattery v0.14.3ble
INFO:SerialBattery:Testing Jkbms_Ble
ERROR:SerialBattery:init of jkbmsble
INFO:SerialBattery:test of jkbmsble
INFO:SerialBattery:Testing Jkbms_Ble
ERROR:SerialBattery:init of jkbmsble
INFO:SerialBattery:test of jkbmsble
INFO:SerialBattery:Testing Jkbms_Ble
ERROR:SerialBattery:init of jkbmsble
INFO:SerialBattery:test of jkbmsble
ERROR:SerialBattery:ERROR >>> No battery connection at /dev/
rm: '/var/lock/serial-starter' is a directory
root@raspberrypi4:/data/etc/dbus-serialbattery# ./start-serialbattery.sh
UTC-2023.02.10-07:41:33 Starting dbus-serialbattery.py on
INFO:SerialBattery:Starting dbus-serialbattery
INFO:SerialBattery:dbus-serialbattery v0.14.3ble
INFO:SerialBattery:Testing Jkbms_Ble
ERROR:SerialBattery:init of jkbmsble
INFO:SerialBattery:test of jkbmsble
connect and scrape on address: C8:47:8C:E9:33:C0
btloop

INFO:SerialBattery:Testing Jkbms_Ble
ERROR:SerialBattery:init of jkbmsble
INFO:SerialBattery:test of jkbmsble
connect and scrape on address: C8:47:8C:E9:33:C0
btloop
INFO:SerialBattery:Testing Jkbms_Ble
ERROR:SerialBattery:init of jkbmsble
INFO:SerialBattery:test of jkbmsble
ERROR:SerialBattery:ERROR >>> No battery connection at /dev/
Exiting bt-loop

Exiting bt-loop
rm: '/var/lock/serial-starter' is a directory
root@raspberrypi4:/data/etc/dbus-serialbattery#

The jibes will do beep beep but the connection will not appear.
Thx for help
Regards

@baranator
Copy link
Contributor Author

@Louisvdw Have install this test version and get this issue with a new jk-bms version 11.x E27A75AB-E689-4AC3-AE8A-3FBEFE0389EF

root@raspberrypi4:/data/etc/dbus-serialbattery# ./start-serialbattery.sh UTC-2023.02.10-07:40:56 Starting dbus-serialbattery.py on INFO:SerialBattery:Starting dbus-serialbattery INFO:SerialBattery:dbus-serialbattery v0.14.3ble INFO:SerialBattery:Testing Jkbms_Ble ERROR:SerialBattery:init of jkbmsble INFO:SerialBattery:test of jkbmsble INFO:SerialBattery:Testing Jkbms_Ble ERROR:SerialBattery:init of jkbmsble INFO:SerialBattery:test of jkbmsble INFO:SerialBattery:Testing Jkbms_Ble ERROR:SerialBattery:init of jkbmsble INFO:SerialBattery:test of jkbmsble ERROR:SerialBattery:ERROR >>> No battery connection at /dev/ rm: '/var/lock/serial-starter' is a directory root@raspberrypi4:/data/etc/dbus-serialbattery# ./start-serialbattery.sh UTC-2023.02.10-07:41:33 Starting dbus-serialbattery.py on INFO:SerialBattery:Starting dbus-serialbattery INFO:SerialBattery:dbus-serialbattery v0.14.3ble INFO:SerialBattery:Testing Jkbms_Ble ERROR:SerialBattery:init of jkbmsble INFO:SerialBattery:test of jkbmsble connect and scrape on address: C8:47:8C:E9:33:C0 btloop

INFO:SerialBattery:Testing Jkbms_Ble ERROR:SerialBattery:init of jkbmsble INFO:SerialBattery:test of jkbmsble connect and scrape on address: C8:47:8C:E9:33:C0 btloop INFO:SerialBattery:Testing Jkbms_Ble ERROR:SerialBattery:init of jkbmsble INFO:SerialBattery:test of jkbmsble ERROR:SerialBattery:ERROR >>> No battery connection at /dev/ Exiting bt-loop

Exiting bt-loop rm: '/var/lock/serial-starter' is a directory root@raspberrypi4:/data/etc/dbus-serialbattery#

The jibes will do beep beep but the connection will not appear. Thx for help Regards

Hm, maybe simply a weak/fragile bt-signal, that breaks after a few secs? looks strange that the bms is only found after several tries.

(dont get irritated by the error-msgs, they are only debug output and show no error at all.)

@testpaul999
Copy link

The RPI and the jk-bms are 1m from one each other…

@baranator
Copy link
Contributor Author

Wait... i noticed that you get no "JKBMS found" message and in your screenshot that the vendor-id of your JKBMS starts with JK_ whereas mine starts with JK- ...I'm checking this in https://github.com/baranator/dbus-serialbattery/blob/master/etc/dbus-serialbattery/jkbms_ble.py#L67 ....Try changing that prefix in the code and run again...

@testpaul999
Copy link

testpaul999 commented Feb 10, 2023

👍🏻🙂
After reboot and manual use start-serialbattery.sh it will connect.
But don't see any voltage or current at the screen.
image
Get this at the cli
INFO:SerialBattery:JK BMS found!
INFO:SerialBattery:Connection established to Jkbms_Ble
INFO:SerialBattery:Battery Jkbms BLE connected to dbus from zero
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 False | DCCM CV False
INFO:SerialBattery:> CCCM T False | DCCM T False
INFO:SerialBattery:> MIN_CELL_VOLTAGE 2.9V | MAX_CELL_VOLTAGE 3.5V
INFO:SerialBattery:DeviceInstance = 1
INFO:SerialBattery:com.victronenergy.battery.zero
INFO:SerialBattery:BAT: JKBMS 11.XW 8 cells
INFO:SerialBattery:DeviceInstance = 1
INFO:SerialBattery:Changed DeviceInstance = 1

At the cell detail page I see all cell voltages.

@baranator
Copy link
Contributor Author

👍🏻slightly_smiling_face After reboot and manual use start-serialbattery.sh it will connect. But don't see any voltage or current at the screen. image Get this at the cli INFO:SerialBattery:JK BMS found! INFO:SerialBattery:Connection established to Jkbms_Ble INFO:SerialBattery:Battery Jkbms BLE connected to dbus from zero 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 False | DCCM CV False INFO:SerialBattery:> CCCM T False | DCCM T False INFO:SerialBattery:> MIN_CELL_VOLTAGE 2.9V | MAX_CELL_VOLTAGE 3.5V INFO:SerialBattery:DeviceInstance = 1 INFO:SerialBattery:com.victronenergy.battery.zero INFO:SerialBattery:BAT: JKBMS 11.XW 8 cells INFO:SerialBattery:DeviceInstance = 1 INFO:SerialBattery:Changed DeviceInstance = 1

At the cell detail page I see all cell voltages.

are those cell voltages plausible? I assume your jkbms uses another protocol than mine. There are two different ones, for now i only implemented the one that uses 2 Byte per cell voltage - the other one uses 4 Byte and also the other values are somewhere else in the frame (see here jk02 and jk04: https://github.com/syssi/esphome-jk-bms/blob/fc6007433d3d69fdbc700c23af41a70ff8ed45db/components/jk_bms_ble/jk_bms_ble.cpp )

@testpaul999
Copy link

Sure the new version will transmit data for 32 cells and not for 24 cells who have the old one.
See this link it’s German https://www.akkudoktor.net/forum/open-source-software-projekte/jkbms-auslesen-ueber-ble-bluetooth-oder-rs485-adapter-mittels-eps-iobroker/paged/32/#post-87482
If you add 32 to your ble analysis it must run with the new on.
The most new jkbms will have the new fw 11.x
Hopefully this will help..

@baranator
Copy link
Contributor Author

Sure the new version will transmit data for 32 cells and not for 24 cells who have the old one. See this link it’s German https://www.akkudoktor.net/forum/open-source-software-projekte/jkbms-auslesen-ueber-ble-bluetooth-oder-rs485-adapter-mittels-eps-iobroker/paged/32/#post-87482 If you add 32 to your ble analysis it must run with the new on. The most new jkbms will have the new fw 11.x Hopefully this will help..

okay. you mean since fw 11 every jkbms uses the 4byte-format? has this been verified? In the bt-data i couldnt find a hint which format is used (that would have been the best approach). To make it run for both formats we would need a certain criterium or a whitelist/lookup-table....

@baranator
Copy link
Contributor Author

Sure the new version will transmit data for 32 cells and not for 24 cells who have the old one. See this link it’s German https://www.akkudoktor.net/forum/open-source-software-projekte/jkbms-auslesen-ueber-ble-bluetooth-oder-rs485-adapter-mittels-eps-iobroker/paged/32/#post-87482 If you add 32 to your ble analysis it must run with the new on. The most new jkbms will have the new fw 11.x Hopefully this will help..

okay. you mean since fw 11 every jkbms uses the 4byte-format? has this been verified? In the bt-data i couldnt find a hint which format is used (that would have been the best approach). To make it run for both formats we would need a certain criterium or a whitelist/lookup-table....

looked a bit more into this. Seems like they all use jk02, but the newer ones have the values after the cell-data shifted 32 Bytes: 16 Bytes for 8 more cell voltages a 2 Bytes and another 16 Bytes for 8 more cell resistances a 2 Bytes. Here an assumption about how to detect this is made https://github.com/syssi/esphome-jk-bms/blob/main/components/jk_bms_ble/jk_bms_ble.cpp#L445

@testpaul999
Copy link

Hmm, do you get the FW version at the connect string?
If yes let’s try figure it out for 11.x use the new format within the 32 cells 🤷🏻‍♂️

@baranator
Copy link
Contributor Author

https://github.com/baranator/jkbms_brntr/tree/f32s give it a try and see if this makes any difference

@testpaul999
Copy link

Have put this in file jkbms_brn.py.
Reboot and start-serialbattery.sh get this issue

root@raspberrypi4:~# cd /data/etc/dbus-serialbattery/
root@raspberrypi4:/data/etc/dbus-serialbattery# ./start-serialbattery.sh
UTC-2023.02.11-19:21:38 Starting dbus-serialbattery.py on
Traceback (most recent call last):
File "/opt/victronenergy/dbus-serialbattery/dbus-serialbattery.py", line 24, i n
from jkbms_ble import Jkbms_Ble
File "/opt/victronenergy/dbus-serialbattery/jkbms_ble.py", line 4, in
from jkbms_brn import JkBmsBle
File "/opt/victronenergy/dbus-serialbattery/jkbms_brn.py", line 148
self.translate(fb, translation, o[translation[0][i]], f32s=f32s, i + 1)
^
SyntaxError: positional argument follows keyword argument
rm: '/var/lock/serial-starter' is a directory
root@raspberrypi4:/data/etc/dbus-serialbattery#

@baranator
Copy link
Contributor Author

Have put this in file jkbms_brn.py. Reboot and start-serialbattery.sh get this issue

root@raspberrypi4:~# cd /data/etc/dbus-serialbattery/ root@raspberrypi4:/data/etc/dbus-serialbattery# ./start-serialbattery.sh UTC-2023.02.11-19:21:38 Starting dbus-serialbattery.py on Traceback (most recent call last): File "/opt/victronenergy/dbus-serialbattery/dbus-serialbattery.py", line 24, i n from jkbms_ble import Jkbms_Ble File "/opt/victronenergy/dbus-serialbattery/jkbms_ble.py", line 4, in from jkbms_brn import JkBmsBle File "/opt/victronenergy/dbus-serialbattery/jkbms_brn.py", line 148 self.translate(fb, translation, o[translation[0][i]], f32s=f32s, i + 1) ^ SyntaxError: positional argument follows keyword argument rm: '/var/lock/serial-starter' is a directory root@raspberrypi4:/data/etc/dbus-serialbattery#

oops. fixed that.

@testpaul999
Copy link

Have new issue 🤷🏻‍♂️

root@raspberrypi4:/data/etc/dbus-serialbattery# ./start-serialbattery.sh
UTC-2023.02.11-21:04:53 Starting dbus-serialbattery.py on
INFO:SerialBattery:Starting dbus-serialbattery
INFO:SerialBattery:dbus-serialbattery v0.14.3ble
INFO:SerialBattery:Testing Jkbms
ERROR:SerialBattery:[Errno 21] could not open port /dev/: [Errno 21] Is a directory: '/dev/'
INFO:SerialBattery:Testing Jkbms_Ble
ERROR:SerialBattery:init of jkbmsble
INFO:SerialBattery:test of jkbmsble
connect and scrape on address: c8:47:8c:e9:33:c0
btloop
reconnect

ERROR:root:A message handler raised an exception: name 'data' is not defined.
Traceback (most recent call last):
File "/usr/lib/python3.8/site-packages/dbus_fast/message_bus.py", line 811, in _process_message
result = user_handler(msg)
File "/usr/lib/python3.8/site-packages/bleak/backends/bluezdbus/manager.py", line 860, in _parse_msg
on_value_changed(message.path, self_interface["Value"])
File "/usr/lib/python3.8/site-packages/bleak/backends/bluezdbus/client.py", line 152, in on_value_changed
callback(bytearray(value))
File "/opt/victronenergy/dbus-serialbattery/jkbms_brn.py", line 251, in ncallback
self.assemble_frame(data)
File "/opt/victronenergy/dbus-serialbattery/jkbms_brn.py", line 246, in assemble_frame
self.decode()
File "/opt/victronenergy/dbus-serialbattery/jkbms_brn.py", line 206, in decode
self.decode_cellinfo_jk02()
File "/opt/victronenergy/dbus-serialbattery/jkbms_brn.py", line 177, in decode_cellinfo_jk02
has32s = (fb[189] == 0x00 and data[189 + 32] > 0)
NameError: name 'data' is not defined

@baranator
Copy link
Contributor Author

Have new issue 🤷🏻‍♂️

root@raspberrypi4:/data/etc/dbus-serialbattery# ./start-serialbattery.sh UTC-2023.02.11-21:04:53 Starting dbus-serialbattery.py on INFO:SerialBattery:Starting dbus-serialbattery INFO:SerialBattery:dbus-serialbattery v0.14.3ble INFO:SerialBattery:Testing Jkbms ERROR:SerialBattery:[Errno 21] could not open port /dev/: [Errno 21] Is a directory: '/dev/' INFO:SerialBattery:Testing Jkbms_Ble ERROR:SerialBattery:init of jkbmsble INFO:SerialBattery:test of jkbmsble connect and scrape on address: c8:47:8c:e9:33:c0 btloop reconnect

ERROR:root:A message handler raised an exception: name 'data' is not defined. Traceback (most recent call last): File "/usr/lib/python3.8/site-packages/dbus_fast/message_bus.py", line 811, in _process_message result = user_handler(msg) File "/usr/lib/python3.8/site-packages/bleak/backends/bluezdbus/manager.py", line 860, in _parse_msg on_value_changed(message.path, self_interface["Value"]) File "/usr/lib/python3.8/site-packages/bleak/backends/bluezdbus/client.py", line 152, in on_value_changed callback(bytearray(value)) File "/opt/victronenergy/dbus-serialbattery/jkbms_brn.py", line 251, in ncallback self.assemble_frame(data) File "/opt/victronenergy/dbus-serialbattery/jkbms_brn.py", line 246, in assemble_frame self.decode() File "/opt/victronenergy/dbus-serialbattery/jkbms_brn.py", line 206, in decode self.decode_cellinfo_jk02() File "/opt/victronenergy/dbus-serialbattery/jkbms_brn.py", line 177, in decode_cellinfo_jk02 has32s = (fb[189] == 0x00 and data[189 + 32] > 0) NameError: name 'data' is not defined

fixed that too....that's why i dont like python - no compiling, no compiling errors and when you run it, shit hits the fan...

@testpaul999
Copy link

image
You get it 🙂🎆

@Johnnylouw
Copy link

Hi Baranator
I'm I right that the consensus is to use a Bluetooth Dongle with this type of application. I haven't been able to connect to my JK with the RP internal bluetooth

@mr-manuel
Copy link
Collaborator

Hi @Johnnylouw, you don't have to use a Bluetooth Dongle. You can use the internal Bluetooth module.

  1. Have you replaced the MAC address in this line
    {"bms": "Jkbms_Ble", "address": "C8:47:8C:E4:54:0E"},
    with the MAC address of your JKBMS?
  2. Have you changed the default connection PIN of your JKBMS?

@Johnnylouw
Copy link

Hi @Johnnylouw, you don't have to use a Bluetooth Dongle. You can use the internal Bluetooth module.

  1. Have you replaced the MAC address in this line
    {"bms": "Jkbms_Ble", "address": "C8:47:8C:E4:54:0E"},

    with the MAC address of your JKBMS?
  2. Have you changed the default connection PIN of your JKBMS?

Thanks for the reply. I will double check my MAC address. What should the default pin be?

@mr-manuel
Copy link
Collaborator

mr-manuel commented Mar 8, 2023

The default PIN for the connection is 1234. If you changed your PIN you have to pair your JKBMS first with OS tools. See https://wiki.debian.org/BluetoothUser#Using_bluetoothctl for more details.

Since this script is using the Python bleak module it depends on it. They are alreay working to add pairing with PIN through the module: hbldh/bleak#1100

This informations were already added for a future release.

@Johnnylouw
Copy link

The default PIN for the connection is 1234. If you changed your PIN you have to pair your JKBMS first with OS tools. See https://wiki.debian.org/BluetoothUser#Using_bluetoothctl for more details.

Since this script is using the Python bleak module it depends on it. They are alreay working to add pairing with PIN through the module: hbldh/bleak#1100

This informations were already added for a future release.

Great, I will give it a go! Thank you for the assistance, much appreciated

@Johnnylouw
Copy link

Hi @Johnnylouw, you don't have to use a Bluetooth Dongle. You can use the internal Bluetooth module.

  1. Have you replaced the MAC address in this line
    {"bms": "Jkbms_Ble", "address": "C8:47:8C:E4:54:0E"},

    with the MAC address of your JKBMS?
  2. Have you changed the default connection PIN of your JKBMS?

Apologies for the stupid questions, how do I scan for the JK BMS Mac address?

@mr-manuel
Copy link
Collaborator

bluetoothctl help gives you all the commands.

bluetoothctl devices lists you all devices. If there are no devices execute bluetoothctl scan on

@Johnnylouw
Copy link

bluetoothctl help gives you all the commands.

bluetoothctl devices lists you all devices. If there are no devices execute bluetoothctl scan on

thanks got it.
I might have to start over.

Im getting this...
root@raspberrypi4:/data/etc/dbus-serialbattery# ./start-serialbattery.sh
UTC-2023.03.08-16:46:26 Starting dbus-serialbattery.py on
INFO:SerialBattery:Starting dbus-serialbattery
INFO:SerialBattery:dbus-serialbattery v0.14.3
INFO:SerialBattery:Testing LltJbd
ERROR:SerialBattery:[Errno 21] could not open port /dev/: [Errno 21] Is a directory: '/dev/'
INFO:SerialBattery:Testing Ant
ERROR:SerialBattery:[Errno 21] could not open port /dev/: [Errno 21] Is a directory: '/dev/'
ERROR:SerialBattery:>>> ERROR: Incorrect Data
INFO:SerialBattery:Testing Daly
ERROR:SerialBattery:[Errno 21] could not open port /dev/: [Errno 21] Is a directory: '/dev/'
ERROR:SerialBattery:[Errno 21] could not open port /dev/: [Errno 21] Is a directory: '/dev/'
ERROR:SerialBattery:[Errno 21] could not open port /dev/: [Errno 21] Is a directory: '/dev/'
INFO:SerialBattery:Testing Daly
ERROR:SerialBattery:[Errno 21] could not open port /dev/: [Errno 21] Is a directory: '/dev/'
ERROR:SerialBattery:[Errno 21] could not open port /dev/: [Errno 21] Is a directory: '/dev/'
ERROR:SerialBattery:[Errno 21] could not open port /dev/: [Errno 21] Is a directory: '/dev/'
INFO:SerialBattery:Testing Jkbms
ERROR:SerialBattery:[Errno 21] could not open port /dev/: [Errno 21] Is a directory: '/dev/'
INFO:SerialBattery:Testing Jkbms_Ble
Traceback (most recent call last):
File "/opt/victronenergy/dbus-serialbattery/dbus-serialbattery.py", line 110, in
main()
File "/opt/victronenergy/dbus-serialbattery/dbus-serialbattery.py", line 79, in main
battery = get_battery_type(port)
File "/opt/victronenergy/dbus-serialbattery/dbus-serialbattery.py", line 50, in get_battery_type
class_ = eval(test["bms"])
File "", line 1, in
NameError: name 'Jkbms_Ble' is not defined
rm: '/var/lock/serial-starter' is a directory
root@raspberrypi4:/data/etc/dbus-serialbattery#

@mr-manuel
Copy link
Collaborator

Did you run the installation? You can do this by executing bash /data/etc/dbus-serialbattery/installlocal.sh

@mr-manuel
Copy link
Collaborator

I opened a discussion #485

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.

8 participants