pygattlib icon indicating copy to clipboard operation
pygattlib copied to clipboard

Notifications

Open better-adapted opened this issue 4 years ago • 1 comments

I have been trying the read_callback.py and read_notification.py

I cannot see how to get the notifications working on a specific UUID - do I need to manually write gatt data to do this?

I can manually read the UUID but cannot get any further - see the below mash-up of the two demo's

adam1.zip

better-adapted avatar Dec 02 '20 19:12 better-adapted

Just a quick note on this (the canned examples and docs do need improvement here):

You need to find the handle for the callback descriptor (2902) corresponding to the attribute that supports notifications/indications (that is, using a recent version, an attribute that has the GATT_CHR_PROP_NOTIFY or GATT_CHR_PROP_INDICATE bits set in the properties field returned while enumerating the device). That handle value sadly isn't directly returned, but it is the "gap" value between that attribute and the one after it.

You then (again, using a recent version) can call enable_notifications() on the device, passing that handle value, turning on notifications or indications as appropriate given the above properties bits.

From that point on you'll get callbacks via on_notification or on_indication on your derived GATTRequester class (...err, you need to override that class to catch those callbacks), the passed value being the full packet value (including a prefix of the packet opcode byte and 2-byte handle value, so you have to ignore the first 3 bytes.)

When disconnecting it's best to turn those notifications off again before calling disconnect, so that if you reconnect again soon enough you don't end up fielding callbacks before you're ready.

jsgh avatar Jan 24 '21 04:01 jsgh