Most examples, tutorials, and standard BLE service implementations within the SDK (14.1.0) seem to use the BLE SoftDevice's sd_ble_gatts_characteristic_add()
when adding a characteristic to a service.
However, I noticed that there seems to be a slightly "higher" level API defined in the SDK,
ble_srv_comm.[h/c]
that allows the user to pass in a parameter structure and then, based on the parameters passed, it sets up and makes the call to the SoftDevice's sd_ble_gatts_characteristic_add()
.
/**@brief Function for adding a characteristic to a given service.
*
* If no pointer is given for the initial value,
* the initial length parameter will be ignored and the initial length will be 0.
*
* @param[in] service_handle Handle of the service to which the characteristic is to be added.
* @param[in] p_char_props Information needed to add the characteristic.
* @param[out] p_char_handle Handle of the added characteristic.
*
* @retval NRF_SUCCESS If the characteristic was added successfully. Otherwise, an error code is returned.
*/
uint32_t characteristic_add(uint16_t service_handle,
ble_add_char_params_t * p_char_props,
ble_gatts_char_handles_t * p_char_handle);
/**@brief Function for adding a characteristic's descriptor to a given characteristic.
*
* @param[in] char_handle Handle of the characteristic to which the descriptor is to be added, if @ref BLE_GATT_HANDLE_INVALID is used, it will be placed sequentially.
* @param[in] p_descr_props Information needed to add the descriptor.
* @param[out] p_descr_handle Handle of the added descriptor.
*
* @retval NRF_SUCCESS If the characteristic was added successfully. Otherwise, an error code is returned.
*/
uint32_t descriptor_add(uint16_t char_handle,
ble_add_descr_params_t * p_descr_props,
uint16_t * p_descr_handle);
I searched the 14.1.0 SDK and there appears to be a only a few services using this API, e.g., CGMS, OTS, LNS, and BMS.
I'm wondering whether the methods are stable and available for use when developing a custom service, or is the recommended best practice to follow more closely the tutorials, by invoking only the API defined the BLE SoftDevice's ble_gatts.h?
Thanks! Don