This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

BLE connection handle value scope

I would like to use connection handle value as index to an array which store some per connection specific data. Some questions about connection handle:

  1. is connection handle value allocated by SD continuous?

  2. Suppose 6 connections has been established, and then one of them disconnected. Will this handle value be re-used to next built connection, or just abandoned?

Thanks in advance.

  • Hi,

    I have heard this idea before, but there are some pitfalls:

    Q1: Not necessarily. It is continuous as long as no devices disconnects. I.e. the first device will get handle 0, device number 2 gets handle 1, and so on. But if the first device disconnects, then device number 3 might get handle 0 again. Furthermore, due to the supervision timeout mechanism, it might in some cases take some time before the Softdevice detects that a device has lost its connection. And if the same device then tries to reconnect quickly (before the supervision timeout occurs) it might get assigned a new connection handle. Hence, it is actually possible that the same device has two connection handles at the same time, although only until the supervision timeout occurs.

    Q2: Yes, the Softdevice will reuse connection handles, and a particular device will not necessarily get the same connection handle value on every connection.

    Another solution to individually identify connected devices is to bond all your devices. Or you can use other information like e.g MAC addresses.

  • thanks for the detailed answer. As in my use cases, the devices at the other end is random and un-predicate-able, so i can not pre-bond any devices. Is there any other better way to do this?

  • I'm not sure if I understand. Why would you have to pre-bond? Can't you bond the devices the first time they connect?

  • Martin, Probably i did not describe the question clearly. The root issue behind it is when there are multiple peer devices connecting at the same time to the same service/characteristic, I need to distinguish the data from different devices, so i can handle them differently, say, forward to different buffer for further processing.

    Using conn handle indexing seems OK except it has to go through a lookup table given it is not continuous which may consume some CPU cycles, when there is more connection number.

    So in this case i am not sure if bonding will help as in service write event seems no bonding information available help faster device indexing.

    Is there any better way to do this?

    thanks.

  • I don't think there are any ways around sacrificing some CPU cycles on this one.

    I suppose one obvious way to distinguish device A and device B when they connect is to check their respective addresses. Maybe you can add a reference to each device in an array and then associate connection handles with their respective device. Then, on each BLE event referencing a connection handle, you can iterate through the array of devices and check their connection handle?

Related