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

Multilink Peripheral BLE Services

Hello,

for multilink client services Nordic introduced the *_EVT_DISCOVERY_COMPLETE events and the *_c_handles_assign functions. Like the BLE_BAS_C_EVT_DISCOVERY_COMPLETE event and the ble_bas_c_handles_assign function for the Batterie Client Service

What is the procedure for multilink server services like the Batterie Server Service? How can I instantiate this service multiple times i.e. one for each possible connection? At the moment the service captures the connection handle

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

So that even when I instantiate the service several times, they all capture the last connection handle. This has the consequence, that when I call ble_bas_battery_level_update only the last connected device received the notification. I have no choice to select a specific device.

For the LED Button Service Server Nordic the "button change" function has an explicit conn_handle argument to select the client.

uint32_t ble_lbs_on_button_change(uint16_t conn_handle, ble_lbs_t * p_lbs, uint8_t button_state);

How can I use the Nordic server services like the Batterie Service with multiple clients?

Parents
  • The battery service module doesn't really support multiple instances, so the library has to be modified. The first step would be to add something like this:

    /** @brief Macro for defining multiple ble_bas instances.
     *
     * @param   _name   Name of the array of instances.
     * @param   _cnt    Number of instances to define.
     */
    #define BLE_BAS_ARRAY_DEF(_name, _cnt)                                                            \
    static ble_bas_t _name[_cnt];                                                                     \
    NRF_SDH_BLE_OBSERVERS(_name ## _obs,                                                                \
                          BLE_BAS_BLE_OBSERVER_PRIO,                                                  \
                          ble_bas_on_ble_evt, &_name, _cnt)
    

    And declare the number of instances you want. I haven't look further into the library to see what other changes are necessary. Let me know if you get into trouble.

  • Thank you for the answer. Do you know if Nordic plans to modify (all) the provided services to support multiple instances in the future?

Reply Children
No Data
Related