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

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

Hi,

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?

Parents
  • 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)
        {
            case BLE_GAP_EVT_CONNECTED:
            {
                m_ble_clients[p_ble_evt->evt.gatts_evt.conn_handle].is_connected = 1;
            } break; /* BLE_GAP_EVT_CONNECTED */
            case BLE_GAP_EVT_DISCONNECTED:
            {
                m_ble_clients[p_ble_evt->evt.gatts_evt.conn_handle].is_connected = 0;
            } break; /* BLE_GAP_EVT_DISCONNECTED */
    
            /* ... */
    
            default:
                break;
    
        }
    }
    

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

Reply
  • 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)
        {
            case BLE_GAP_EVT_CONNECTED:
            {
                m_ble_clients[p_ble_evt->evt.gatts_evt.conn_handle].is_connected = 1;
            } break; /* BLE_GAP_EVT_CONNECTED */
            case BLE_GAP_EVT_DISCONNECTED:
            {
                m_ble_clients[p_ble_evt->evt.gatts_evt.conn_handle].is_connected = 0;
            } break; /* BLE_GAP_EVT_DISCONNECTED */
    
            /* ... */
    
            default:
                break;
    
        }
    }
    

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

Children
Related