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

Question about creating new service following Github instruction

Hello all,

I'm practicing creating my own service following instruction from this link: https://github.com/bjornspockeli/custom_ble_service_example

Now I stuck at part 7 and there are several question flying around my head, so could anyone help me explain my questions?

1. What is "Propagating Custom Service events to the application"? What is the "application" mean? Why not propagating event from SD to application as normal? Cause I see in the instruction he created 2 on connect and on disconnect event for his service which can be handled by SoftDevice as in previous part of the instruction. He also created a notification event in his service, why he created this event, is this because the SD does not support this event? The main issue here is that I can't understand why he replaced the event handled by SD with his own

2. The Client Characteristic Configuration line in nrf Connect only appear after I finish part 8, is this because we add an option to turn of or off notification for the characteristic?

I have found a question same with mine in our forum, but the explanation is quite hard for a newbie and also a non-english speaker as me to understand.I would really appreciate if anyone can give me a easy-to-understand explanation

Thankyou so much!

  • Hi,

    1. What is "Propagating Custom Service events to the application"?

    An event can be generated from different sources.  Events from the SoftDevice are propagated to the application by software triggered interrupts. The application is then responsible for handling the interrupt and for invoking the relevant SoftDevice functions to obtain the event data. So all SoftDevice events needs to be taken care by the application side (your code).


    The ble_cus_on_ble_evt() in ble_cus.c handles the events propagated by the softdevice (ble_evt_t type events). It checks which event has been propagated to the application and handles for example what the service should do in case of a softdevice connected event (BLE_GAP_EVT_CONNECTED ) or a disconnected event (BLE_GAP_EVT_DISCONNECTED).

    This events are also handled locally in other parts of the code, just search for BLE_GAP_EVT_CONNECTED throught your project and you will see local handlers in ble_advertising.c (ble_advertising_on_ble_evt()), ble_conn_params.c, etc..

    And then we have event types specifics to a service, in our case we defined BLE_CUS_EVT_DISCONNECTED and BLE_CUS_EVT_CONNECTED. These are then propagated from the service to the application, by having the service call a event handler defined in main.c, in our case this handler is called on_cus_evt().

    Another nordic example generating events from a custom service is the ble_app_uart, in ble_nus.h line 111 the events specific to the "Nordic UART service" (which is a custom service) are listed. If you take a look at the ble_nus.c you will see that the BLE_NUS_EVT_RX_DATA is generated by the service function on_write(), which is called upon a BLE_GATTS_EVT_WRITE (softdevice event). BLE_NUS_EVT_RX_DATA is then handle in main by the function nus_data_handler, which will process the data received from the nordic uart ble service and send it to the uart module. 

    You can also see this answer to understand the signal path for a BLE_GATTS_EVT_WRITE event in the ble_custom_service tutorial.

    2. The Client Characteristic Configuration line in nrf Connect only appear after I finish part 8, is this because we add an option to turn of or off notification for the characteristic?

    Yes. This descriptor will be added for any characteristic that has either the notify or the indicate properties. But you still need to setup the metadata of the descriptor, for example set the read and write permissions, where the value of the CCCD will be store, etc.

    I hope this answers your questions. Have a good day.

    Best Regards,

    Marjeris

Related