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

Characteristic's base UUID different from Service's base UUID

Dear all

I have a service with an UUID. Let's say 11111111-2222-3333-4444-555555555555

I also have two characteristics that belong to this service:

66666666-7777-8888-9999-AAAAAAAAAAAA

66666666-7777-8888-9999-AAAAAAAAAAAB

I know that this is not the canonical form of a service and charachteristics. My question is: can I implement it on a nRF52 with S132?

To add charachteristics I have to use sd_ble_gatts_characteristic_add, that takes as an argument a ble_gatts_attr_t. This structure contains a ble_uuid_t, where only 16 bits of UUID can be defined. So I assume that the base UUID for the characteristic is read from the service hande passed to sd_ble_gatts_characteristic_add. Is this correct?

Is there a way to implement this service with said characteristics?

Kind regards, E:P

  • Adding UUID bases with sd_ble_uuid_vs_add return an unique uuid_type for each custom UUID and yes, it is used with sd_ble_gatts_characteristic_add, passed in p_attr_char_value. All you need to do is add a new UUID base for each of your characteristics since you're changing the base part.

    So for your example the following snipped should illustrate how to do it the SD way:

    ble_uuid_t uuidA = { .uuid = 0x6666 };
    ble_uuid128_t uuidA_base = { 0xAA, 0xAA, 0xAA, 0xAA, 
    										0xAA, 0xAA, 0x99, 0x99, 
    										0x88, 0x88, 0x77, 0x77, 
    										0x00, 0x00, 0x66, 0x66 };
    sd_ble_uuid_vs_add(&uuidA_base, &uuidA.type);
    // uuidA is now 66666666-7777-8888-9999-AAAAAAAAAAAA
    
    ble_uuid_t uuidB = { .uuid = 0x6666 };
    ble_uuid128_t uuidB_base = { 0xAB, 0xAA, 0xAA, 0xAA, 
    										0xAA, 0xAA, 0x99, 0x99, 
    										0x88, 0x88, 0x77, 0x77, 
    										0x00, 0x00, 0x66, 0x66 };
    sd_ble_uuid_vs_add(&uuidB_base, &uuidB.type);
    // uuidB is now 66666666-7777-8888-9999-AAAAAAAAAAAB
    
    ...
    ble_gatts_attr_t uuidA_gatts_attr;
    ...
    ble_gatts_attr_t uuidB_gatts_attr;
    ...
    uuidA_gatts_attr.p_uuid = &uuidA;
    ....
    uuidB_gatts_attr.p_uuid = &uuidB;
    ...
    sd_ble_gatts_characteristics_add(x, y, &uuidA_gatts_attr, z);
    sd_ble_gatts_characteristics_add(x, y, &uuidB_gatts_attr, z);
    
  • Is this for Server side or do we need to do this "trick" also for Client side (Central) before discovering services and characteristics form Peripheral/Server ?

Related