Jakeler / ble-serial

"RFCOMM for BLE" a UART over Bluetooth low energy (4+) bridge for Linux, Mac and Windows
https://blog.ja-ke.tech/tags/#bluetooth
MIT License
251 stars 37 forks source link

HM-BT4502W - Unexpected Error: No characteristic with specified UUID #40

Closed steinhb closed 2 years ago

steinhb commented 2 years ago

Describe the bug I tried to connect a Raspberry Pi Compute Module 4 via its built-in bluetooth module to this external module: https://www.hoperf.com/modules/Bluetooth/HM-BT4502W.html I already managed to connected the module with my phone with the app 'Serial Bluetooth Terminal' so I knew the correct UUIDs already.

I followed the introduction, deep-scanned the ble-module address and tried to connect specifying the respective UUIDs. There I encountered an error that it didn't find a characteristic with the specified UUID (see log).

It turns out that changing the UUIDs in 'ble_serial/bluetooth/constants.py' to the correct ones did the trick.

Log messages Deep scan: (I marked the correct ones)

ble-scan -d 62:00:A1:1E:78:40
Started deep scan of 62:00:A1:1E:78:40

SERVICE 5833ff01-9b8b-5191-6142-22a4536ef123 (Handle: 50): Unknown
     CHARACTERISTIC 5833ff03-9b8b-5191-6142-22a4536ef123 (Handle: 53): Unknown ['notify']
         DESCRIPTOR 00002902-0000-1000-8000-00805f9b34fb (Handle: 55): Client Characteristic Configuration
     CHARACTERISTIC 5833ff02-9b8b-5191-6142-22a4536ef123 (Handle: 51): Unknown ['write']
SERVICE 0000ffe0-0000-1000-8000-00805f9b34fb (Handle: 44): Vendor specific
  -> CHARACTERISTIC 0000ffe4-0000-1000-8000-00805f9b34fb (Handle: 47): Vendor specific ['notify']
         DESCRIPTOR 00002902-0000-1000-8000-00805f9b34fb (Handle: 49): Client Characteristic Configuration
  -> CHARACTERISTIC 0000ffe9-0000-1000-8000-00805f9b34fb (Handle: 45): Vendor specific ['write-without-response', 'write'] 
SERVICE 0000ff90-0000-1000-8000-00805f9b34fb (Handle: 23): Vendor specific
     CHARACTERISTIC 0000ff9a-0000-1000-8000-00805f9b34fb (Handle: 42): Vendor specific ['read', 'write-without-response', 'write']
     CHARACTERISTIC 0000ff99-0000-1000-8000-00805f9b34fb (Handle: 40): Vendor specific ['read', 'write-without-response', 'write']
     CHARACTERISTIC 0000ff98-0000-1000-8000-00805f9b34fb (Handle: 38): Vendor specific ['read', 'write-without-response', 'write']
     CHARACTERISTIC 0000ff97-0000-1000-8000-00805f9b34fb (Handle: 36): Vendor specific ['read', 'write-without-response', 'write']
     CHARACTERISTIC 0000ff96-0000-1000-8000-00805f9b34fb (Handle: 34): Vendor specific ['read', 'write-without-response', 'write']
     CHARACTERISTIC 0000ff95-0000-1000-8000-00805f9b34fb (Handle: 32): Vendor specific ['read', 'write-without-response', 'write']
     CHARACTERISTIC 0000ff94-0000-1000-8000-00805f9b34fb (Handle: 30): Vendor specific ['write-without-response', 'write']
     CHARACTERISTIC 0000ff93-0000-1000-8000-00805f9b34fb (Handle: 28): Vendor specific ['read', 'write-without-response', 'write']
     CHARACTERISTIC 0000ff92-0000-1000-8000-00805f9b34fb (Handle: 26): Vendor specific ['read', 'write-without-response', 'write']
     CHARACTERISTIC 0000ff91-0000-1000-8000-00805f9b34fb (Handle: 24): Vendor specific ['read', 'write-without-response', 'write']
SERVICE 0000ffc0-0000-1000-8000-00805f9b34fb (Handle: 17): Vendor specific
     CHARACTERISTIC 0000ffc2-0000-1000-8000-00805f9b34fb (Handle: 20): Vendor specific ['notify', 'indicate']
         DESCRIPTOR 00002902-0000-1000-8000-00805f9b34fb (Handle: 22): Client Characteristic Configuration
     CHARACTERISTIC 0000ffc1-0000-1000-8000-00805f9b34fb (Handle: 18): Vendor specific ['write-without-response', 'write']
SERVICE 0000180a-0000-1000-8000-00805f9b34fb (Handle: 12): Device Information
     CHARACTERISTIC 00002a26-0000-1000-8000-00805f9b34fb (Handle: 15): Firmware Revision String ['read']
     CHARACTERISTIC 00002a23-0000-1000-8000-00805f9b34fb (Handle: 13): System ID ['read']
SERVICE 00001801-0000-1000-8000-00805f9b34fb (Handle: 8): Generic Attribute Profile
     CHARACTERISTIC 00002a05-0000-1000-8000-00805f9b34fb (Handle: 9): Service Changed ['indicate']
         DESCRIPTOR 00002902-0000-1000-8000-00805f9b34fb (Handle: 11): Client Characteristic Configuration

Error when trying to connect with the correct read/write UUIDs

ble-serial -d 62:00:A1:1E:78:40 -r 0000ffe4-0000-1000-8000-00805f9b34fb
08:42:19.927 | INFO | linux_pty.py: Slave created on /tmp/ttyBLE -> /dev/pts/2
08:42:19.928 | INFO | ble_interface.py: Receiver set up
08:42:19.940 | INFO | ble_interface.py: Trying to connect with 62:00:A1:1E:78:40
08:42:24.891 | INFO | ble_interface.py: Device 62:00:A1:1E:78:40 connected
08:42:24.891 | ERROR | main.py: Unexpected Error: No characteristic with specified UUID ['0000ff01-0000-1000-8000-00805f9b34fb', '0000ff02-0000-1000-8000-00805f9b34fb', '0000ffe1-0000-1000-8000-00805f9b34fb'] found!
08:42:24.892 | WARNING | main.py: Shutdown initiated
08:42:24.892 | INFO | linux_pty.py: Serial reader and symlink removed
08:42:26.876 | WARNING | ble_interface.py: Device 62:00:A1:1E:78:40 disconnected
08:42:26.877 | INFO | linux_pty.py: Stopping serial event loop
08:42:26.878 | INFO | ble_interface.py: Stopping Bluetooth event loop
08:42:26.878 | INFO | ble_interface.py: Bluetooth disconnected
08:42:26.879 | INFO | main.py: Shutdown complete.
ble-serial -d 62:00:A1:1E:78:40 -w 0000ffe9-0000-1000-8000-00805f9b34fb
08:42:46.343 | INFO | linux_pty.py: Slave created on /tmp/ttyBLE -> /dev/pts/2
08:42:46.343 | INFO | ble_interface.py: Receiver set up
08:42:46.355 | INFO | ble_interface.py: Trying to connect with 62:00:A1:1E:78:40
08:42:52.244 | INFO | ble_interface.py: Device 62:00:A1:1E:78:40 connected
08:42:52.246 | INFO | ble_interface.py: Found write characteristic 0000ffe9-0000-1000-8000-00805f9b34fb (H. 45)
08:42:52.247 | ERROR | main.py: Unexpected Error: No characteristic with specified UUID ['0000ff01-0000-1000-8000-00805f9b34fb', '0000ff02-0000-1000-8000-00805f9b34fb', '0000ffe1-0000-1000-8000-00805f9b34fb'] found!
08:42:52.248 | WARNING | main.py: Shutdown initiated
08:42:52.250 | INFO | linux_pty.py: Serial reader and symlink removed
08:42:55.014 | WARNING | ble_interface.py: Device 62:00:A1:1E:78:40 disconnected
08:42:55.015 | INFO | linux_pty.py: Stopping serial event loop
08:42:55.015 | INFO | ble_interface.py: Stopping Bluetooth event loop
08:42:55.016 | INFO | ble_interface.py: Bluetooth disconnected
08:42:55.016 | INFO | main.py: Shutdown complete.

Changed 'ble_serial/bluetooth/constants.py' to

ble_chars = [
#    '0000ff01-0000-1000-8000-00805f9b34fb', # LithiumBatteryPCB adapter: read/notify
#    '0000ff02-0000-1000-8000-00805f9b34fb', # LithiumBatteryPCB adapter: write
#    '0000ffe1-0000-1000-8000-00805f9b34fb', # TI CC245x (HM-10, HM-11)
    '0000ffe0-0000-1000-8000-00805f9b34fb', # HOPERF BT4502 - service UUID
    '0000ffe4-0000-1000-8000-00805f9b34fb', # HOPERF BT4502 - read UUID
    '0000ffe9-0000-1000-8000-00805f9b34fb', # HOPERF BT4502 - write UUID
]

Everything works fine

ble-serial -d 62:00:A1:1E:78:40
09:18:37.998 | INFO | linux_pty.py: Slave created on /tmp/ttyBLE -> /dev/pts/3
09:18:37.998 | INFO | ble_interface.py: Receiver set up
09:18:38.010 | INFO | ble_interface.py: Trying to connect with 62:00:A1:1E:78:40
09:18:44.254 | INFO | ble_interface.py: Device 62:00:A1:1E:78:40 connected
09:18:44.255 | INFO | ble_interface.py: Found write characteristic 0000ffe9-0000-1000-8000-00805f9b34fb (H. 45)
09:18:44.255 | INFO | ble_interface.py: Found notify characteristic 0000ffe4-0000-1000-8000-00805f9b34fb (H. 47)
09:18:45.036 | INFO | main.py: Running main loop!

Setup (please complete the following information):

Jakeler commented 2 years ago

You don't have to edit bluetooth/constants.py just specify both read and write characteristic like this:

ble-serial -d 62:00:A1:1E:78:40 -r 0000ffe4-0000-1000-8000-00805f9b34fb -w 0000ffe9-0000-1000-8000-00805f9b34fb

The problem is when you specify only the read characteristic that it searches for write too, but none in the list matches. Vice versa if you only specify write. It requires both by default.

Another way would be to disable one direction, for example if you want a read only connection then the read characteristic is enough of course:

ble-serial -d 62:00:A1:1E:78:40 -r 0000ffe4-0000-1000-8000-00805f9b34fb --permit ro

I should probably explain this a bit more in the Readme and use different error messages for the builtin list vs. user supplied characteristics.

btw: service UUID is irrelevant in any case, only read/notify and write characteristic matters.

Jakeler commented 2 years ago
ble-serial -d 62:00:A1:1E:78:40 -r 0000ffe4-0000-1000-8000-00805f9b34fb -w 0000ffe9-0000-1000-8000-00805f9b34fb

@steinhb Does this solve the issue? If so please close it. I have also adjusted the readme, should be clearer now?

steinhb commented 2 years ago

Sorry to let you wait that long. I totally forgot to close the issue.

Yes, everything is fine now and in hindsight the usage totally makes sense. Thank you for helping me out!