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

Add bluetooth support #13

Closed
3 tasks
Louisvdw opened this issue Mar 15, 2021 · 13 comments
Closed
3 tasks

Add bluetooth support #13

Louisvdw opened this issue Mar 15, 2021 · 13 comments
Labels
enhancement New feature or request

Comments

@Louisvdw
Copy link
Owner

It would be good to have the driver use bluetooth to connect from the VenusOS device to the BMS
The latest rPi images has bluetooth enabled. A GX device will need a USB bluetooth dongle.

It will need to

  • Pair the device and the BMS
  • Send commands to connected bluetooth
  • Read values from connected bluetooth
@Louisvdw Louisvdw added the enhancement New feature or request label Sep 12, 2021
@TheEldar
Copy link

TheEldar commented Jun 6, 2022

Can help with Testing if needed. I have a Cerbo GX and 3 Renogy RBT200LFP12-BT.

@damonblumenstein
Copy link

I would love to see this come to fruition. I have 2 propane sensors on BT now and its awesome. This would make total sense!

@TheEldar
Copy link

did some tests with a Raspi and my Renogy RBT200LFP12-BT. Sorry it's not for the ANT BMS. But maybe it will also Help to implement the BT Support.

The Solar Monitor from Olen works and connects to the BT module of the Renogy. The scripts are meant for MQTT but maybe you can use the BT part and for integration in the GX devices?
Olen on GitHub

And an other Script on reddit
Link to Reddit Post

@Louisvdw Louisvdw mentioned this issue Sep 22, 2022
@baranator
Copy link
Contributor

baranator commented Nov 27, 2022

Last week i got the last parts for my victron battery system and tried to wire it up. the dbus-serialbattery wouldn't work. After some testing i came to the conclusion out that the serialport of my jk-b2a24s20p is broken as i couldn't get it running with any serial/dongle-combination other people describe as working - no signals on the directly attached oscilloscope either. Therefore i had to look for an alternative:

I spent my weekend on figuring out how to communicate with my jk-b2a24s20p via python-bleak via Bluetooth. Good news: I think i've already manages the hardest part and have all relevant readings (threshold & protection-voltages, per-cell-voltages and so on) in a python-dict.

In the next days i would have a closer look at your dbus-serialbattery implementation and how to fit this in. I would assume the easiest way would be to create another Battery-Subclass as a wrapper for the functions i wrote today in etc/dbus-serialbattery e.g. jkbms_ble.py, so that while running dbus-serialbattery simply wouldn't only poll all the currently implemented serial-connections, but would also try to build up a bluetooth-connection and poll data from there.

Is this a/the way to go? Anything else to consider?

@Louisvdw
Copy link
Owner Author

The protocol would be the same via normal wired serial communication and bluetooth. The setup of bluetooth and the address would be the big differences. But to make it easier you can just make a new battery type like you suggest and add that to the types to check. As long as your type has all the requered function calls it will be tested.
Make a draft Pull Request even though you have not finished it. That way we can see what you have done and give you feedback and we can merge when it is done.

@baranator
Copy link
Contributor

baranator commented Dec 2, 2022

Okay, i forked the repo, but for now i will concentrate on building a class that solely concentrates on retrieving the jkms-data via ble. I put that pre-alpha-test on github, see: https://github.com/baranator/jkbms_brntr

This is a single file, that should already be kind of runnable and print some values from the battery every few seconds; the library is going to create a background-thread, that handles all the incoming bluetooth-stuff and will provide a get_status() function that can be called any time to get the freshly updated values. Only very basic error-handling at the moment. I took many parts from https://github.com/syssi/esphome-jk-bms and translated the c-code to python. As i do not have that much experience with python i dont dare to guarantee for any kind of code-quality :D

@baranator
Copy link
Contributor

Did some first steps on my fork: https://github.com/baranator/dbus-serialbattery/commit/fe6b89cfb2a1623bd835d60f76b5bcd9102c684d

this isn't running just yet, just trying to figure out how to put things together...
to make it work you need to install the bleak python-package, what won't do fully automatic
to get it installed, run opkg install python3-pip and then bring it up to the newest version pip install --upgrade pip. if you then try to install bleak via pip install bleak you will get some weird errors, that i provisionally got rid of by installing all available python-modules :S via pip install python3-modules ... this should be reduced to the really needed packages later :)

(just wanted to give a sign of life)

@mr1978
Copy link

mr1978 commented Dec 14, 2022

Perhaps i can help by installing the required modules. The trick is you have to download the modules via wget, extract an install it manually.

Example:

cd /opt/victronenergy/inst
wget https://github.com/hbldh/bleak/archive/refs/heads/develop.zip
unzip develop.zip

By my testings I had the problem that some modules are missing:

cd /opt/victronenergy/inst
wget https://github.com/Bluetooth-Devices/dbus-fast/archive/refs/heads/main.zip
unzip main.zip.1

cd /opt/victronenergy/inst/dbus-fast-main/src
mv dbus_fast /opt/victronenergy/

cd /opt/victronenergy/inst
wget https://github.com/aio-libs/async-timeout/archive/refs/heads/master.zip
unzip master.zip

cd async-timeout-master
python3 setup.py install

cd /opt/victronenergy/inst
wget https://github.com/dreadnought/python-daly-bms/archive/refs/heads/main.zip

unzip main.zip
cd python-daly-bms-main/
python3 setup.py install

I hope this helps.

@idstein
Copy link
Contributor

idstein commented Dec 19, 2022

this isn't running just yet, just trying to figure out how to put things together... to make it work you need to install the bleak python-package, what won't do fully automatic to get it installed, run opkg install python3-pip and then bring it up to the newest version pip install --upgrade pip. if you then try to install bleak via pip install bleak you will get some weird errors, that i provisionally got rid of by installing all available python-modules :S via pip install python3-modules ... this should be reduced to the really needed packages later :)

(just wanted to give a sign of life)

Thanks for those valuable instructions. For me the following worked to get custom python packages on board:
opkg update opkg install python3-pip python3-modules

For the concrete serial rfcomm with a BLE GATT device, I use ble_serial:

pip3 install ble_serial

For JBD BMS the following service, rx and tx UUIDs work to construct a local serial socket forwarding:
ble_serial -p /tmp/ttyBLE1 -s 0000ff00-0000-1000-8000-00805f9b34fb -r 0000ff01-0000-1000-8000-00805f9b34fb -w 0000ff02-0000-1000-8000-00805f9b34fb

Sample output running on a RPi4 Venus OS:
root@raspberrypi4:~# ble-serial -s "0000ff00-0000-1000-8000-00805f9b34fb" 21:20:30.075 | INFO | linux_pty.py: Port endpoint created on /tmp/ttyBLE -> /dev/pts/2 21:20:30.076 | INFO | ble_interface.py: Receiver set up 21:20:30.077 | WARNING | ble_interface.py: Picking first device with matching service, consider passing a specific device address, especially if there could be multiple devices /usr/lib/python3.8/site-packages/ble_serial/bluetooth/ble_interface.py:28: FutureWarning: This method will be removed future version, pass the callback to the BleakClient constructor instead. self.dev.set_disconnected_callback(self.handle_disconnect) 21:20:31.233 | INFO | ble_interface.py: Trying to connect with 70:3E:97:D2:F4:D0: JBD-AP21S002 21:20:32.163 | INFO | ble_interface.py: Device 70:3E:97:D2:F4:D0 connected 21:20:32.165 | INFO | ble_interface.py: Found write characteristic 0000ff02-0000-1000-8000-00805f9b34fb (H. 20) 21:20:32.167 | INFO | ble_interface.py: Found notify characteristic 0000ff01-0000-1000-8000-00805f9b34fb (H. 16) 21:20:32.225 | INFO | main.py: Running main loop! ^C21:29:59.848 | WARNING | main.py: Shutdown initiated 21:29:59.849 | INFO | linux_pty.py: Serial reader and symlink removed 21:30:02.017 | WARNING | ble_interface.py: Device 70:3E:97:D2:F4:D0 disconnected 21:30:02.018 | INFO | ble_interface.py: Stopping Bluetooth event loop 21:30:02.020 | INFO | ble_interface.py: Bluetooth disconnected 21:30:02.021 | INFO | main.py: Shutdown complete.

This will construct a local tty file endpoint backed by BLE GATT device with a RX/TX characteristics using write / notify. Unfortunately, I haven't found a way to inform serial-starter about this new pseudo terminal device. But reading this here it does not sound like an easy route https://unix.stackexchange.com/questions/240352/control-pseudo-terminal-dev-pts-assignments.

Any interesting on the Python code can take a look at the attached patch file. The patch assumes tty path is provided with a query, e.g. /tmp/ttyBLE?ble=[address]. Minimal sample also works with just calling with tty path /tmp/ttyBLE?ble=
jbd_ble.patch

@baranator
Copy link
Contributor

slowly getting somewhere :)

https://bilderupload.org/bild/7e0a90548-jkbms

@baranator
Copy link
Contributor

created a pull-request draff, so further progress will be handled there: #372

@mr-manuel
Copy link
Collaborator

See this discussion for the big progress: #485

The Bluetooth connection for the JKBMS is now working fine since 4 months and the cornerstone for adding other Bluetooth drivers was placed.

mr-manuel pushed a commit that referenced this issue May 31, 2023
Louisvdw pushed a commit that referenced this issue May 31, 2023
* Changes 2023.05.18 (#649)

* Added: Show specific TimeToSoC points in GUI
Only if 0%, 10%, 20%, 80%, 90% and/or 100% are selected

* Added: Show specific TimeToSoC points in GUI
Only if 0%, 10%, 20%, 80%, 90% and/or 100% are selected

* fix black lint error

* fix black lint error

* Improved JBD BMS soc calculation
#439

* Fix for #397
#484

* small fixes

* sort bms imports

* Add support for HLPdata BMS4S
#505

* Add support for Seplos BMS
#530

* change flake8 settings

* fix black lint errors

* removed wildcard imports

* fixed black lint errors

* change flake8 settings

* remove wildcard import and fix black lint errors

* removed wildcard import

* fixed black lint check

* removed wildcard import, fixed black lint errors

* config changes

* removed wildcard import, fixed black lint errors

* remove old log message in handle_changed_setting()

* remove old log message in handle_changed_setting()

* simplified condition for Time-To-Go/Soc

* simplified condition for Time-To-Go/Soc

* fix renogy import

* fix renogy import

* added BMS info and cleanup
* MNB
* Revov
* Sinowealth

* added BMS info and cleanup
* MNB
* Revov
* Sinowealth

* moved BMS to subfolder

* moved BMS to subfolder

* moved BMS to subfolder

* corrected installble to run correct script

* Added self.unique_identifier to the battery class
Used to identify a BMS when multiple BMS are connected
planned for future use

* Added self.unique_identifier to the battery class
Used to identify a BMS when multiple BMS are connected
planned for future use

* changed ble service name
from `dbus-blebattery-$1` to `dbus-blebattery.$1` like the non ble service

* fix small errors

* read installed capacity at startup

* disable ANT BMS by default
#479

* fix cell voltage header parser

* rework daly receive routine

* improve read cell voltages - only work on sufficient data, drop only the bad package on checksum error, not the complete transmission

* allow read_soc to also retry serial transmission

* add daly cell balance state info. cells are red only if unbalanced now

* bump version

* typo

* moved read_serialport_data() to daly.py

* revert read_serialport_data() to the state before my changes

* fix connection log startup message.
now voltage/current/soc are displayed correctly

* black reformatting

* added linear voltage recalculation interval
In the config file can now be defined how often CVL, CCL and DCL is recalculated

* revert Daly adaption

* replaced penalty voltage calculation
with automatically calculated penalty voltages to simplify config
max voltage is kept until batteries are balanced

* flake config change

* flake config change

* added linear voltage recalculation interval
In the config file can now be defined how often CVL, CCL and DCL is recalculated

* replaced penalty voltage calculation
with automatically calculated penalty voltages to simplify config
max voltage is kept until batteries are balanced

* fix black lint errors

* updated changelog

* disabled ANT BMS by default
#479

* updated config.default.ini

* fix typo

* update nightly install script

* Removed line

* fixed error in HLPdataBMS4S

* fixed wrong variable assignment
`str` instead of `int`

* fixed wrong variable assignment
`str` instead of `int`

* updated battery template

* updated battery template

* Fix for #450
#450

* Read charge/discharge limit JKBMS
#4

* updated battery template

* Progress with config limits reason

* updated CELL_VOLTAGE_DIFF_TO_RESET_VOLTAGE_LIMIT default value

* added SoC round for LLT/JBD

* fixed log typo

* updated nightly script

* Fix for #450
#450

* Read charge/discharge limit JKBMS
#4

* reworked installation procedure
Bluetooth BMS is now also fetched from config.ini

* updated release workflow

* updated readme

* Merge branch 'master' into jkbms_ble

* deploy to github pages only
on changes in master or docusaurus branch

* cleanup

* Merge branch 'master' of into jkbms_ble

* GitHub pages config change

* GitHub pages config change

* cleanup

* Renamed scripts for better reading #532

* update docusaurus dependencies

* Renamed scripts for better reading #532

* update docusaurus dependencies

* change sh with bash

* limitation reason cleanup

* limitation reason cleanup

* changed default config settings
FLOAT_CELL_VOLTAGE from 3.350V to 3.375V
LINEAR_LIMITATION_ENABLE from False to True

* changed default config settings
FLOAT_CELL_VOLTAGE from 3.350V to 3.375V
LINEAR_LIMITATION_ENABLE from False to True

* removed testing line

* Cleanup duplicated files

Files were moved and not deleted

* Cleanup

* MOSFET temperature was displayed twice after merge

* small typo fixes

* updated changelog

* updated changelog

* Small fixes

* fix disconnection behaviour: on disconnect, show '---' after 10s and 'not connected' after 60s

* fix flake errors

* small fix

* fix disconnection behaviour & small fixes
* on disconnect, show '---' after 10s and 'not connected' after 60s by @transistorgit
* small fixes in shell script
* added restart driver script

* fixed file permission

* Added: apply max voltage if CVCM_ENABLE is False
before float voltage was applied

* fixed type error

* Added: BMS disconnect behaviour
* Choose to block charge/discharge on disconnect
* Trigger Venus OS alarm

* Changed: Remove wildcard import from dbushelper.py

* small fixes

* Added: apply max voltage if CVCM_ENABLE is False
before float voltage was applied

* Added: BMS disconnect behaviour
* Choose to block charge/discharge on disconnect
* Trigger Venus OS alarm

* Changed: Remove wildcard import from dbushelper.py

* flake8 changes

* copied lltjbd_ble from idstein:jdb_ble

* Added and adapted LltJbd_Ble
ATTENTION: Currently it's untested

* small changes

* read production date and append to hardware version

* Set SOC nightly. Button is working, next is send command to bms

* Added: Show additional data in device page
* show self.unique_identifier as serial number
* show self.production as device name

* Added: JKBMS unique identifier & fixed data length

* Added: JKBMS BLE unique identifier

* Added: Jkbms_Ble connection_name()

* Added: Daly unique identifier

* Added: JKBMS BLE serial number, user defined field

* Added: Show additional data in device page
* show self.unique_identifier as serial number
* show self.production as device name

* Added: JKBMS unique identifier & fixed data length

* move config.ini before update

* read production date by @tranistorgit
this adds the battery production date

* read out daly battery code and use as unique id

* moved production date and added custom field

* clean battery code
strip whitespace and replace one or multiple spaces with one underline
if no battery code generate unique field

* Daly read_capacity change
Read capacity from config file, if no value provided by BMS

* Daly try to fix no reply

* Improvements by @transistorgit

* changed value

* set SOC (and date time) on button press.

* fix battery code parser

* format fix

* format fix

* fix extra long serial timeouts
by calculating max time instead of loop counts

* Changed: Merged all install files into one

* updated install docs for nightly build

* Small fixes

* changed config backup

* updated config file

* updated changelog

* debug daly

* changed release workflow

* changed release workflow

* changed release workflow

* changed release workflow

* Updated from master

* fix blank screen, debug daly

* make Reset SoC a spin box

* fix possible read_capacity problem

* Daly read_balance_state() add missing return

* Daly advanced troubleshooting

* Changed: Improved Daily stability by a lot

* fixes for disable and uninstall
service was not removed and if removed, it was recreated by the serial starter

* optimized USB install method

* updated changelog

* added missing qml to restore-gui.sh

* optimized USB install method

* Daly improvements
* Set SoC on button press by @transistorgit
* Improved driver stability by @transistorgit & @mr-manuel

* moved production date and added custom field

* changed jkbms_ble to dev

* changed order

* final daly 'broken packages handling'

* Last changes for daly read problem
by @transistorgit

* change version in utils based on GitHub tag

* test automatic release version change

* Added: Configure voltage drop

* test automatic release version change

* fix Daly alarms

* fixes small errors in bash files

* fix missing driver name in restart-driver.sh

* linear mode, allow max voltage on soc thesshold

* Daly added one retry if failed

* fixed LLT/JBD cell balancing display

* rename tar after USB install
fixes #638

* add force buttons

* force buttons working

* fixed removing entries

* implement force charge/discharge

* little bit cleaner soc preset

* use existing serial read/write function

* add stop balancong switch

* use existing serial read/write function

* Changed: Get bg colors from MbStyle for dark mode

* prevent short circuit evaluation

* fix merge errors

* added changelog info

* Fix #648

---------

Co-authored-by: Bernd Stahlbock <[email protected]>

* Limit control voltage to max cell voltage

* Rework serial parser (#12)

much cleaner code, as it is optimised for the daly protocol

* updated changelog

* fix black lint error

* fixed black lint error

* added infos to battery template

* JDB BLE support (#499)

* Implementing JBD BLE support. It is built upon Bleak
* Additionally, it provides some handling of for up to 4 temperature probes labels T1 (NTC2), T2 (NTC3), T3 (NTC4) and T4 (NTC5). NTC1 is the BMS module temperature itself
* The device page has been extend to provide more details about the actual used hardware (= product name), firmware version and BLE address

* updated changelog

* Add Supoprt for HeltecSmartBMS (YYBMS) using modbus via RS485 connection (#658)

* Changes 2023.05.24 (#667)

* Check Venus OS version before installing

* fix Jkbms_Ble error

* updated changelog

* updated readme and added donation link

* bugfix: Heltec BMS test_connection breaks on other modbus compliant BMS systems

* bugfix: LLTJBD BMS ignore non ASCII letters for hardware version

* updated readme

* Suppress daly read errors (#13)

* updated descriptions

* Changed logging level and give better feedback
* Changed logging level to debug for unneeded messages
* Give the user feedback, if a BMS is found or not. Useful, if only one BMS is tested.

* small fixes

---------

Co-authored-by: Bernd Stahlbock <[email protected]>
Co-authored-by: Oleg Gurevich <[email protected]>
Co-authored-by: Bernd <[email protected]>
Co-authored-by: Paul Strawder <[email protected]>
Co-authored-by: Raphael Mack <[email protected]>
Co-authored-by: Strawder, Paul <[email protected]>
@mr-manuel
Copy link
Collaborator

Was implemented for most used BMS by community. Further PR for more BMS are very welcome.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

7 participants