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

ADD UUID 128 custom service to advertising packet

Hi all,

is there an example to add the uuid 128 of a custom service on advertising data?

  • If you want you can use this one.

    drive.google.com/open

    Its an example I made which is based on the ble_app_template (SDK12.2) If you are on CodeLimitation just disable LRF_LOG in the config. If you only fokus on the advertising part it should be fine. I build this out of the template and the blinky app from their github

    If your code uses ble_advertising_init basically all you have to do is to add your service to the second parameter. If you get Error 0x07 it is often the case that you want to initialize advertising before the services are initialized. You have to change the order in the main of the ble_app_template from advertising_init(); services_init(); to services_init(); advertising_init(); Hope that helps you a little bit

    uint32_t               err_code;
    ble_advdata_t          advdata;
    ble_adv_modes_config_t options;
    
    // Build advertising data struct to pass into @ref ble_advertising_init.
    memset(&advdata, 0, sizeof(advdata));
    
    advdata.name_type               = BLE_ADVDATA_FULL_NAME;
    advdata.include_appearance      = true;
    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;
    
    memset(&options, 0, sizeof(options));
    options.ble_adv_fast_enabled  = true;
    options.ble_adv_fast_interval = APP_ADV_INTERVAL;
    options.ble_adv_fast_timeout  = APP_ADV_TIMEOUT_IN_SECONDS;
    
    ble_uuid_t adv_uuids[] = {{LUXS_UUID_SERVICE, m_luxs.uuid_type}};
    
    ble_advdata_t srdata;
    memset(&srdata, 0, sizeof(srdata));
    srdata.uuids_complete.uuid_cnt = sizeof(adv_uuids) / sizeof(adv_uuids[0]);
    srdata.uuids_complete.p_uuids = adv_uuids;
    
    err_code = ble_advertising_init(&advdata, &srdata, &options, on_adv_evt, NULL);
    NRF_LOG_ERROR("%d\r\n", err_code);
    APP_ERROR_CHECK(err_code);
    
  • Mmmhh.

    i use a ble devloper studio and uuid of my service created is:

     ble_uuid128_t bds_base_uuid = {{0xB6, 0x9D, 0x21, 0x57, 0xA7, 0xA3, 0xFA, 0xA0, 0x97, 0x4A, 0x72, 0xA7, 0x00, 0x00, 0x20, 0xF3}};
    

    But i don't understand how pass this value to advdata.uuids_complete.p_uuids =

  • I'm sorry unfortunately can't help you with that. I just did it the way Nordic did it in the examples. Maybe you can post your code / find out what error you get from the return of ble_advertising_init.

  • Hi,

    The BLE UART example shows how to add a custom UUID to the scan response data. You can also find a detailed explanation of how you do this in the BLE Services, a beginner's tutorial. Note that you can add it to the advertising data if you have enough available space, but the maximum payload of one advertising packet is 27 bytes.

    Best regards,

    Jørgen

  • Hi jorgen,

    thanks for the answer. i see the uart example, it's very simple.

    static ble_uuid_t                       m_adv_uuids[] = {{BLE_UUID_NUS_SERVICE, NUS_SERVICE_UUID_TYPE}};  
    
    /**< Universally unique service identifier. */
    
    /**@brief Function for initializing the Advertising functionality.
     */
    
    static void advertising_init(void)
    {
        uint32_t               err_code;
        ble_advdata_t          advdata;
        ble_advdata_t          scanrsp;
        ble_adv_modes_config_t options;
    
    // Build advertising data struct to pass into @ref ble_advertising_init.
    memset(&advdata, 0, sizeof(advdata));
    advdata.name_type          = BLE_ADVDATA_FULL_NAME;
    advdata.include_appearance = false;
    advdata.flags              = BLE_GAP_ADV_FLAGS_LE_ONLY_LIMITED_DISC_MODE;
    
    memset(&scanrsp, 0, sizeof(scanrsp));
    scanrsp.uuids_complete.uuid_cnt = sizeof(m_adv_uuids) / sizeof(m_adv_uuids[0]);
    scanrsp.uuids_complete.p_uuids  = m_adv_uuids;
    
    memset(&options, 0, sizeof(options));
    options.ble_adv_fast_enabled  = true;
    options.ble_adv_fast_interval = APP_ADV_INTERVAL;
    options.ble_adv_fast_timeout  = APP_ADV_TIMEOUT_IN_SECONDS;
    
    err_code = ble_advertising_init(&advdata, &scanrsp, &options, on_adv_evt, NULL);
    APP_ERROR_CHECK(err_code);
    

    }

    my problem is the define of BLE_UUID_NUS_SERVICE is not simple 0xXXXX but it's somethink like that

    ble_uuid128_t bds_base_uuid = {{0xB6, 0x9D, 0x21, 0x57, 0xA7, 0xA3, 0xFA, 0xA0, 0x97, 0x4A, 0x72, 0xA7, 0x00, 0x00, 0x20, 0xF3}};
    

    and i don't know how meange it

Related