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

SDK 14 - How to set up a BLE Observer for custom service

NRF52DK (PCA10040) - SDK14 - Arm GCC (using Eclipse) - S132 5.0.0 Soft Device

I had a custom service set up in SDK13 using the tutorial here.

I am migrating my project to SDK14. I have everything else completely working except the BLE service. I can see the custom service and characteristics associated with it fine. I can make changes to the values of the characteristics but they are not getting passed to the "on_write" function of my custom service like it did before with SDK13. Also not working are any changes made on the board that were sent via BLE to the characteristics in my custom service (using the our_xxxxxx_characteristic_update function in my custom service per the tutorial).

I believe it is because the new SoftDevice handler implementation. Before I had the following code under -

static void ble_evt_dispatch(ble_evt_t * p_ble_evt)

ble_conn_state_on_ble_evt(p_ble_evt);
pm_on_ble_evt(p_ble_evt);
ble_conn_params_on_ble_evt(p_ble_evt);
on_ble_evt(p_ble_evt);
ble_advertising_on_ble_evt(p_ble_evt);
nrf_ble_gatt_on_ble_evt(&m_gatt, p_ble_evt);
ble_our_service_on_ble_evt(&m_our_service, p_ble_evt);

The last one was for my custom service.

That code is not in my current program on SDK 14 because I know that it has changed per the SDK migration document. The new way is to use BLE stack event observers. I am confused on how to implement the new BLE stack event observers with my custom service.

I am building off of the peripheral, ble_app_hrs example. There is code in there under ble_stack_init that says:

// Register a handler for BLE events.
NRF_SDH_BLE_OBSERVER(m_ble_observer, APP_BLE_OBSERVER_PRIO, ble_evt_handler, NULL);

What do I need to do to get my custom service "handled" in this new SDK?

I am sure I am missing something seemingly simple but any help would be greatly appreciated!

Related