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.

Parents
  • 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.

  • 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?

Reply
  • 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?

Children
No Data
Related