JDB / XiaoXiang BMS tool

Announcement - Help us fight the BOTS! Please report all spam including stuff in your inbox!

graham

Member
Joined
Jan 5, 2018
Messages
40
If compiled with MQTT support (needs paho mqqt library), jbdtool outputs mqtt data. You can specify the info on the comand line with the -m option, for example:


Code:
jbdtool -m host:clientid:topic[:user[ass]]

jbdtool -t ip:pack_01 -m localhost:pack_01:/Battery/pack_01

(pack_01 is the dns name of my wifi module #1)

In another window, I can subscribe to /Battery/# to see the JSON output:

# mosquitto_sub -h localhost -t '/Battery/#'
{"Voltage":53.330001831054688,"Current":0,"DesignCapacity":100,"RemainingCapacity":64.339996337890625,"PercentCapacity":64,"CycleCount":0,"Probes":2,"Temps":[17,15.300000000000001],"Strings":14,"Cells":[3.79,3.7850000000000001,3.7919999999999998,3.7909999999999999,3.819,3.8290000000000002,3.831,3.8300000000000001,3.8250000000000002,3.8130000000000002,3.8239999999999998,3.8039999999999998,3.794,3.7999999999999998],"CellTotal":53.326999664306641,"CellMin":3.7850000858306885,"CellMax":3.8310000896453857,"CellDiff":0.046000003814697266,"CellAvg":3.8090713024139404,"DeviceName":"15350019-SP15S008C-P14S-100A","ManufactureDate":"20210116","Version":2.5,"FET":"Charge,Discharge"}


I have a node-red server running on the same host which injects the info into an influx DB. It should look something like this:

View attachment 23789

Reads from /Battery topic, converts JSON to javascript obect, then flattens the Cells array into cell01,02,03,04 as seperate fields, does the same for temps, then removes arrays for the remainder of the data.

From there, its easy to make a dash for it in Grafana. Something like this maybe (could use some work):

View attachment 23790

After that you could get fancy and maybe do some linking if you have multiple packs so you can click on each pack to get the info


NOTE: I just updated the github repo ... it wasnt setting the name field in the JSON output with the mqtt clientid.

EDIT: no way to remove those stupid emojis ... they are colon p
Wow thats something to work towards,

I have alot of questions but i will try an keep it short,

I am currently running the static version for pi that you put together, do i need to switch to the github repo?
 

chuckp

Member
Joined
Jul 29, 2018
Messages
404
This looks great I have a couple of Pi’s kicking around that the Mrs got me as part of my Christmas present.
Have you managed to get the batt off and on buttons and the config page to work remotely also.
Would be great to also be able to access the BMS remotely when away from home.

My nephew who in my eyes is a programming wizard is building a custom system for me at the moment that will integrate all my equipment into one interactive user dashboard. I’ll have access to data from my micro inverters, (wind turbine inverter once I’ve installed it) battery charger inverter and my BMS. He is also looking at linking my BMS to the coms on my charge controller (SOFAR ME300SP). Then I can use the proper default Lithium charge settings rather than the custom settings I’m using at the moment.

In the meantime though this looks to be a great option.
 
Last edited:

sshoecraft

Member
Joined
Jan 23, 2021
Messages
47
This looks great I have a couple of Pi’s kicking around that the Mrs got me as part of my Christmas present.
Have you managed to get the batt off and on buttons and the config page to work remotely also.
Would be great to also be able to access the BMS remotely when away from home.

My nephew who in my eyes is a programming wizard is building a custom system for me at the moment that will integrate all my equipment into one interactive user dashboard. I’ll have access to data from my micro inverters, (wind turbine inverter once I’ve installed it) battery charger inverter and my BMS. He is also looking at linking my BMS to the coms on my charge controller (SOFAR ME300SP). Then I can use the proper default Lithium charge settings rather than the custom settings I’m using at the moment.

In the meantime though this looks to be a great option.

Yes, you can turn charging and discharging off/on by using the -g (charging) and -G (discharging) options

All of the config parameters can be set. Use the -l (ell) option to list them. Use the -r option to read specific ones, or -r -a to list them all. Then, if you want to set a parameter, use the -w option with key/value pairs. For instance, to set the Balance start voltage to 3800 and the Balance window to 15mv, you would use this command:

jbdtool -t <transport opts> -w BalanceStartVoltage 3800 BalanceWindow 15

The only thing I didnt implement was the voltage/current calibration and balance control modes (odd/even/etc).

Since I have so many packs, I set all my BMSs to the same values by using a JSON file like so:

jbdtool -t <transport opts> -w -f jbd_settings.json


You can capture the current settings into a JSON file using the -r and -a options with -o (output):

jbdtool -t <transport opts> -r -a -n -J -o my_settings.json


Your transport opts are going to specific to your BMS, (like bt:01:02:03:04:05:06 or serial:/dev/ttyS0)

Also, I tried the read the settings command into a json file and realized it was sending the batteryconfig and ntc output to stdout (instead of redirecting to a file if it was asked to). I attached an updated copy here, but your copy should work fine with the commands above.
 

Attachments

  • jbdtool_pi_static.zip
    1.3 MB · Views: 107

graham

Member
Joined
Jan 5, 2018
Messages
40
@sshoecraft thank for all your help,

So Far
I have connected to the BMS using Jbdtool through serial port.

$ jbdtool -t serial:/dev/ttyUSB0,9600 Battery

gives me a full read out of BMS,, all good

Mqtt

I have read a couple of tutorials and followed these instructions

$ sudo nano /etc/mosquitto/mosquitto.conf

replaced the last line. $ include_dir /etc/mosquitto/conf.d

with $ listener 1883

exit/saved/ rebooted.

Now i can subscribe and publish using

$ mosquitto_sub -d -t Test
$ mosquitto_pub -d -t Test -m "Hello' World!"

But when i try this,

$ jbdtool -t serial:/dev/ttyUSB0,9600 -m localhost:Test:/Battery/

nothing,,, I guess im not addressing the jbdtool correctly, or i have set up Mosquitto incorrectly?

any advice would be gratefully recieved.

Thank you
 

chuckp

Member
Joined
Jul 29, 2018
Messages
404
Thanks

As soon as I have some free time I’ll dig out the Pi’s and set it up.
 

bwolten

New member
Joined
Sep 13, 2020
Messages
8
I used the current download from your github page... I see the others are PI, I do have a PI so maybe I will try on the PI
In the JBD directory where I have the JBDTools and MYBMM: I am using ubuntu 20.4, at the command line i type: sudo make throws the below error
Not sure if I did something wrong which likely the case.. I see in the JBDtools folder the gattlib.h file..
Any thoughts???

../mybmm/bt.c:18:10: fatal error: gattlib.h: No such file or directory
18 | #include "gattlib.h"
| ^~~~~~~~~~~
compilation terminated.
 

sshoecraft

Member
Joined
Jan 23, 2021
Messages
47
Y
I used the current download from your github page... I see the others are PI, I do have a PI so maybe I will try on the PI
In the JBD directory where I have the JBDTools and MYBMM: I am using ubuntu 20.4, at the command line i type: sudo make throws the below error
Not sure if I did something wrong which likely the case.. I see in the JBDtools folder the gattlib.h file..
Any thoughts???

../mybmm/bt.c:18:10: fatal error: gattlib.h: No such file or directory
18 | #include "gattlib.h"
| ^~~~~~~~~~~
compilation terminated.

If you're not using a PI you'll need to compile and install gattlib from github: https://github.com/labapart/gattlib
 

sshoecraft

Member
Joined
Jan 23, 2021
Messages
47
@sshoecraft thank for all your help,

So Far
I have connected to the BMS using Jbdtool through serial port.

$ jbdtool -t serial:/dev/ttyUSB0,9600 Battery

gives me a full read out of BMS,, all good

Mqtt

I have read a couple of tutorials and followed these instructions

$ sudo nano /etc/mosquitto/mosquitto.conf

replaced the last line. $ include_dir /etc/mosquitto/conf.d

with $ listener 1883

exit/saved/ rebooted.

Now i can subscribe and publish using

$ mosquitto_sub -d -t Test
$ mosquitto_pub -d -t Test -m "Hello' World!"

But when i try this,

$ jbdtool -t serial:/dev/ttyUSB0,9600 -m localhost:Test:/Battery/

nothing,,, I guess im not addressing the jbdtool correctly, or i have set up Mosquitto incorrectly?

any advice would be gratefully recieved.

Thank you

You might try subscribing to any topic on your mosquitto server and see if you see anything

mosquitto_sub -h localhost -t '#' -v

and then turn on debugging in jbdtool with the -d # option

jbdtool -t serial:/dev/ttyUSB0,9600 -m localhost:Test:/Battery/ -d 2

(each increase of the debugging level increases the verbosity, 5 or 7 will show you the packet data sent back/forth to the bms, 9 is pretty much everything)
 

SailCS33

New member
Joined
Mar 2, 2021
Messages
1
Hi everyone. I got to this forum and this thread via Google as I was trying to find a way to pull stats from Daly Smart BMS.
It looks like jbdtool is exactly what I need but having some issues building it. Eventually I will move this project to Pi4 but at this time I am using my laptop running Ubuntu 20x.

Followed instructions on github. Cloned mybmm and tried to do initial 'make'

First issue was actually with mybmm. mqtt.h was looking for a file it didnt even have.
../mybmm/mqtt.h:6:10: fatal error: MQTTClient.h: No such file or directory
Luckily, jbdtool clone had this file and I simply copied it over to the mybmm directory.

Next issue was that MQTTClient.h now looking for a file it didnt have.
../mybmm/MQTTClient.h:121:10: fatal error: MQTTProperties.h: No such file or directory
I didnt have MQTTProperties file anywhere. So I installed "MQTT-Client-Framework" which provided MQTTProperties.h.

The next issue unfortunately I cannot overcome because I cannot find the missing file anywhere.
../mybmm/MQTTProperties.h:9:9: fatal error: Foundation/Foundation.h: No such file or directory

I also installed mosquitto.

Package: mosquitto
Version: 1.6.12-1
Priority: optional
Section: universe/net
Origin: Ubuntu
Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
Original-Maintainer: Roger A. Light <roger@atchoo.org>
Bugs: https://bugs.launchpad.net/ubuntu/+filebug
Installed-Size: 496 kB
Depends: adduser (>= 3.10), libuuid1, lsb-base (>= 4.1+Debian3), libc6 (>= 2.29), libdlt2 (>= 2.18.5), libssl1.1 (>= 1.1.0), libsystemd0, libwebsockets16 (>= 1.6.0), libwrap0 (>= 7.6-4~)
Suggests: apparmor
Homepage: https://mosquitto.org/
Download-Size: 161 kB
APT-Manual-Installed: yes
APT-Sources: http://us.archive.ubuntu.com/ubuntu groovy/universe amd64 Packages
Description: MQTT version 5.0/3.1.1/3.1 compatible message broker


Would much appreciate any assistance.

Thanks

Val
 
Last edited:

sshoecraft

Member
Joined
Jan 23, 2021
Messages
47
Val, I apologize for not creating a proper README for mybmm. In truth, I've forked the project over and taking a new direction: instead of all drivers built into the binary, they will all send MQTT messages to a master controller. It's still a work in progress. In the meantime, I'll go ahead and update jbdtool so that it does not require any other [of my] projects to build.

If you want MQTT support, you'll need the paho mqtt library


mybmm should not require it unless MQTT=yes is enabled in the Makefile. Set MQTT=no and it should build w/o it.


That's not the real problem here, though. jbdtool is only for the JBD BMS, and probably wont work with others as the protocol differs.



Now if someone would send me a 14s 100A li-on ANT BMS with UART option, I would send them the same JBD BMS with a WI-FI module included.
I could then write a utility for ANT (provided I can find the ANT protocol).
 
Last edited:

sshoecraft

Member
Joined
Jan 23, 2021
Messages
47
I was able to cross compile my jbtool binary from linux to windows. It only works for ip (wifi) or serial on windows (no BT support yet), but it does have MQTT support.
Code:
C:\>jbdtool -t ip:10.10.10.10
Voltage                   54.320
Current                   0.000
DesignCapacity            75.000
RemainingCapacity         74.640
PercentCapacity           100
CycleCount                0
Probes                    2
Temps                     22.7,21.3
Strings                   14
Cells                     3.887,3.888,3.886,3.885,3.874,3.879,3.878,3.878,3.880,3.878,3.879,3.880,3.870,3.879
CellTotal                 54.321
CellMin                   3.870
CellMax                   3.888
CellDiff                  0.018
CellAvg                   3.880
DeviceName                15350021-SP15S008C-P14S-100A
ManufactureDate           20201022
Version                   2.5
FET                       Charge,Discharge

For serial
C:\>jbdtool -t serial:COM6
...

To send MQTT data (ip or serial):
C:\>jbdtool -t serial:COM6 -m 10.10.10.1:pack_01:/Powerwall/pack_01

Keep in mind I *just* compiled this ~30m ago so I haven't been able to test fully, but if you dont have linux it might work for you
 

Attachments

  • jbdtool_win.zip
    339.6 KB · Views: 106

sshoecraft

Member
Joined
Jan 23, 2021
Messages
47
This looks great I have a couple of Pi’s kicking around that the Mrs got me as part of my Christmas present.
Have you managed to get the batt off and on buttons and the config page to work remotely also.
Would be great to also be able to access the BMS remotely when away from home.

My nephew who in my eyes is a programming wizard is building a custom system for me at the moment that will integrate all my equipment into one interactive user dashboard. I’ll have access to data from my micro inverters, (wind turbine inverter once I’ve installed it) battery charger inverter and my BMS. He is also looking at linking my BMS to the coms on my charge controller (SOFAR ME300SP). Then I can use the proper default Lithium charge settings rather than the custom settings I’m using at the moment.

In the meantime though this looks to be a great option.

Chuck, has your nephew published this system in github, etc? I'd like to take a look at it as I'm doing something similar ATM (I have SMA Sunny Islands).
 

AndrewL

New member
Joined
Mar 27, 2021
Messages
3
@sshoecraft

Like @chuckp I am also using the JBD BMS with a Sofar ME3000SP.

My plan is for two RPi, one interfacing the ME3000SP (RS-485&CanBus), 4 x JBD BMS and a Victron MPPT charger. The second RPi is the brains of my home automation system. I currently use Domoticz. The two RPis communicate via MQTT.

I have been running your great JBDTool for about a week. There are occasional packet dumps on the terminal sessions that run the app - I am still in development mode, so everything is hand started.

This morning one the process stopped reporting any data, here is the output from debug level 3:

./jbdtool -a -t serial:/dev/ttyUSB1,9600 -d 3
main(786): transport: 0x7eb3053c, target: 0x7eb30543
main(811): transport: serial
mybmm_load_module(58): NOT found.
mybmm_load_module(111): init: 0x26898
mybmm_load_module(118): adding module: serial
mybmm_load_module(52): mp->name: serial, mp->type: 2
mybmm_load_module(58): NOT found.
mybmm_load_module(111): init: 0x1884c
mybmm_load_module(118): adding module: jbd
jbd_new(411): transport: serial
jbd_new(420): pp->target: /dev/ttyUSB1, pp->opts: 9600
serial_new(33): target: /dev/ttyUSB1
serial_new(46): baud: 9600, stop: 8, parity: 1
main(827): charge: -1, discharge: -1
main(851): mqtt: (nil)
main(894): outfp: 0x31b8e0
jbd_get_info(261): transport: serial
serial_write(203): writing...
serial_write(205): bytes: 7
serial_read(157): buf: 0x7eb2f82c, buflen: 256
serial_read(184): debug: 3
serial_read(186): returning: 34
jbd_verify(47): len: 34
jbd_verify(73): CRC ERROR: my_crc: faaf, pkt_crc: faac
data(34):
0000: DD 03 00 1B 14 88 FE 38 13 9C 1F 40 00 0A 28 D4 .......8...@..(.
0010: 00 00 00 00 00 00 19 3F 03 0E 02 0B 6D 0B 62 FA .......?....m.b.
0020: AC 77 .w
serial_write(203): writing...
serial_write(205): bytes: 7
serial_read(157): buf: 0x7eb2f82c, buflen: 256
serial_read(184): debug: 3
serial_read(186): returning: 34
jbd_verify(47): len: 34
jbd_verify(73): CRC ERROR: my_crc: fab6, pkt_crc: fab3
data(34):
0000: DD 03 00 1B 14 89 FE 30 13 9C 1F 40 00 0A 28 D4 .......0...@..(.
0010: 00 00 00 00 00 00 19 3F 03 0E 02 0B 6D 0B 62 FA .......?....m.b.
0020: B3 77 .w
serial_write(203): writing...
serial_write(205): bytes: 7
serial_read(157): buf: 0x7eb2f82c, buflen: 256
serial_read(184): debug: 3
serial_read(186): returning: 34
jbd_verify(47): len: 34
jbd_verify(73): CRC ERROR: my_crc: fab6, pkt_crc: fab3
data(34):
0000: DD 03 00 1B 14 89 FE 30 13 9C 1F 40 00 0A 28 D4 .......0...@..(.
0010: 00 00 00 00 00 00 19 3F 03 0E 02 0B 6D 0B 62 FA .......?....m.b.

Have you seen similar intermittent CRC errors? What is the meaning of "parity: 1", my notes on the BMS protocol state the parity should be none.

I tried the BT version but this generates, a BT notification error:

./jbdtool -t bt:A4:C1:38:0B:82:6F -a -d 3
main(786): transport: 0x7e9b67bb, target: 0x7e9b67be
main(811): transport: bt
mybmm_load_module(58): NOT found.
mybmm_load_module(111): init: 0x27dc8
mybmm_load_module(118): adding module: bt
mybmm_load_module(52): mp->name: bt, mp->type: 2
mybmm_load_module(58): NOT found.
mybmm_load_module(111): init: 0x1884c
mybmm_load_module(118): adding module: jbd
jbd_new(411): transport: bt
jbd_new(420): pp->target: A4:C1:38:0B:82:6F, pp->opts:
main(827): charge: -1, discharge: -1
main(851): mqtt: (nil)
main(894): outfp: 0x859908
bt_open(85): connecting to: A4:C1:38:0B:82:6F
bt_open(91): s->c: 0x859b18
bt_open(97): error: failed to start bluetooth notification.

I am using the RPi version you posted above.

Andrew
 

sshoecraft

Member
Joined
Jan 23, 2021
Messages
47
If it was working fine then suddenly not I would check your serial connections. Even the smallest bit of resistance may cause an issue with serial.

I looked at the code and it's reporting the serial attribs incorrectly

serial_new(46): baud: 9600, stop: 8, parity: 1

SHOULD read: 9600, data: 8, stop: 1, parity: none

// 8 bits, no parity, one stop bit
options.c_cflag &= ~PARENB;
options.c_cflag &= ~CSTOPB;
options.c_cflag &= ~CSIZE;
options.c_cflag |= CS8;

if you're getting more JBD BMSs, I would recommend you build some of my WiFI modules for them:


I also control everything with a Raspberry PI - great little boxes
 

sshoecraft

Member
Joined
Jan 23, 2021
Messages
47
I was looking at the serial code and it looks like it may have been trying to set the stop bits/parity incorrectly.

I updated it to force: 8,N,1

// 8 bits, no parity, one stop bit
options.c_cflag &= ~PARENB;
options.c_cflag &= ~CSTOPB;
options.c_cflag &= ~CSIZE;
options.c_cflag |= CS8;

Attached is an updated binary. If you still have issues, definitely check the serial connections.
 

Attachments

  • jbdtool_pi_static.zip
    1.3 MB · Views: 114

chuckp

Member
Joined
Jul 29, 2018
Messages
404
Chuck, has your nephew published this system in github, etc? I'd like to take a look at it as I'm doing something similar ATM (I have SMA Sunny Islands).
Not yet. He is still working on it and will be using the project as per of his uni work. But he will be publishing it eventually.
 

sshoecraft

Member
Joined
Jan 23, 2021
Messages
47
I've done some work on it so far; here's my github.


I completely changed my architecture; I now do all my agent/client communication via MQTT. The agents all publish to MQTT and I can have any number of clients do reporting (or, in the case of solard) and controlling. I am even able to set configuration params over MQTT.

I only have JBD BMSs and Sunny Island/Sunny Boy working so far, but I have a JIKONG active balancing BMS to test with now as well. The controller is a work in progress but I am able to set config and control the BMS and Sunny Island with MQTT messages.

Setting config params on the Sunny Island requires the RS485 card and a RS485 connection. In my case, I use a dual 485/CAN bus HAT in my RPI:


Which serves as both the updater for Sunny Island as well as setting config params. I'm using a modified version of the YASDI libary right now, but I am working on my own smanet lib.

I'm interested to see his work as it's nice to see what others are doing.
 

AndrewL

New member
Joined
Mar 27, 2021
Messages
3
@sshoecraft

I have replaced the USB to tty converter and that has solved the issue!

It may have had an intermittent fault from new, I remember having some trouble setting up the profile on the BMS. I assumed it was finger trouble!

@chuckp I have had some success emulating Pylon Battery messages over the CANBUS interface to my ME3000SP. The fault light on the inverter is off and it is sending heartbeat messages in response to my status messages. I now need to run a full cycle to check if everything works as expected.

Andrew
 
Top