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

Enabling multiple different services to run together in nrf52832

Hello,

I followed the following tutorial to create my own service and characteristics. 

Now, I want to combine this custom service with the UART service so that I can run both my service and the UART Service together at the same time. Is that possible to do? I have combined the code for the custom service with the ble_app_uart example (under peripheral) and tried doing many things, but right now I am only able to advertise the UART service and nothing seems to happen for my custom service.

Any help or guidance will be helpful. I am using the S132 softdevice, and SDK 17.0.2

Thanks,

Ananye

  • Hi,

     

    Is that possible to do?

     Yes! Many of our examples in the SDK has multiple services, see the services_init() in the ble_app_hrs example for instance. It shows you how to setup multiple services.

    regards

    Jared 

  • Hi,

    Thank you for your reply. I am a little confused about services that work with vendor specific UUIDs versus those that don't. In the ble_app_hrs example, the different services only use a 16 bit UUID and when the services are initialized, the function sd_ble_gatts_service_add() is called.

    However, in the ble_app_uart example for the UART service, we use a 128 bit base UUID and we first call the sd_ble_uuid_vs_add() function and then the sd_ble_gatts_service_add() .

    So, whats the difference and importance of these different approaches to add a service. Is it not better to just use a 16bit UUID each time to save on memory?

    Thanks,

    Ananye

  • Hi.

    In short, a 16 bit UUID is used when you make a service that is one of the Bluetooth SIG pre-defined services. The service that you make has to then follow the GATT specification for the service.

    A 128 bit UUID is used when you make a service that is not one of Bluetooth SIG pre-defined services. The Nordic UART Service is not a pre-defined service but rather a custom service made by Nordic Semiconductor. 

    The difference between the two UUIDs is summarized in the Service tutorial:

    A UUID is an abbreviation you will see a lot in the BLE world. It is a unique number used to identify services, characteristics and descriptors, also known as attributes. These IDs are transmitted over the air so that e.g. a peripheral can inform a central what services it provides. To save transmitting air time and memory space in your nRF52 there are two kinds of UUIDs:

    The first type is a short 16-bit UUID. The predefined Heart rate service, e.g., has the UUID 0x180D and one of its enclosed characteristics, the Heart Rate Measurement characteristic, has the UUID 0x2A37. The 16-bit UUID is energy and memory efficient, but since it only provides a relatively limited number of unique IDs there is a rule; you can only transmit the predefined Bluetooth SIG UUIDs directly over the air. Hence there is a need for a second type of UUID so you can transmit your own custom UUIDs as well.

    The second type is a 128-bit UUID, sometimes referred to as a vendor specific UUID. This is the type of UUID you need to use when you are making your own custom services and characteristics. It looks something like this: 4A98xxxx-1CC4-E7C1-C757-F1267DD021E8 and is called the “base UUID”. The four x’s represent a field where you will insert your own 16-bit IDs for your custom services and characteristics and use them just like a predefined UUID. This way you can store the base UUID once in memory, forget about it, and work with 16-bit IDs as normal. 

  • Hi Jared,

    I cracked the methodology of how-to setup multiple service; However, I am not able to understand that how to switch from one service to another? For example, I want to add BLE keyboard service into customize code which has functionality of BLE MIDI service and i require to switch BLE keyboard service to BLE MIDI service to run one service at a time. How this can be done? 

Related