This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Is it safe to use conn_handle as an index to an array?

In other words, is it safe to assume that in various BLE events, conn_handle is either invalid (0xFFFF) or between 0 and (CENTRAL_LINK_COUNT + PERIPHERAL_LINK_COUNT - 1), as used in softdevice_enable_get_default_config()?

I've seen this used in nRF5_SDK_12.2.0_f012efa\examples\ble_central\ble_app_multilink_central\main.c, but not in the documents.

Parents
  • Hi,

    What is your purpose of doing that? I have seen a similar question where the purpose was to store information about connected devices in an array and later use the connection handle as an index to access the information in the array. The problem with this though, is that sometimes it takes time for the SoftDevice to detect a disconnection (supervision timeout) and until the supervision timeout kicks in, the connection handle is not reused. So consider this:

    1. A device connects to our SoftDevice and gets assigned a connection handle.

    2. The device moves away or there is some kind of link loss.

    3. If the same device immediately reconnects before supervision timeout then the same device will get a new connection handle. That's how you will end up with the same device having 2 different connection handles.

    Hence, you have to be very careful if you want to do this.

Reply
  • Hi,

    What is your purpose of doing that? I have seen a similar question where the purpose was to store information about connected devices in an array and later use the connection handle as an index to access the information in the array. The problem with this though, is that sometimes it takes time for the SoftDevice to detect a disconnection (supervision timeout) and until the supervision timeout kicks in, the connection handle is not reused. So consider this:

    1. A device connects to our SoftDevice and gets assigned a connection handle.

    2. The device moves away or there is some kind of link loss.

    3. If the same device immediately reconnects before supervision timeout then the same device will get a new connection handle. That's how you will end up with the same device having 2 different connection handles.

    Hence, you have to be very careful if you want to do this.

Children
No Data
Related