Can you save ble "handles" for later use?

In Xbee3 ble, can you save a service or characteristic “handle” for later use?

I tried and it seemed to work:

>>> conn=ble.gap_connect(ble.ADDR_TYPE_RANDOM, ubinascii.unhexlify(“F64D1D24B0E6”), timeout_ms=5000)

>>> list(conn.gattc_services())
[(65545, UUID(0x1800)), (655370, UUID(0x1801)), (786431, UUID(‘0000BEEF-1212-EFDE-1523-785FEF13D123’))]

>>> list(conn.gattc_characteristics(786431))
[(13, UUID(‘00004478-1212-EFDE-1523-785FEF13D123’), 18)]

>>> conn.close()

then some period of time later:

>>> conn=ble.gap_connect(ble.ADDR_TYPE_RANDOM, ubinascii.unhexlify(“F64D1D24B0E6”), timeout_ms=5000)

>>> list(conn.gattc_read_characteristic(13))
[13]

and 13 is a correct reading from that characteristic.

Is this safe? I can’t really find much of a description of these handles. Is it a digi specific concept, or is it part of BLE?

Characteristic handles are a part of BLE, they are not Digi specific. You can find more information about them online, in documents such as this: https://www.oreilly.com/library/view/getting-started-with/9781491900550/ch04.html

As for whether you can “save” the handles for later – that depends on whether you bond the connection with the other device (the GATT server). If you do, then yes you could save the handles as they’d be guaranteed not to change. However, we would probably just recommend that you look up the characteristic again on each connection. If you have know exactly which UUID you’re looking for, you can specify the service UUID on gattc_services(…) to filter the results, and then the characteristic UUID on gattc_characteristics(service_handle, …).

1 Like

Thanks.

The other part of my question had to do with OTA transactions that must take place. getting the list of services seems to occur instantly. The services are part of the advertisement, but the characteristics for each service is not. So what I gather is that when I call gap_connection() the Xbee at that point does some scanning/reading which is why gattc_services() returns seemingly instantly … but what about when I enumerate the characteristics? There must be an OTA poll for those, when does that take place?