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 to set Service UUID for central and peripheral

Hi. I'm using nRF51822AC, SDK12.2.0, S130 as central and peripheral.

Q1. What's "sd_ble_uuid_vs_add" function? is it for setting service UUID? Q2. If Q1 yes, how to change service uuid?

for example) I want to set service uuid as below.

For central : #define LBS_UUID_BASE {0x23, 0xD1, 0xBC, 0xEA, 0x5F, 0x78, 0x23, 0x15,
0xDE, 0xEF, 0x12, 0x12, 0x00, 0x00, 0x00, 0x00}

For periphral : #define p_BASE_UUID {0x00, 0x00, 0x00, 0x30, 0x52, 0xD0, 0x00, 0x00, 0, 1, 2, 3, 4, 5, 6, 7}

and I made source code as below. ......

ble_uuid128_t lbs_base_uuid = {LBS_UUID_BASE};

err_code = sd_ble_uuid_vs_add(&lbs_base_uuid, &p_ble_lbs_c->uuid_type);
if (err_code != NRF_SUCCESS)
{
    return err_code;
}
VERIFY_SUCCESS(err_code);

......

ble_uuid128_t p_base_uuid = p_BASE_UUID;
err_code = sd_ble_uuid_vs_add(&p_base_uuid, &p_m_p->uuid_type);
if (err_code != NRF_SUCCESS)
{
    return err_code;
}
VERIFY_SUCCESS(err_code);

But it's service UUID in advertising data is LBS_UUID_BASE.

How can I set p_BASE_UUID in advertising data?

I need your help.

  • If i want to use 2 different Base UUID, how can I change them? I want to change them whenever I want.

    I need your help.

  • You need to add the base UUID to the stack using sd_ble_uuid_vs_add(). This function is described in this answer. You then need to add the characteristics to the GATT table with the new base UUID. Why do you want to change the base UUID outside initialization?

  • I want to use nRF51822 as Central and Peripheral as well. Please refer to my question at the top. I made init code for Central using "lbs_base_uuid" and then made init code for Peripheral using "p_base_uuid". Central function is working well, but Peripheral is not working well. I'm sure that I added all the code what you let me know. But it still advertises "lbs_base_uuid" not "p_base_uuid". When I remove Central init code, it advertises "p_base_uuid". I don't know why does it advertise central UUID? That's what i'm asking.

    I need your help.

  • If you add multiple BASE_UUIDs to the stack using sd_ble_uuid_vs_add(), you have to set the UUID type to the correct number.

    In ble_app_uart example, the UUID type is set to BLE_UUID_TYPE_VENDOR_BEGIN, as there is only one vendor specific base UUID added to the stack. If you add multiple base UUIDs, you will have to set the UUID type in the order the base UUIDs are added to the stack:

    If you have two vendor specific services that you want to advertise, defined like this:

    #define NUS_BASE_UUID					{{0x9E, 0xCA, 0xDC, 0x24, 0x0E, 0xE5, 0xA9, 0xE0, 0x93, 0xF3, 0xA3, 0xB5, 0x00, 0x00, 0x40, 0x6E}}
    #define LBS_UUID_BASE        			{{0x23, 0xD1, 0xBC, 0xEA, 0x5F, 0x78, 0x23, 0x15, 0xDE, 0xEF, 0x12, 0x12, 0x00, 0x00, 0x00, 0x00}}
    
    #define BLE_UUID_NUS_SERVICE 			0x0001
    #define LBS_UUID_SERVICE				0x1523
    

    Your UUID types should be:

    #define NUS_SERVICE_UUID_TYPE      		BLE_UUID_TYPE_VENDOR_BEGIN
    #define LBS_SERVICE_UUID_TYPE			BLE_UUID_TYPE_VENDOR_BEGIN + 1
    

    And you should add the base UUIDs to the stack in this order:

    sd_ble_uuid_vs_add(NUS_BASE_UUID)
    sd_ble_uuid_vs_add(LBS_UUID_BASE)
    

    You can then add the two UUIDs, with different base UUIDs, to the advertising/scan response packet:

    static ble_uuid_t                       m_adv_uuids[] = {{BLE_UUID_NUS_SERVICE, NUS_SERVICE_UUID_TYPE},{LBS_UUID_SERVICE, LBS_SERVICE_UUID_TYPE}};
    
    advdata.uuids_more_available.uuid_cnt = 1;
    advdata.uuids_more_available.p_uuids  = &m_adv_uuids[0];
    
    scanrsp.uuids_more_available.uuid_cnt = 1;
    scanrsp.uuids_more_available.p_uuids  = &m_adv_uuids[1];
    
  • Thank you so much for your help. It's very helpful. I solved it with your answer.

Related