https://toitlang.org/ logo
Bluetooth GATT Handle to UUID Mapping
# help
z
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?
f
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.
The BLE code is based on nimble. So maybe you can find more information there.
z
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
nimBLE has
RemoteCharacteristic::getHandle().
which is similar to the
Copy code
NimBLEUUID NimBLERemoteDescriptor::getUUID    (        )
how you get the UUID?
f
The uuid is part of the characteristic. No?
That's how it is referenced.
z
the characteristic has 2 properties: a uuid and a handle
RemoteCharacteristic::getHandle() RemoteCharacteristic::getUUID() ^^ 2 different attributes that nimBLE lets you fetch with regard to a given characteristic
f
I intend to work on the BLE library tomorrow. I will read up on handles then.
z
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
f
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.
z
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
that would also be really nice to implement when subscribing to a GATT, to know if we need to await an additional packet
f
Ok.
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).
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.
i
could the "more data" be the manufacturer data which you can add to the service?
f
Really don't know, but even if it is: I would need the nimble function to somehow expose it.
i
the manufacturer part is already in the ble library. but I am also not sure what this "more data" part might be
3 Views