guild icon
Toit
#Bluetooth GATT Handle to UUID Mapping
Thread channel in help
z3ugma
z3ugma 04/21/2024 05:48 PM
At https://libs.toit.io/ble/class-RemoteCharacteristic the docs describe a BLE GATT characteristic and let you access the UUID of the characteristic.

Separately is the concept of a BLE handle which is what raw ATT packets contain

Does Toit keep a mapping of the handle to the uuid of the characteristic, and can it be accessed from the Characteristic's properties?
floitsch
floitsch 04/21/2024 05:51 PM
I recently worked on the BLE library again but I didn't see any reference to the term "handle". My first instinct is that the handle is not exposed. I would need to look at the code to know more.
floitsch
floitsch 04/21/2024 05:51 PM
The BLE code is based on nimble. So maybe you can find more information there.
z3ugma
z3ugma 04/21/2024 05:54 PM
Check out something like https://stackoverflow.com/questions/75428882/trying-to-understand-ble-uuids-and-handles-with-bluetoothctl-example


when first interrogating a BLE device, a mapping of the handle to the UUID is maintained.

When you sent the actual BLE packet, it references the handle and not the UUID
z3ugma
z3ugma 04/21/2024 05:55 PM
nimBLE has RemoteCharacteristic::getHandle().
z3ugma
z3ugma 04/21/2024 05:56 PM
which is similar to the NimBLEUUID NimBLERemoteDescriptor::getUUID ( )

how you get the UUID?
floitsch
floitsch 04/21/2024 05:56 PM
The uuid is part of the characteristic. No?
floitsch
floitsch 04/21/2024 05:56 PM
That's how it is referenced.
z3ugma
z3ugma 04/21/2024 05:57 PM
the characteristic has 2 properties: a uuid and a handle
z3ugma
z3ugma 04/21/2024 05:58 PM
RemoteCharacteristic::getHandle()
RemoteCharacteristic::getUUID()

^^ 2 different attributes that nimBLE lets you fetch with regard to a given characteristic
floitsch
floitsch 04/21/2024 06:00 PM
I intend to work on the BLE library tomorrow. I will read up on handles then.
z3ugma
z3ugma 04/21/2024 06:23 PM
cool!

During the initial connection when you discover the services and characteristic, the BLE packet that is sent is called
use the BLE opcode : Read By Type Request (0x08)

which matches up the Handle to the UUID
floitsch
floitsch 04/21/2024 06:34 PM
I'm not yet familiar with the handles, but what does that mean for Toit?
Do we do it right or wrong? Is something still missing.
z3ugma
z3ugma 04/22/2024 02:28 PM
yes - right now, I need to send a write command to a characteristic GATT UUID.

If I know the handle but not the UUID, then it's a bunch more debugging to figure out which handle matches up to which UUID

if I know the handle, it would be nice to directly be able to identify a characteristic by its handle instead of by its UUID
z3ugma
z3ugma 04/22/2024 02:30 PM
While we are at it:



BLE's L2CAP protocol allows a packet to say if it expects more data
z3ugma
z3ugma 04/22/2024 02:30 PM
that would also be really nice to implement when subscribing to a GATT, to know if we need to await an additional packet
floitsch
floitsch 04/22/2024 02:54 PM
Ok.
floitsch
floitsch 04/22/2024 02:55 PM
I have been working on the BLE library the whole day, and will probably continue to do so tomorrow as well.
I will see if I can expose the handle and the 'more data' flag. (assuming that's what it is).
👌1
floitsch
floitsch 04/23/2024 05:07 PM
I have uploaded a PR for the handles, but I couldn't find any information on how to get to the "More Data" header field.
If you know how to get to it in nimBLE/ESP-IDF I can have another look.
👏🏻1
floitschfloitsch
I have uploaded a PR for the handles, but I couldn't find any information on how to get to the "More Data" header field. If you know how to get to it in nimBLE/ESP-IDF I can have a...
theHuanter
theHuanter 04/26/2024 09:22 AM
could the "more data" be the manufacturer data which you can add to the service?
floitsch
floitsch 04/26/2024 09:44 AM
Really don't know, but even if it is: I would need the nimble function to somehow expose it.
floitschfloitsch
Really don't know, but even if it is: I would need the nimble function to somehow expose it.
theHuanter
theHuanter 04/26/2024 09:45 AM
the manufacturer part is already in the ble library. but I am also not sure what this "more data" part might be
23 messages in total