Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs
This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Advertising sevices SDK15.2 LBS and HRS advertising

Hello everyone!

I am trying unsuccessfully to advertise a custom UUID as LBS along whit HRS but the examples use different functions to handle the advertising.

The blink example use:

  • ble_uuid_t adv_uuids[] = {{LBS_UUID_SERVICE, m_lbs.uuid_type}}
  • ble_advdata_encode(&advdata, m_adv_data.adv_data.p_data, &m_adv_data.adv_data.len)
  • ble_advdata_encode(&srdata, m_adv_data.scan_rsp_data.p_data, &m_adv_data.scan_rsp_data.len)
  • sd_ble_gap_adv_set_configure(&m_adv_handle, &m_adv_data, &adv_params);
  • sd_ble_gap_adv_start(m_adv_handle, APP_BLE_CONN_CFG_TAG);

But the hrs example only use:

  • static ble_uuid_t m_adv_uuids[] ={{BLE_UUID_HEART_RATE_SERVICE, BLE_UUID_TYPE_BLE}};
  • ble_advertising_init(&m_advertising, &init);
  • ble_advertising_conn_cfg_tag_set(&m_advertising, APP_BLE_CONN_CFG_TAG);
  • ble_advertising_start(&m_advertising, BLE_ADV_MODE_FAST);

why are they using so different function How can I use those services at the same time? a tutorial somewhere maybe?

Tank you in advance!

Parents
  • Hi,

    The two methods are in essence doing the same things, namely populating the advertising and scan response data fields. But they have different features, in that the encode function can be used to create a payload for NFC message. The blink example does also use softdevice calls directly, I would rather recommend using the HRS method of using the API call ble_advertising_start().  You should integrate the two projects into the ble_template project.

    Best regards

    Jared 

  • Hi, thank you for your answer.

    I tried that, but doesn't work. I don’t complelly understand how it works because in one case the adv_uuid[] vector is created static as a global variable, in the other case it is declared in the function advertising_init(). When you try to add {LBS_UUID_SERVICE, m_lbs.uuid_type} to the global static declaration I get an error that said "the variable must be contsnt". In addition, I think that you can't mix custom uuid and generic services in the same vector. 

    static void advertising_init(void)
    {
        ret_code_t    err_code;
        ble_uuid_t m_adv_uuids[] = {
            {LBS_UUID_SERVICE, m_lbs.uuid_type},
            {BLE_UUID_HEART_RATE_SERVICE,        BLE_UUID_TYPE_BLE}
        };
    
        ble_advertising_init_t init;
    
        memset(&init, 0, sizeof(init));
    
        init.advdata.name_type               = BLE_ADVDATA_FULL_NAME;
        init.advdata.include_appearance      = true;
        init.advdata.flags                   = BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE;
        init.advdata.uuids_complete.uuid_cnt = sizeof(m_adv_uuids) / sizeof(m_adv_uuids[0]);
        init.advdata.uuids_complete.p_uuids  = m_adv_uuids;
    
        init.config.ble_adv_fast_enabled  = true;
        init.config.ble_adv_fast_interval = APP_ADV_INTERVAL;
        init.config.ble_adv_fast_timeout  = APP_ADV_DURATION;
    
        init.evt_handler = on_adv_evt;
    
        err_code = ble_advertising_init(&m_advertising, &init);
        APP_ERROR_CHECK(err_code);
    
        ble_advertising_conn_cfg_tag_set(&m_advertising, APP_BLE_CONN_CFG_TAG);
    
    }

Reply
  • Hi, thank you for your answer.

    I tried that, but doesn't work. I don’t complelly understand how it works because in one case the adv_uuid[] vector is created static as a global variable, in the other case it is declared in the function advertising_init(). When you try to add {LBS_UUID_SERVICE, m_lbs.uuid_type} to the global static declaration I get an error that said "the variable must be contsnt". In addition, I think that you can't mix custom uuid and generic services in the same vector. 

    static void advertising_init(void)
    {
        ret_code_t    err_code;
        ble_uuid_t m_adv_uuids[] = {
            {LBS_UUID_SERVICE, m_lbs.uuid_type},
            {BLE_UUID_HEART_RATE_SERVICE,        BLE_UUID_TYPE_BLE}
        };
    
        ble_advertising_init_t init;
    
        memset(&init, 0, sizeof(init));
    
        init.advdata.name_type               = BLE_ADVDATA_FULL_NAME;
        init.advdata.include_appearance      = true;
        init.advdata.flags                   = BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE;
        init.advdata.uuids_complete.uuid_cnt = sizeof(m_adv_uuids) / sizeof(m_adv_uuids[0]);
        init.advdata.uuids_complete.p_uuids  = m_adv_uuids;
    
        init.config.ble_adv_fast_enabled  = true;
        init.config.ble_adv_fast_interval = APP_ADV_INTERVAL;
        init.config.ble_adv_fast_timeout  = APP_ADV_DURATION;
    
        init.evt_handler = on_adv_evt;
    
        err_code = ble_advertising_init(&m_advertising, &init);
        APP_ERROR_CHECK(err_code);
    
        ble_advertising_conn_cfg_tag_set(&m_advertising, APP_BLE_CONN_CFG_TAG);
    
    }

Children
Related