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

How do I add 2nd base UUID for Service and Characteristic?

Hello, i try to get a service with base_uuid1 and to this service a characteristic with the base_uuid2. I am trying to implement BLE MIDI, the BLE_MIDI Specs:

  1. BLE Service and Characteristics Definitions The following service and characteristic are defined:
  • MIDI Service (UUID: 03B80E5A-EDE8-4B33-A751-6CE34EC4C700)
  • MIDI Data I/O Characteristic (UUID: 7772E5DB-3868-4112-A1A9-F2669D106BF3)

I did the tutorials and created my service ID like the MIDI SERVICE UUID from the specs. The Characteristic tutorial just let me add a custom 16bit UUID but i need to change the complete base_uuid. But when i am changing the base_uuid in the our_service.c the nrf52 DK is not advertising anymore and all four leds light up.

This is from the our_service.h

// FROM_SERVICE_TUTORIAL: Defining 16-bit service and 128-bit base UUIDs
#define BLE_UUID_OUR_BASE_UUID              {{0x00, 0xC7, 0xC4, 0x4E, 0xE3, 0x6C, 0x51, 0xA7, 0x33, 0x4B, 0xE8, 0xED, 0x5A, 0x0E, 0xB8, 0x03}} // 128-bit base UUID
#define BLE_UUID_OUR_SERVICE_UUID                0x0E5A // Just a random, but recognizable value

// ALREADY_DONE_FOR_YOU: Defining 16-bit characteristic UUID
#define BLE_UUID_OUR_BASE_CHAR_UUID              {{0xF3, 0x6B, 0x10, 0x9D, 0x66, 0xF2, 0xA9, 0xA1, 0x12, 0x41, 0x68, 0x38, 0xDB, 0xE5, 0x72, 0x77}} // 128-bit base UUID
#define BLE_UUID_OUR_CHARACTERISTC_UUID          0xE5DB 

from the our_service.h

static uint32_t our_char_add(ble_os_t * p_our_service)
{
    uint32_t   err_code = 0; // Variable to hold return codes from library and softdevice functions
 
    // OUR_JOB: Step 2.A, Add a custom characteristic UUID
    ble_uuid_t          char_uuid;
    ble_uuid128_t       base_uuid = BLE_UUID_OUR_BASE_CHAR_UUID;
    char_uuid.uuid      = BLE_UUID_OUR_CHARACTERISTC_UUID;

																		
	sd_ble_uuid_vs_add(&base_uuid, &char_uuid.type);
    APP_ERROR_CHECK(err_code);

...

err_code = sd_ble_gatts_characteristic_add(p_our_service->service_handle,
                                   &char_md,
                                   &attr_char_value,
                                   &p_our_service->char_handles);
APP_ERROR_CHECK(err_code);

return NRF_SUCCESS;
}

And i Didint do anything to the our_service_init().

I hope someone can help my i am a little confused and new working with the nrf. Thank you. I probably forgot the most things so please ask.

Parents
  • All good found my problem.

    To use two or more vendor specific UUIDs you will need to define how many such UUIDs you need. In the typical SDK example (and in the tutorial code) you do this in the function ble_stack_init() found in main.c. Add the line

    ble_enable_params.common_enable_params.vs_uuid_count = 2;

    and you should be able to use two vs UUIDs.

  • I'm been awarded the Necromancer badge by this site for replying to a post after 3 months.... but this is close... so here goes.

    This is just what I need, though I can't quite put it together.

    I have seen and set the value in sdk_config.h as follows,

    // <o> NRF_SDH_BLE_VS_UUID_COUNT - The number of vendor-specific UUIDs. 
    #ifndef NRF_SDH_BLE_VS_UUID_COUNT
    #define NRF_SDH_BLE_VS_UUID_COUNT 2 //<-- changed from 1 to 2 to allow custom 128 bit UUID for both Service and Attribute
    #endif

    I would (naively) expect this would have the same effect as the code you mention, @niklasjacob_2611.

    I've also tried playing with this at the top of main.c in many example files:

    // YOUR_JOB: Use UUIDs for service(s) used in your application.
    static ble_uuid_t m_adv_uuids[] =                                               /**< Universally unique service identifiers. */
    {
        {BLE_UUID_MIDI_SERVICE, BLE_UUID_TYPE_VENDOR_BEGIN}
        ,    {BLE_UUID_MIDI_CHARACTERISTIC, BLE_UUID_TYPE_VENDOR_BEGIN} //<-- I added this
    };
    

    I'd welcome a reference to an example app that uses two 128-bit UUIDs.

    Apples (MIDI.org documented) MIDI over BLE spec appears to require advertising both 128 bit UUIDs for an app like GarageBand to recognize the peripheral.

    Thanks

  • :  You will not be able to fit two 128-bit UUIDs inside a 31-byte advertisement packet. You'll need to put the second UUID in a scan response packet. Which SDK version are you using? Once I know which version you're using I can start setting up an example for you.

Reply Children
Related