How to switch between connection handles when nrf52 is connected to multiple centrals?

pranay.dhuri gravatar image

asked 2017-03-20 07:11:25 +0100


I am using nRF52 and SDK13 with SoftDevice 132 v 4.0.2 which is now supporting multi-peripheral connections. I am using multi-peripheral example for reference. In that i have connected 4 android devices to nRF52. I want to send data from nRF52 to each of connected device. So i think I need to switch between connection handles to send data..How to achieve this?

edit retag flag offensive close delete report spam

2 answers

Sort by ยป oldest newest most voted
sijohans gravatar image

answered 2017-03-20 15:26:37 +0100

I also have some question about this. Assume my application can handle 4 concurrent connections and i configure the softdevice for this. Will the connection handles always be in range [0:3]?

If i have a structure (this is just an example) that holds the state of a client, and have an array of these structures, is it safe to use the connection handle as index in the array?

typedef struct ble_client_s {
    volatile uint8_t     is_connected;
    volatile uint8_t     notification_enabled;
    app_fifo_t  rx_queue;
    app_fifo_t  tx_queue;
    void        *p_context;
} ble_client_t;

static ble_client_t m_ble_clients[4];

static void isr_ble_evt_handler(ble_evt_t *p_ble_evt)
    switch (p_ble_evt->header.evt_id)
            m_ble_clients[p_ble_evt->evt.gatts_evt.conn_handle].is_connected = 1;
        } break; /* BLE_GAP_EVT_CONNECTED */
            m_ble_clients[p_ble_evt->evt.gatts_evt.conn_handle].is_connected = 0;
        } break; /* BLE_GAP_EVT_DISCONNECTED */

        /* ... */



If this a suitable solution to hold states of the different connected clients? Or can the connection handles have other values?

edit flag offensive delete publish link more


no it's not - there's no guarantees abut the connection handle value. It might work today, it might fail dismally tomorrow with a new release. For full code compatibility you need to map them.

RK ( 2017-03-20 22:22:15 +0100 )editconvert to answer

Do you have a good suggestion for how to map them?

sijohans ( 2017-03-22 11:15:48 +0100 )editconvert to answer

To map the various connection handles, you can for example use an array.

Kristin ( 2017-03-27 10:55:07 +0100 )editconvert to answer
rols gravatar image

answered 2017-03-20 07:19:12 +0100

Well if the data is just a readable characteristic then there's nothing to do, you set the value, any of the connected centrals can read. if you're talking about something like notifications where you send data out proactively, those calls all take a connection handle, so just put in the connection handle of the device you want to send to.

edit flag offensive delete publish link more


Hi,Thanks RK when I am simply sending the data it is being received by lastly connected device,not by others...as you have mentioned in second case from where I should extract connection handle of each connected device?

Pranay ( 2017-03-20 07:26:16 +0100 )editconvert to answer

The connection handle is given to you when the device connects. You need to save it and use it later.

RK ( 2017-03-20 07:27:33 +0100 )editconvert to answer

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer. Do not ask a new question or reply to an answer here.

[hide preview]

Question Tools

1 follower


Asked: 2017-03-20 07:11:25 +0100

Seen: 153 times

Last updated: mars 20