This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

How do I create my own service on the BLE stack?

I've sifted through the examples given to me, and none of them seem to explain how to create your own service and add it to the stack. All of the services that are registered in the ble examples (nRF51 nordic pca10001) have their own header and c files.

Does anyone know how to create your own service, or at least know of any documentation that could point me in the right direction?

Thanks in advance!

  • Hi Alex

    A good place to start would be the ble_app_template example. I created one generic working service from there and used it to build multiple of my own services.

    Unfortunately you will not be able to move away from using .c and .h files to configure your services. If you look at figure 2 on page 7 of the softdevice specification, you will see that the setup of services and attributes is the responsibility of your app. Even though the Softdevice hosts the GAPP server, the configuration is up to the you. As far as adding your own service to the stack: This is not possible since the stack is a pre-compiled .hex file supplied by Nordic. You can simply send your setup and configuration at runtime to the stack to configure the GATT server.

    Hope this helps a bit

  • This is absolutely correct, and this is a base principle of BLE; all services and profiles are implemented in the application and not in the stack. This makes custom services much easier to create and use.

    Please also see these questions: http://devzone.nordicsemi.com/index.php/is-there-a-serial-port-profile-for-ble http://devzone.nordicsemi.com/index.php/what-is-the-most-efficient-way-to-transfer-data-over-ble

  • Hi there,

    If by "create your own service" you mean simply adding a service to the ATT table so it's visible to all GATT clients connecting to your application, then it's simply a matter of using the provided APIs:

    sd_ble_gatts_service_add sd_ble_gatts_include_add sd_ble_gatts_characteristic_add sd_ble_gatts_descriptor_add

    All those APIs can be used both with 16-bit UUIDs (for SIG approved services) and 128-bit UUIDs (if you are designing your own proprietary services).

    Carles

  • I've looked at the example, and it helps a lot, thanks! But the one part that I really needed help on it just tells me to fill in myself. The function, static void services_init(void) { // YOUR_JOB: Add code to initialize the services used by the application. }

    is the one that I have no idea how to do! This is where the other ble examples dive into their 20 file infrastructure that I can't quite follow. I just need to create one simple bare-bones service to get my foot in the door.

    Carles was nice enough to provide me with these functions:

    sd_ble_gatts_service_add sd_ble_gatts_include_add sd_ble_gatts_characteristic_add sd_ble_gatts_descriptor_add

    but I'm not sure how to use them.

    Do you know how to implement these?

    Thanks again!

  • To create a custom service, you should try to follow the general flow of the existing services, and mor or less copy them. The battery service (ble_bas.c/ble_bas.h) is probably the simplest one, and should provde a good starting point.

    If you look at it, you can see that the init function first adds a service, using the sd_ble_gatts_service_add() function, then calls an internal function to add a characteristic. This internal functions sets up a lot of parameter structures, that in different ways affect the characteristic added.

    Most services also needs to know what happens on run-time, so you need to create a event handler to handle events coming from the stack. This should be named service_name_on_ble_evt(), and be called from the applications main.c-file's ble_evt_dispatch() method.

    Finally, most services also need some API function to actually do something useful, for example the battery service's method to update the measured battery value.

Related