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

Custom BLE Service Help

Hello,

I am really confused on how to get a custom BLE service up and running. I have read through nAN-36, and compared the suggestions in that document to the HRS example provided. It seems like the code in nAN-36 is missing a lot of the code provided in the HRS example as far as initialization of advdata and m_adv_params. Do you have an example that provides a more detailed set of code that outlines how to make a custom BLE service?

I just need to create a service that sends 3 characteristics (all uint32_t).

Lucas

  • Hi Lucas, totally agree that the instruction in the application note is a little less descriptive. I had to go through it several times to create a custom service of my own. In order to create a service, basically, u need to have 2 basic structures (one is for init, the other one for storing necessery info about the service itself). Take battery service (ble_bas) as an example. We have ble_bas_s for the service itself and ble_bas_init_t for passing initialization info to the custom service.

    Then you will need to create an init func in which you will add your custom characteristics (look at ble_bas_init function in ble_bas.c). In your case, you will need to add 3 characteristics. In order to to add characteristic, you will need ble_gatts_char_md_t (for characteristic metadata), ble_gatts_attr_t (for characteristic value, UUID, etc...) and ble_gatts_attr_md_t (for setting access permission to characteristic). Additionally, you need to set up and 'send' function in your custom service as well. This will take care of sending characteristic data to peripheral device (take a look at ble_hrs_heart_rate_measurement_send in ble_hrs.c for reference).

    Considerting initialization of advdata, the template ble_app_template mentioned in the AN already did the basic initialization. you can play with the config if you want to.

    This will probably take some time to understand all the logics of the code. So be patient :)

Related