diy solar

diy solar

JBD BMS Linux Utility

melkier

Solar Enthusiast
Joined
Jul 24, 2020
Messages
129
I wrote a utility on Linux to manage my JBD BMSs. For you Linux/Pi users, please give it a try and give me some feedback. It's written in C and is part of a larger project to manage my 14 packs (of 14s battery banks). I tried several diff types of BMSs before settling on JBD.


Any questions, PM me. Yes, it uses Makefiles. No, I havent built CMakefile/configure scripts for it yet. Yes, I'll get to them.

I have some things to do yet: some of the delay parameters cant be set, and the Hard Protection configuration I haven't fully decoded yet. Rest works pretty well and the ability to write all the params using JSON files is great.
 
I wrote a utility on Linux to manage my JBD BMSs. For you Linux/Pi users, please give it a try and give me some feedback. It's written in C and is part of a larger project to manage my 14 packs (of 14s battery banks). I tried several diff types of BMSs before settling on JBD.


Any questions, PM me. Yes, it uses Makefiles. No, I havent built CMakefile/configure scripts for it yet. Yes, I'll get to them.

I have some things to do yet: some of the delay parameters cant be set, and the Hard Protection configuration I haven't fully decoded yet. Rest works pretty well and the ability to write all the params using JSON files is great.
Fantastic work !

I'd like to see some screenshots if that's possible ?
 
Viewing standard info
# jbdtool -t ip:pack_10
Voltage 54.370
Current 0.000
DesignCapacity 80.000
RemainingCapacity 54.340
PercentCapacity 68
CycleCount 0
Probes 2
Temps 12.4,11.2
Strings 14
Cells 3.847,3.836,3.846,3.851,3.858,3.851,3.856,3.853,3.907,3.901,3.908,3.947,3.950,3.952
CellTotal 54.363
CellMin 3.836
CellMax 3.952
CellDiff 0.116
CellAvg 3.883
DeviceName 15350019-SP15S008C-P14S-100A
ManufactureDate 20201216
Version 2.5
FET Charge,Discharge

Getting & Setting Balance Start voltage
# jbdtool -t ip:pack_10 -r BalanceStartVoltage
BalanceStartVoltage 4000
# jbdtool -t ip:pack_10 -w BalanceStartVoltage 3800
# jbdtool -t ip:pack_10 -r BalanceStartVoltage
BalanceStartVoltage 3800

JSON output
# jbdtool -t ip:pack_02 -J
{
"Voltage": 54.340000152587891,
"Current": 0,
"DesignCapacity": 80,
"RemainingCapacity": 67.580001831054688,
"PercentCapacity": 84,
"CycleCount": 0,
"Probes": 2,
"Temps": [
11.6,
11.800000000000001
],
"Strings": 14,
"Cells": [
3.891,
3.8929999999999998,
3.895,
3.891,
3.8780000000000001,
3.8799999999999999,
3.8780000000000001,
3.879,
3.8759999999999999,
3.8759999999999999,
3.8799999999999999,
3.879,
3.8700000000000001,
3.8780000000000001
],
"CellTotal": 54.343997955322266,
"CellMin": 3.869999885559082,
"CellMax": 3.8949999809265137,
"CellDiff": 0.025000095367431641,
"CellAvg": 3.8817141056060791,
"DeviceName": "15350021-SP15S008C-P14S-100A",
"ManufactureDate": "20201022",
"Version": 2.5,
"FET": "Charge,Discharge"
}

non-pretty json output
# jbdtool -t ip:pack_03 -j
{"Voltage":54.310001373291016,"Current":0,"DesignCapacity":80,"RemainingCapacity":65.239997863769531,"PercentCapacity":82,"CycleCount":6,"Probes":2,"Temps":[10.1,11.699999999999999],"Strings":14,"Cells":[3.8820000000000001,3.8780000000000001,3.8820000000000001,3.879,3.8820000000000001,3.8820000000000001,3.8809999999999998,3.8820000000000001,3.8820000000000001,3.8799999999999999,3.879,3.8799999999999999,3.8740000000000001,3.8759999999999999],"CellTotal":54.319004058837891,"CellMin":3.874000072479248,"CellMax":3.8819999694824219,"CellDiff":0.0079998970031738281,"CellAvg":3.8799288272857666,"DeviceName":"15350021-SP15S008C-P14S-100A","ManufactureDate":"20201022","Version":2.5,"FET":"Charge,Discharge"}

i dont know how to get rid of the emoticons ... but thats ip colon pack
 
i just went out and plugged the bluetooth module into pack 2

# jbdtool -t bt:88:25:83:F1:F1:CB
Voltage 54.340
Current 0.000
DesignCapacity 80.000
RemainingCapacity 67.580
PercentCapacity 84
CycleCount 0
Probes 2
Temps 11.9,11.8
Strings 14
Cells 3.891,3.893,3.895,3.891,3.878,3.880,3.878,3.879,3.876,3.876,3.880,3.879,3.869,3.878
CellTotal 54.343
CellMin 3.869
CellMax 3.895
CellDiff 0.026
CellAvg 3.882
DeviceName 15350021-SP15S008C-P14S-100A
ManufactureDate 20201022
Version 2.5
FET Charge,Discharge

I'll make a post about my IP modules ... they are just an ESP8266 (esp-01) with a voltage regulator and esplink flashed onto them ... my whole battery farm is IP addressable over Wi-Fi.

I've attached a pic of one of the modules - I plug them directly into the UART port of the JBD BMS and then access them remotely. I have a wifi router in my "solar room."
 

Attachments

  • jbd-esp.jpg
    jbd-esp.jpg
    52.4 KB · Views: 57
Pack 01 and 11 are offline right now - I'm testing out one of those "active balancer" BMS (Jikong) on pack_01 and pack_11 im trying to manually balance because I mismatched the cells. I bought 2 complete bmw battery packs from batteryhookup and didnt keep the batteries from the same pack together like a dummy.
 

Attachments

  • cellmon.JPG
    cellmon.JPG
    64.3 KB · Views: 59
this is really good. I like the JBD/Overkills , they work well for my usage. Great to have contributions such as this to the DIY community.
 
FYI, I did a writeup on how to make a Wi-FI module that jbdtool connects to

 
hi, jbdtool is exactly what I have waited for .. cool that you take the time and wrote a such tool ... I tryed for a long time different tools and github projects to get the data of a JBD battery BMS every 10 seconds to store in elastic/grafana or other DB (in my case elastic). no of the other tools realy work using bluetooth.

yesterday I tryed your tool ... but whatever I used restults in a empty output.

jbdtool -t bt:A4:C1:38:10:BD:9A -j
jbdtool -t bt:A4:C1:38:10:BD:9A -r -a

I can see the led of the bluetooth module is on while command is running ... but no data ... I use a raspberry 4 with current buster ...
compiling gnattlib, mybmm, paho.mqtt.c and jbdtool was sucessfully ...

ideas are welcome ... my goal is to query any n time my BMS's and store data while charging or storing
 
hmmm, does noone have an idea what I have to do to get it running ? no of my 5 BMS replaying with the tool ...

Linux raspberrypi 5.10.17-v7l+ #1403 SMP Mon Feb 22 11:33:35 GMT 2021 armv7l GNU/Linux
Bluez-5.50

root@raspberrypi:/skbin/source/mybmm# jbdtool -t bt:a4:c1:38:d2:48:c2 -d 1
main(786): transport: 0xbebcfdf8, target: 0xbebcfdfb
jbd_new(420): pp->target: a4:c1:38:d2:48:c2, pp->opts:
main(851): mqtt: (nil)
main(894): outfp: 0x287938
bt_open(85): connecting to: a4:c1:38:d2:48:c2
Fail to connect to the bluetooth device.

the BMS module blue LED shows connection but nothing transferred ... isa there anything more I can provide as information ?

Seriell connection over USB is working .... but need it with bluetooth :)
 
Last edited:
Struggling to get jbdtool to work on a linux box. As my linux knowledge is limited to cut and paste commands, I'm not sure what I'm doing incorrectly.

I have compiled and installed gattlib and phao.mqtt.c (I think successfully). However, when I use the "make" command, from within the jbtool-main directory. I get the following.
Linux Lite 5.6 (GNU/Linux 5.4.0-89-generic x86_64)
jjhdtv-HP-G42-Notebook-PC  jjhdtv  …  local  src  jbdtool-main  127  make

\gcc -Wall -g -DDEBUG=1 -DMQTT -DBLUETOOTH -o jbdtool main.o jbd_info.o jbd.o parson.o list.o utils.o cfg.o daemon.o module.o ip.o serial.o bt.o can.o mqtt.o -lpaho-mqtt3c -lgattlib -lgobject-2.0 -lgio-2.0 -lglib-2.0 -lpthread
/usr/bin/ld: warning: libpython3.5m.so.1.0, needed by /usr/lib/gcc/x86_64-linux-gnu/9/../../../../lib/libgattlib.so, not found (try using -rpath or -rpath-link)
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/9/../../../../lib/libgattlib.so: undefined reference to `PyGILState_Release'
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/9/../../../../lib/libgattlib.so: undefined reference to `PyEval_CallObjectWithKeywords'
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/9/../../../../lib/libgattlib.so: undefined reference to `PyGILState_Ensure'
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/9/../../../../lib/libgattlib.so: undefined reference to `Py_BuildValue'
collect2: error: ld returned 1 exit status
make: *** [Makefile:72: jbdtool] Error 1

appreciate the help.
 
I'm receiving the same error in debian 11. It appears to be python related, but I have yet to find a solution
 
hi, jbdtool is exactly what I have waited for .. cool that you take the time and wrote a such tool ... I tryed for a long time different tools and github projects to get the data of a JBD battery BMS every 10 seconds to store in elastic/grafana or other DB (in my case elastic). no of the other tools realy work using bluetooth.

yesterday I tryed your tool ... but whatever I used restults in a empty output.

jbdtool -t bt:A4:C1:38:10:BD:9A -j
jbdtool -t bt:A4:C1:38:10:BD:9A -r -a

I can see the led of the bluetooth module is on while command is running ... but no data ... I use a raspberry 4 with current buster ...
compiling gnattlib, mybmm, paho.mqtt.c and jbdtool was sucessfully ...

ideas are welcome ... my goal is to query any n time my BMS's and store data while charging or storing
I have a very similar issue. I am using the Overkill/JBD BMS, raspberry pi 4. I compiled and built the dependencies as recommended. It connects and I see that with the LED and with bluetoothctl, but no data seems to be passing. What are my next steps? using debug, I see this repeating pattern which to me seems that it's not getting any replies...
bt.c(189) bt_write: buf: 0xbece896c, buflen: 7
bt.c(193) bt_write: s->c: 0xe0ee30
bt.c(156) bt_read: buf: 0xbece886c, buflen: 256
bt.c(160) bt_read: s->len: 0
bt.c(160) bt_read: s->len: 0
bt.c(160) bt_read: s->len: 0
bt.c(204) bt_close: s->c: 0xe0ee30

And I see this in bluetoothctl

[CHG] Device A4:C1:38:5D:F0:1F Connected: yes
[CHG] Device A4:C1:38:5D:F0:1F ServicesResolved: yes
[CHG] Device A4:C1:38:5D:F0:1F ServicesResolved: no
[CHG] Device A4:C1:38:5D:F0:1F Connected: no

Any help is appreciated.
 
I screwed around with Bluetooth trying to get this setup to work reliably for weeks, and the truth of the matter is that Bluetooth support in Linux is a sh*t show. Do yourself a favor... Buy the USB adapter for your BMS, plug it directly into your system, and forget that the Bluetooth dongle even exists. Your life will be better for it. :)
 
Is it possible to control the JBD BMS via this or a similar linux based method, for instance to toggle the charge or discharge ports on or off programatically? Either USB or Bluetooth would work for this, just trying to find a way to remotely manage these without having to be near the BMS bluetooth radio with the Xiaoxiang app.
 
I tried to install jbdtools to my newly patched Debian 12. Managed to install gattlib and paho.mqtt.c from git repositories... Its ugly that they don't have Debian packages and despite efforts, I did not managed to package them with checkinstall.
But when I try to run "make" in jbdtools, I get following errors:

gcc -MT bt.o -MMD -MP -MF .deps/bt.d -Wall -g -DDEBUG=1 -DMQTT -DBLUETOOTH -c -o bt.o bt.c
bt.c:22:9: error: unknown type name ‘gatt_connection_t’
22 | gatt_connection_t *c;
| ^~~~~~~~~~~~~~~~~
bt.c: In function ‘bt_open’:
bt.c:87:16: error: too few arguments to function ‘gattlib_connect’
87 | s->c = gattlib_connect(NULL, s->target, GATTLIB_CONNECTION_OPTIONS_LEGACY_DEFAULT);
| ^~~~~~~~~~~~~~~
In file included from bt.c:19:
/home/tuipveus/jbd/jbdtool/gattlib/include/gattlib.h:366:5: note: declared here
366 | int gattlib_connect(gattlib_adapter_t* adapter, const char *dst,
| ^~~~~~~~~~~~~~~
bt.c:94:38: warning: passing argument 1 of ‘gattlib_discover_char’ from incompatible pointer type [-Wincompatible-pointer-types]
94 | ret = gattlib_discover_char(s->c, &cp, &count);
| ~^~~
| |
| int *
/home/tuipveus/jbd/jbdtool/gattlib/include/gattlib.h:465:49: note: expected ‘gattlib_connection_t *’ {aka ‘struct _gattlib_connection *’} but argument is of type ‘int *’
465 | int gattlib_discover_char(gattlib_connection_t* connection, gattlib_characteristic_t** characteristics, int* characteristics_count);
| ~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~
bt.c:130:40: warning: passing argument 1 of ‘gattlib_register_notification’ from incompatible pointer type [-Wincompatible-pointer-types]
130 | gattlib_register_notification(s->c, notification_cb, s);
| ~^~~
| |
| int *
/home/tuipveus/jbd/jbdtool/gattlib/include/gattlib.h:654:57: note: expected ‘gattlib_connection_t *’ {aka ‘struct _gattlib_connection *’} but argument is of type ‘int *’
654 | int gattlib_register_notification(gattlib_connection_t* connection, gattlib_event_handler_t notification_handler, void* user_data);
| ~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~
bt.c:131:41: warning: passing argument 1 of ‘gattlib_notification_start’ from incompatible pointer type [-Wincompatible-pointer-types]
131 | if (gattlib_notification_start(s->c, &s->uuid)) {
| ~^~~
| |
| int *
/home/tuipveus/jbd/jbdtool/gattlib/include/gattlib.h:613:54: note: expected ‘gattlib_connection_t *’ {aka ‘struct _gattlib_connection *’} but argument is of type ‘int *’
613 | int gattlib_notification_start(gattlib_connection_t* connection, const uuid_t* uuid);
| ~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~
bt.c:133:37: warning: passing argument 1 of ‘gattlib_disconnect’ from incompatible pointer type [-Wincompatible-pointer-types]
133 | gattlib_disconnect(s->c);
| ~^~~
| |
| int *
/home/tuipveus/jbd/jbdtool/gattlib/include/gattlib.h:385:46: note: expected ‘gattlib_connection_t *’ {aka ‘struct _gattlib_connection *’} but argument is of type ‘int *’
385 | int gattlib_disconnect(gattlib_connection_t* connection, bool wait_disconnection);
| ~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~
bt.c:133:17: error: too few arguments to function ‘gattlib_disconnect’
133 | gattlib_disconnect(s->c);
| ^~~~~~~~~~~~~~~~~~
/home/tuipveus/jbd/jbdtool/gattlib/include/gattlib.h:385:5: note: declared here
385 | int gattlib_disconnect(gattlib_connection_t* connection, bool wait_disconnection);
| ^~~~~~~~~~~~~~~~~~
bt.c: In function ‘bt_write’:
bt.c:194:41: warning: passing argument 1 of ‘gattlib_write_char_by_uuid’ from incompatible pointer type [-Wincompatible-pointer-types]
194 | if (gattlib_write_char_by_uuid(s->c, &s->uuid, buf, buflen)) return -1;
| ~^~~
| |
| int *
/home/tuipveus/jbd/jbdtool/gattlib/include/gattlib.h:533:54: note: expected ‘gattlib_connection_t *’ {aka ‘struct _gattlib_connection *’} but argument is of type ‘int *’
533 | int gattlib_write_char_by_uuid(gattlib_connection_t* connection, uuid_t* uuid, const void* buffer, size_t buffer_len);
| ~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~
bt.c: In function ‘bt_close’:
bt.c:208:52: warning: passing argument 1 of ‘gattlib_notification_stop’ from incompatible pointer type [-Wincompatible-pointer-types]
208 | gattlib_notification_stop(s->c, &s->uuid);
| ~^~~
| |
| int *
/home/tuipveus/jbd/jbdtool/gattlib/include/gattlib.h:623:53: note: expected ‘gattlib_connection_t *’ {aka ‘struct _gattlib_connection *’} but argument is of type ‘int *’
623 | int gattlib_notification_stop(gattlib_connection_t* connection, const uuid_t* uuid);
| ~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~
bt.c:212:37: warning: passing argument 1 of ‘gattlib_disconnect’ from incompatible pointer type [-Wincompatible-pointer-types]
212 | gattlib_disconnect(s->c);
| ~^~~
| |
| int *
/home/tuipveus/jbd/jbdtool/gattlib/include/gattlib.h:385:46: note: expected ‘gattlib_connection_t *’ {aka ‘struct _gattlib_connection *’} but argument is of type ‘int *’
385 | int gattlib_disconnect(gattlib_connection_t* connection, bool wait_disconnection);
| ~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~
bt.c:212:17: error: too few arguments to function ‘gattlib_disconnect’
212 | gattlib_disconnect(s->c);
| ^~~~~~~~~~~~~~~~~~
/home/tuipveus/jbd/jbdtool/gattlib/include/gattlib.h:385:5: note: declared here
385 | int gattlib_disconnect(gattlib_connection_t* connection, bool wait_disconnection);
| ^~~~~~~~~~~~~~~~~~
make: *** [Makefile:92: bt.o] Error 1
 
I can see my 4 batteries with bluetoothctl, I can "trust" them, but I can not pair them, since it complains about password.
So I have 2 problems:
1) I can not compile sshoecraft/jbdtool
2) I can not connect to my batteries
 
I have no idea what I am doing, but this way I got the compilation through:
I modified bt.c.

There must be some better way to give correct parameters for gattlib_connect().

--- ../../jbdtool/bt.c 2024-04-21 19:39:03.479964846 +0300
+++ bt.c 2024-04-21 20:01:59.040490626 +0300
@@ -16,10 +16,10 @@
#undef DEBUG_MEM

#include "mybmm.h"
-#include <gattlib.h>
+#include "gattlib.h"

struct bt_session {
- gattlib_connection_t* c;
+ gatt_connection_t *c;
uuid_t uuid;
char target[32];
char topts[32];
@@ -84,7 +84,7 @@
if (s->c) return 0;

dprintf(1,"connecting to: %s\n", s->target);
- s->c = gattlib_connect(NULL, s->target, GATTLIB_CONNECTION_OPTIONS_LEGACY_DEFAULT, NULL, NULL);
+ s->c = gattlib_connect(NULL, s->target, GATTLIB_CONNECTION_OPTIONS_LEGACY_DEFAULT);
if (!s->c) {
log_write(LOG_ERROR,"Fail to connect to the bluetooth device.\n");
return 1;
@@ -130,7 +130,7 @@
gattlib_register_notification(s->c, notification_cb, s);
if (gattlib_notification_start(s->c, &s->uuid)) {
dprintf(1,"error: failed to start bluetooth notification.\n");
- gattlib_disconnect(s->c, NULL);
+ gattlib_disconnect(s->c);
return 1;
} else {
s->not = 1;
@@ -209,7 +209,7 @@
s->not = 0;
}
dprintf(1,"disconnecting...\n");
- gattlib_disconnect(s->c, false);
+ gattlib_disconnect(s->c);
s->c = 0;
}
return 0;

ps. I still can't connect with bluetoothctl,
[bluetooth]# pair FF:C1:38:FF:43:6E
Attempting to pair with FF:C1:38:FF:43:6E
[CHG] Device FF:C1:38:FF:43:6E Connected: yes
Failed to pair: org.bluez.Error.AuthenticationFailed
[CHG] Device FF:C1:38:FF:43:6E Connected: no

How can I give a password, which is 4 zeroes or 6 zeroes for bluetoothctl?
 
Back
Top