sshoecraft / jbdtool

JBD BMS Linux utility
BSD 3-Clause "New" or "Revised" License
46 stars 10 forks source link

Empty output #10

Closed sabakad closed 1 year ago

sabakad commented 2 years ago

Hi, I'm still struggling to get jbdtool output working for me. What I've done:

  1. compiled and installed gattlib, paho.mqqt.c, jbdtool
  2. tested via gatttool -b A4:C1:37:30:2B:74 -I and sudo btmon -A -T that BT LE communication works by reading random characteristics.
  3. Bluetoothctl trust A4:C1:37:30:2B:74 ->succeeded, pair A4:C1:37:30:2B:74->Failed to pair: org.bluez.Error.AuthenticationFailed, [CHG] Device A4:C1:37:30:2B:74 Connected: no
  4. in var/log/messages-> bluetoothd[9395]: src/adapter.c:dev_disconnected() Device A4:C1:37:30:2B:74 disconnected, reason 2
  5. issued sudo ./jbdtool -a -t bt:A4:C1:37:30:2B:74 and got empty output after ~2secs
  6. captured comms. from btmon below... Any hint how to get pair done as it fails always (not asking for password, also there is not one as it's LE device?)... Or how to get it working without pairing as comms works without that fine in gatttool? Thank you thank you a lot!!

Log from sudo btmon -A -T:

Bluetooth monitor ver 5.55 = Note: Linux version 5.15.53-v7l+ (armv7l) 2022-07-19 09:34:13.372559 = Note: Bluetooth subsystem version 2.22 2022-07-19 09:34:13.372565 = New Index: 00:1A:7D:DA:71:0A (Primary,USB,hci0) [hci0] 2022-07-19 09:34:13.372569 = Open Index: 00:1A:7D:DA:71:0A [hci0] 2022-07-19 09:34:13.372572 = Index Info: 00:1A:7D:DA:71:0A (Cambridge Silicon Radio) [hci0] 2022-07-19 09:34:13.372574 @ MGMT Open: bluetoothd (privileged) version 1.21 {0x0001} 2022-07-19 09:34:13.372577 < HCI Command: LE Set Scan Parameters (0x08|0x000b) plen 7 #1 [hci0] 2022-07-19 09:34:33.928642 Type: Passive (0x00) Interval: 60.000 msec (0x0060) Window: 60.000 msec (0x0060) Own address type: Public (0x00) Filter policy: Ignore not in white list (0x01)

HCI Event: Command Complete (0x0e) plen 4 #2 [hci0] 2022-07-19 09:34:33.930874 LE Set Scan Parameters (0x08|0x000b) ncmd 1 Status: Success (0x00) < HCI Command: LE Set Scan Enable (0x08|0x000c) plen 2 #3 [hci0] 2022-07-19 09:34:33.930952 Scanning: Enabled (0x01) Filter duplicates: Enabled (0x01) HCI Event: Command Complete (0x0e) plen 4 #4 [hci0] 2022-07-19 09:34:33.933870 LE Set Scan Enable (0x08|0x000c) ncmd 1 Status: Success (0x00) HCI Event: LE Meta Event (0x3e) plen 42 #5 [hci0] 2022-07-19 09:34:33.949868 LE Advertising Report (0x02) Num reports: 1 Event type: Connectable undirected - ADV_IND (0x00) Address type: Public (0x00) Address: A4:C1:37:30:2B:74 (OUI A4-C1-37) Data length: 30 Flags: 0x06 LE General Discoverable Mode BR/EDR Not Supported 16-bit Service UUIDs (partial): 1 entry Unknown (0xff00) Name (complete): SP10S009-L8S-100A-B-U RSSI: -69 dBm (0xbb) < HCI Command: LE Set Scan Enable (0x08|0x000c) plen 2 #6 [hci0] 2022-07-19 09:34:33.949963 Scanning: Disabled (0x00) Filter duplicates: Disabled (0x00) HCI Event: Command Complete (0x0e) plen 4 #7 [hci0] 2022-07-19 09:34:33.973881 LE Set Scan Enable (0x08|0x000c) ncmd 1 Status: Success (0x00) < HCI Command: LE Create Connection (0x08|0x000d) plen 25 #8 [hci0] 2022-07-19 09:34:33.973953 Scan interval: 60.000 msec (0x0060) Scan window: 60.000 msec (0x0060) Filter policy: White list is not used (0x00) Peer address type: Public (0x00) Peer address: A4:C1:37:30:2B:74 (OUI A4-C1-37) Own address type: Public (0x00) Min connection interval: 15.00 msec (0x000c) Max connection interval: 30.00 msec (0x0018) Connection latency: 0 (0x0000) Supervision timeout: 4000 msec (0x0190) Min connection length: 0.000 msec (0x0000) Max connection length: 0.000 msec (0x0000) HCI Event: Command Status (0x0f) plen 4 #9 [hci0] 2022-07-19 09:34:33.981883 LE Create Connection (0x08|0x000d) ncmd 1 Status: Success (0x00) HCI Event: LE Meta Event (0x3e) plen 19 #10 [hci0] 2022-07-19 09:34:34.009879 LE Connection Complete (0x01) Status: Success (0x00) Handle: 70 Role: Master (0x00) Peer address type: Public (0x00) Peer address: A4:C1:37:30:2B:74 (OUI A4-C1-37) Connection interval: 30.00 msec (0x0018) Connection latency: 0 (0x0000) Supervision timeout: 4000 msec (0x0190) Master clock accuracy: 0x00 @ MGMT Event: Device Connected (0x000b) plen 43 {0x0001} [hci0] 2022-07-19 09:34:34.009930 LE Address: A4:C1:37:30:2B:74 (OUI A4-C1-37) Flags: 0x00000008 Unknown device flag (0x00000008) Data length: 30 Flags: 0x06 LE General Discoverable Mode BR/EDR Not Supported 16-bit Service UUIDs (partial): 1 entry Unknown (0xff00) Name (complete): SP10S009-L8S-100A-B-U < HCI Command: LE Read Remote Used Features (0x08|0x0016) plen 2 #11 [hci0] 2022-07-19 09:34:34.010099 Handle: 70 HCI Event: Command Status (0x0f) plen 4 #12 [hci0] 2022-07-19 09:34:34.015899 LE Read Remote Used Features (0x08|0x0016) ncmd 0 Status: Success (0x00) HCI Event: Command Status (0x0f) plen 4 #13 [hci0] 2022-07-19 09:34:34.107901 NOP (0x00|0x0000) ncmd 1 Status: Success (0x00) HCI Event: LE Meta Event (0x3e) plen 12 #14 [hci0] 2022-07-19 09:34:34.166914 LE Read Remote Used Features (0x04) Status: Success (0x00) Handle: 70 Features: 0x3d 0x00 0x00 0x00 0x00 0x00 0x00 0x00 LE Encryption Extended Reject Indication Slave-initiated Features Exchange LE Ping LE Data Packet Length Extension < ACL Data TX: Handle 70 flags 0x00 dlen 7 #15 [hci0] 2022-07-19 09:34:34.168172 ATT: Exchange MTU Request (0x02) len 2 Client RX MTU: 517 HCI Event: Number of Completed Packets (0x13) plen 5 #16 [hci0] 2022-07-19 09:34:34.196918 Num handles: 1 Handle: 70 Count: 1 ACL Data RX: Handle 70 flags 0x02 dlen 7 #17 [hci0] 2022-07-19 09:34:34.226341 ATT: Exchange MTU Response (0x03) len 2 Server RX MTU: 23 < ACL Data TX: Handle 70 flags 0x00 dlen 7 #18 [hci0] 2022-07-19 09:34:34.227162 ATT: Read Request (0x0a) len 2 Handle: 0x000e HCI Event: Number of Completed Packets (0x13) plen 5 #19 [hci0] 2022-07-19 09:34:34.256924 Num handles: 1 Handle: 70 Count: 1 ACL Data RX: Handle 70 flags 0x02 dlen 12 #20 [hci0] 2022-07-19 09:34:34.286368 ATT: Read Response (0x0b) len 7 Value: 028a2466820100 < ACL Data TX: Handle 70 flags 0x00 dlen 7 #21 [hci0] 2022-07-19 09:34:34.286796 ATT: Read Request (0x0a) len 2 Handle: 0x0003 HCI Event: Number of Completed Packets (0x13) plen 5 #22 [hci0] 2022-07-19 09:34:34.316928 Num handles: 1 Handle: 70 Count: 1 ACL Data RX: Handle 70 flags 0x02 dlen 27 #23 [hci0] 2022-07-19 09:34:34.346482 ATT: Read Response (0x0b) len 22 Value: 53503130533030392d4c38532d313030412d422d5500 < ACL Data TX: Handle 70 flags 0x00 dlen 7 #24 [hci0] 2022-07-19 09:34:34.346755 ATT: Read Request (0x0a) len 2 Handle: 0x0005 HCI Event: Number of Completed Packets (0x13) plen 5 #25 [hci0] 2022-07-19 09:34:34.376931 Num handles: 1 Handle: 70 Count: 1 ACL Data RX: Handle 70 flags 0x02 dlen 7 #26 [hci0] 2022-07-19 09:34:34.406328 ATT: Read Response (0x0b) len 2 Value: 0000 < ACL Data TX: Handle 70 flags 0x00 dlen 11 #27 [hci0] 2022-07-19 09:34:34.406728 ATT: Read By Type Request (0x08) len 6 Handle range: 0x0001-0xffff Attribute type: Unknown (0x2b3a) HCI Event: Number of Completed Packets (0x13) plen 5 #28 [hci0] 2022-07-19 09:34:34.443942 Num handles: 1 Handle: 70 Count: 1 ACL Data RX: Handle 70 flags 0x02 dlen 9 #29 [hci0] 2022-07-19 09:34:34.466335 ATT: Error Response (0x01) len 4 Read By Type Request (0x08) Handle: 0x0001 Error: Attribute Not Found (0x0a) < ACL Data TX: Handle 70 flags 0x00 dlen 11 #30 [hci0] 2022-07-19 09:34:34.466650 ATT: Read By Group Type Request (0x10) len 6 Handle range: 0x0001-0xffff Attribute group type: Primary Service (0x2800) HCI Event: Number of Completed Packets (0x13) plen 5 #31 [hci0] 2022-07-19 09:34:34.496941 Num handles: 1 Handle: 70 Count: 1 ACL Data RX: Handle 70 flags 0x02 dlen 24 #32 [hci0] 2022-07-19 09:34:34.526459 ATT: Read By Group Type Response (0x11) len 19 Attribute data length: 6 Attribute group list: 3 entries Handle range: 0x0001-0x0007 UUID: Generic Access Profile (0x1800) Handle range: 0x0008-0x000b UUID: Generic Attribute Profile (0x1801) Handle range: 0x000c-0x000e UUID: Device Information (0x180a) < ACL Data TX: Handle 70 flags 0x00 dlen 9 #33 [hci0] 2022-07-19 09:34:34.526718 ATT: Read Blob Request (0x0c) len 4 Handle: 0x0003 Offset: 0x0016 HCI Event: Number of Completed Packets (0x13) plen 5 #34 [hci0] 2022-07-19 09:34:34.556956 Num handles: 1 Handle: 70 Count: 1 ACL Data RX: Handle 70 flags 0x02 dlen 5 #35 [hci0] 2022-07-19 09:34:34.586296 ATT: Read Blob Response (0x0d) len 0 < ACL Data TX: Handle 70 flags 0x00 dlen 11 #36 [hci0] 2022-07-19 09:34:34.586668 ATT: Read By Group Type Request (0x10) len 6 Handle range: 0x000f-0xffff Attribute group type: Primary Service (0x2800) HCI Event: Number of Completed Packets (0x13) plen 5 #37 [hci0] 2022-07-19 09:34:34.616962 Num handles: 1 Handle: 70 Count: 1 ACL Data RX: Handle 70 flags 0x02 dlen 18 #38 [hci0] 2022-07-19 09:34:34.646412 ATT: Read By Group Type Response (0x11) len 13 Attribute data length: 6 Attribute group list: 2 entries Handle range: 0x000f-0x0016 UUID: Unknown (0xff00) Handle range: 0x0017-0x001a UUID: Unknown (0xfa00) < ACL Data TX: Handle 70 flags 0x00 dlen 11 #39 [hci0] 2022-07-19 09:34:34.646659 ATT: Read By Group Type Request (0x10) len 6 Handle range: 0x001b-0xffff Attribute group type: Primary Service (0x2800) HCI Event: Number of Completed Packets (0x13) plen 5 #40 [hci0] 2022-07-19 09:34:34.676968 Num handles: 1 Handle: 70 Count: 1 ACL Data RX: Handle 70 flags 0x02 dlen 9 #41 [hci0] 2022-07-19 09:34:34.706322 ATT: Error Response (0x01) len 4 Read By Group Type Request (0x10) Handle: 0x001b Error: Attribute Not Found (0x0a) < ACL Data TX: Handle 70 flags 0x00 dlen 9 #42 [hci0] 2022-07-19 09:34:34.733608 ATT: Write Request (0x12) len 4 Handle: 0x000b Data: 0200 HCI Event: Number of Completed Packets (0x13) plen 5 #43 [hci0] 2022-07-19 09:34:34.736987 Num handles: 1 Handle: 70 Count: 1 ACL Data RX: Handle 70 flags 0x02 dlen 5 #44 [hci0] 2022-07-19 09:34:34.796300 ATT: Write Response (0x13) len 0 ACL Data RX: Handle 70 flags 0x02 dlen 16 #45 [hci0] 2022-07-19 09:34:35.006425 LE L2CAP: Connection Parameter Update Request (0x12) ident 1 len 8 Min interval: 12 Max interval: 24 Slave latency: 0 Timeout multiplier: 400 @ MGMT Event: New Connection Parameter (0x001c) plen 16 {0x0001} [hci0] 2022-07-19 09:34:35.006527 Store hint: Reserved (0x74) LE Address: 01:A4:C1:37:30:2B (OUI 01-A4-C1) Min connection interval: 12 Max connection interval: 24 Connection latency: 0 (0x0000) Supervision timeout: 400 < ACL Data TX: Handle 70 flags 0x00 dlen 10 #46 [hci0] 2022-07-19 09:34:35.006557 LE L2CAP: Connection Parameter Update Response (0x13) ident 1 len 2 Result: Connection Parameters accepted (0x0000) < HCI Command: LE Connection Update (0x08|0x0013) plen 14 #47 [hci0] 2022-07-19 09:34:35.006648 Handle: 70 Min connection interval: 15.00 msec (0x000c) Max connection interval: 30.00 msec (0x0018) Connection latency: 0 (0x0000) Supervision timeout: 4000 msec (0x0190) Min connection length: 0.000 msec (0x0000) Max connection length: 0.000 msec (0x0000) HCI Event: Command Status (0x0f) plen 4 #48 [hci0] 2022-07-19 09:34:35.012020 LE Connection Update (0x08|0x0013) ncmd 1 Status: Success (0x00) HCI Event: Number of Completed Packets (0x13) plen 5 #49 [hci0] 2022-07-19 09:34:35.038030 Num handles: 1 Handle: 70 Count: 1 HCI Event: LE Meta Event (0x3e) plen 10 #50 [hci0] 2022-07-19 09:34:35.216058 LE Connection Update Complete (0x03) Status: Success (0x00) Handle: 70 Connection interval: 30.00 msec (0x0018) Connection latency: 0 (0x0000) Supervision timeout: 4000 msec (0x0190) @ MGMT Command: Disconnect (0x0014) plen 7 {0x0001} [hci0] 2022-07-19 09:34:37.229408 LE Address: A4:C1:37:30:2B:74 (OUI A4-C1-37) < HCI Command: Disconnect (0x01|0x0006) plen 3 #51 [hci0] 2022-07-19 09:34:37.229498 Handle: 70 Reason: Remote User Terminated Connection (0x13) HCI Event: Command Status (0x0f) plen 4 #52 [hci0] 2022-07-19 09:34:37.231313 Disconnect (0x01|0x0006) ncmd 1 Status: Success (0x00) HCI Event: Disconnect Complete (0x05) plen 4 #53 [hci0] 2022-07-19 09:34:37.257323 Status: Success (0x00) Handle: 70 Reason: Connection Terminated By Local Host (0x16) @ MGMT Event: Command Complete (0x0001) plen 10 {0x0001} [hci0] 2022-07-19 09:34:37.257391 Disconnect (0x0014) plen 7 Status: Success (0x00) LE Address: A4:C1:37:30:2B:74 (OUI A4-C1-37)

mav- commented 2 years ago

Looks like I have the same problem, -l works fine, but requesting a specific value yields no output ./jbdtool -t bt:E0:9F:2A:E4:A1:12 -l DesignCapacity CycleCapacity FullChargeVol ChargeEndVol DischargingRate ManufactureDate SerialNumber (..)

sshoecraft commented 1 year ago

the -l (ell) option just provides a list of all field names, not the values themselves. Its so you can use the names from the list to ask for specific values (or use -a for all values).

for example:

jbdtool -l | grep -i balance

BalanceStartVoltage BalanceWindow

jbdtool -t ip:pack_01 -r BalanceStartVoltage

BalanceStartVoltage 3950

(example uses the wifi adapter: https://diysolarforum.com/threads/jbd-bms-wi-fi-module.17252/)

the original question was about BT. I have finally aquired a JBD BT adapter (vs a generic one from amazon) and I'll start testing it next week.

sshoecraft commented 1 year ago

sabakad, have a look at mav's reply on another thread:

Couldn't get this to work, spend too much time on it already. However, for what its worth, this did work for me:

Install https://github.com/Jakeler/ble-serial with pip install ble-serial. Run ble-scan to identify BMS:

$ ble-scan
Started BLE scan

A4:C1:38:19:9A:A2 (RSSI=-54): 16S10AH-LIGHT
A4:C1:38:F0:86:0D (RSSI=-91): 16S20AH50A

then run:

$ ble-serial -d A4:C1:38:F0:86:0D

Should get the following output:

21:34:19.750 | INFO | linux_pty.py: Slave created on /tmp/ttyBLE -> /dev/pts/0
21:34:19.750 | INFO | ble_interface.py: Receiver set up
21:34:19.913 | INFO | ble_interface.py: Trying to connect with A4:C1:38:F0:86:0D: 16S20AH50A
21:34:22.252 | INFO | ble_interface.py: Device A4:C1:38:F0:86:0D connected
21:34:22.253 | INFO | ble_interface.py: Found write characteristic 0000ff02-0000-1000-8000-00805f9b34fb (H. 20)
21:34:22.253 | INFO | ble_interface.py: Found notify characteristic 0000ff01-0000-1000-8000-00805f9b34fb (H. 16)
21:34:22.622 | INFO | main.py: Running main loop!

Now you can use jbdtool to connect to the serial port mentioned:

jbdtool -t serial:/dev/pts/0 
Voltage                   53.400
Current                   0.000
DesignCapacity            20.000
RemainingCapacity         19.990
PercentCapacity           100
CycleCount                14
Probes                    3
Strings                   16
Temps                     19.0,19.0,19.1
Cells                     3.337,3.336,3.336,3.337,3.341,3.338,3.339,3.337,3.339,3.335,3.339,3.337,3.339,3.337,3.339,3.335
Balance                   0000000000000000
CellTotal                 53.401
CellMin                   3.335
CellMax                   3.341
CellDiff                  0.006
CellAvg                   3.338
DeviceName                SP20S020A-L16S-50A-50A-B-U
ManufactureDate           20211101
Version                   12.9
FET                       Charge,Discharge

this might work for you

sabakad commented 1 year ago

Thanks, I've resolved it by using UART instead, since then it works like charm :-)