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.

  • Hi,

    The function sd_ble_uuid_vs_add() is described in the infocenter. The UUIDs in the stack is not put into the advertising data by default, you have to add it yourself.

    If you application advertise the LBS UUID and you are using one of the examples from the SDK (ble_app_blinky?), it is most likely added to the advertising data in advertising_init() function. You can have a look at the ble_app_uart example, as this shows how to advertise a custom UUID.

    If you connect to your peripheral and perform a service discovery, do you see your custom service?

    Best regards,

    Jørgen

  • Thank you very much for your reply. In "advertising_init" function, I can make custom advertising data as below.

    static void advertising_init(void) { uint32_t err_code; ble_advdata_t advdata; ble_advdata_t scanrsp;

    // Build advertising data struct to pass into @ref ble_advertising_init.
    memset(&advdata, 0, sizeof(advdata));
    advdata.name_type          = BLE_ADVDATA_NO_NAME;
    advdata.include_appearance = false;
    advdata.flags              = BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE;
    advdata.uuids_complete.uuid_cnt = sizeof(m_adv_uuids) / sizeof(m_adv_uuids[0]);
    advdata.uuids_complete.p_uuids  = m_adv_uuids;
    

    ...... }

    In advdata structure, I can't see "Complete list of 128-bit UUIDs available". I think "advdata.uuids_complete" supports just 16-bit UUID. How can I send "Complete list of 128-bit UUIDs" in advertising data?

    I need your help.

  • The advdata struct can take 128-bit UUIDs, you just needs to specify the correct UUID type. You should use the type BLE_UUID_TYPE_VENDOR_BEGIN for 128-bit UUIDs.

    This is how a 128-bit UUID is added to the scan response package in the ble_app_uart example:

    #define NUS_SERVICE_UUID_TYPE           BLE_UUID_TYPE_VENDOR_BEGIN  
    static ble_uuid_t                       m_adv_uuids[] = {{BLE_UUID_NUS_SERVICE, NUS_SERVICE_UUID_TYPE}};
    

    And in advertising_init():

    scanrsp.uuids_complete.uuid_cnt = sizeof(m_adv_uuids) / sizeof(m_adv_uuids[0]);
    scanrsp.uuids_complete.p_uuids  = m_adv_uuids;
    
  • How can it be 128bit? BLE_UUID_NUS_SERVICE is 16bit as below.

    #define BLE_UUID_NUS_SERVICE 0x0001
    

    I still need your help.

  • The Nordic UART Service is a 128-bit vendor-specific UUID, as described in example documentation in the infocenter. The base UUID, NUS_BASE_UUID, is defined in ble_nus.c. This is added to the stack in services_init() with a call to sd_ble_uuid_vs_add(). When the UUID is added to the advertising data, the NUS_SERVICE_UUID_TYPE is used to get the base UUID from the stack.

Related