-
-
Notifications
You must be signed in to change notification settings - Fork 147
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
Conversation
…st is executed, further work required
…o that the bt-connection can be tested
Things seem to work already, if Meanwhile i found out, that you do not need to install the whole |
nvm... this was a file-permission problem; after |
two more notes:
|
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 (see: raspberrypi/linux#1552 and https://forum.fhem.de/index.php?topic=70179.0 ) I will test this with an external wifi-card. |
tried with an external wifi-dongle an an I had no success in resetting the internal bluetooth without a reboot. I tried un- and reloading kernel-modules |
got my bt-usb-dongle running by manually installing Lets see if this fixes the bt-stability problems.... |
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. |
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 ) |
i'll put this bluetooth issue as "works for now" aside for now. @Louisvdw :
|
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. 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 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. |
okay, sounds fine. will do that.
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
The bluetooth-service itself is running on venus os per default. From there on you simply can access it anytime via the |
… if no bt-device is available during test_connection
Is it already possible to insert the connection pin somewhere or is the default pin |
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. |
@Louisvdw root@raspberrypi4:/data/etc/dbus-serialbattery# ./start-serialbattery.sh INFO:SerialBattery:Testing Jkbms_Ble Exiting bt-loop The jibes will do beep beep but the connection will not appear. |
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.) |
The RPI and the jk-bms are 1m from one each other… |
Wait... i noticed that you get no "JKBMS found" message and in your screenshot that the vendor-id of your JKBMS starts with |
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 ) |
Sure the new version will transmit data for 32 cells and not for 24 cells who have the old one. |
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 |
Hmm, do you get the FW version at the connect string? |
https://github.com/baranator/jkbms_brntr/tree/f32s give it a try and see if this makes any difference |
Have put this in file jkbms_brn.py. root@raspberrypi4:~# cd /data/etc/dbus-serialbattery/ |
oops. fixed that. |
Have new issue 🤷🏻♂️ root@raspberrypi4:/data/etc/dbus-serialbattery# ./start-serialbattery.sh ERROR:root:A message handler raised an exception: 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... |
Hi Baranator |
Hi @Johnnylouw, you don't have to use a Bluetooth Dongle. You can use the internal Bluetooth module.
|
Thanks for the reply. I will double check my MAC address. What should the default pin be? |
The default PIN for the connection is Since this script is using the Python This informations were already added for a future release. |
Great, I will give it a go! Thank you for the assistance, much appreciated |
Apologies for the stupid questions, how do I scan for the JK BMS Mac address? |
|
thanks got it. Im getting this... |
Did you run the installation? You can do this by executing |
I opened a discussion #485 |
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:
later those actions should be automated and only the really necessary python modules installed.