Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs
This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

How to use ble_hids with multiple peripherals

I'm trying to create a HID bluetooth device with multiple connections to centrals. Looking at the ble_hids service implementation, the on_connect event handler sets the connection handle of a new connection on the hids instance. How can I associate one hids service with one connection?

static void on_connect(ble_hids_t * p_hids, ble_evt_t const * p_ble_evt)
{
// ...
p_hids->conn_handle = p_ble_evt->evt.gap_evt.conn_handle;
// ...
}

Parents
  • Hi,

    I'm not quite sure if I understand your problem. In Nordic's Softdevices you cannot have more than one GATT database, so associating one instance of a service to just one connection doesn't quite make sense to me. You can have two services of the same type in your database though, and map them to two different links. Then you can declare two p_hids variables, p_hids_1 and p_hids_2, and have some logic in on_connect() that associates the instances with different links. 

  • Ok, I'm quite new so please forgive any misunderstanding.

    Really I'd like one hids that works with multiple clients, but as the hids implementation only stores one connection handle I'm not sure that's possible without modifying it or having multiple instances, is that correct? Which of those options would you recommend?

    If I should use multiple instances, am I correct in thinking I should call ble_hids_on_ble_evt manually instead of registering the service for notifications with NRF_SDH_BLE_OBSERVER?

  • No worries. 

    So the one peripheral will send the exact same data to multiple peripherals? Then instead of changing the hids service structure I would rather change the functions that transmit the data you need. Take the function ble_hids_inp_rep_send() in ble_hids.c for example. It takes a hids service structure as parameter and uses p_hids->conn_handle when sending notifications with sd_ble_gatts_hvx(). If you change the function signature for ble_hids_inp_rep_send() to accept the connection handle directly you could just call the function multiple times, but pass different connection handles to it. You can store all your connection handles in an array and iterate through that in a for loop to transmit data to all connections:

    for(number of active connections)
    {
        ble_hids_inp_rep_send(conn_handle, ...)
    }

    You can also possibly get some inspiration from the BLE Multiperipheral Application example.

  • Ok great. Is it OK to copy and modify the standard ble_hids.c/.h from the SDK? In the header it says:

    To maintain compliance with Nordic Semiconductor ASA Bluetooth profile
    qualification listings, this section of source code must not be modified.

    By changing the implementation do I lose qualification?

    Will you be updating the services in the SDK to support multiple peripherals by default in the future?

  • Hi Martin, could you help with these last questions? Many thanks

Reply Children
No Data
Related