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

ble_advertising_advdata_update

Hi All. 

I am trying to use the "ble_advertising_advdata_update" function, but my compiler is giving me the following error. Which class do I need to add?

undefined reference to `ble_advertising_advdata_update


I am using SDK nRF5_SDK_15.0.0_a53641a. Advertising works ok after initialisation, but I am trying to update the manufacturer data whilst advertising.

Thanks

void advertising_update(void)
{
    ret_code_t err_code;
    uint8_t testData[8] = {0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x11, 0x22};

    ble_gap_adv_data_t adv_data2 = {
        .adv_data.p_data = testData,
        .adv_data.len = 0x08,
        .scan_rsp_data.p_data = testData,
        .scan_rsp_data.len = 0//sizeof(raw_scan_rsp_data_buffer2)
    };

    err_code = ble_advertising_advdata_update(&m_advertising, &adv_data2, true);
    APP_ERROR_CHECK(err_code);
}

  • OK - thanks.

    ble_advertising_advdata_update() looks pretty pointless as a user API call, since it requires you to supply formatted data to it in the Advertising module's internal format!!

    I also added a comment in the thread you referenced - as the code seems to rely upon an undocumented call & Magic Numbers

    https://devzone.nordicsemi.com/f/nordic-q-a/38056/advertising-data-update-nrf_error_invalid_addr/183210#183210

    In my case, the data is not changing rapidly (many minutes) so I can just let the advertising time out, then repeat the advertising_init() and advertising_start() ...

  • Basically you stop the advertising, then call a second version of your advertising_init() function but update whatever manufacturing data you want to in there.

    Then start advertising again. In our application we do this at about once per second with no problems.

    Not very efficient, but works for us. I spent ages on the ble_advertising_advdata_update() so wasn't worth spending more time on.

    sd_ble_gap_adv_stop(m_advertising.adv_handle);
    advertising_init2();
    uint32_t err_code = ble_advertising_start(&m_advertising, BLE_ADV_MODE_FAST);
    APP_ERROR_CHECK(err_code);

  • stop the advertising, then call a second version of your advertising_init() function but update whatever manufacturing data you want

    Yes - that's effectively what I did:

    let the advertising time out, then repeat the advertising_init() and advertising_start()
  • You don't need to re-initialize.  Try this snippet code from the EHAL library 

    void BleAppAdvManDataSet(uint8_t *pAdvData, int AdvLen, uint8_t *pSrData, int SrLen)
    {
    	uint32_t err;
    
    	if (pAdvData && AdvLen > 0)
    	{
    		int l = min(AdvLen, BLE_GAP_ADV_SET_DATA_SIZE_MAX);
    
    		memcpy(g_BleAppData.ManufData.data.p_data, pAdvData, l);
    
    		g_BleAppData.ManufData.data.size = l;
            g_AdvInstance.adv_data.adv_data.len = BLE_GAP_ADV_SET_DATA_SIZE_MAX;
    
            err = ble_advdata_encode(&g_BleAppData.AdvData, g_AdvInstance.adv_data.adv_data.p_data, &g_AdvInstance.adv_data.adv_data.len);
    		APP_ERROR_CHECK(err);
    
    	}
    
    	if (pSrData && SrLen > 0)
    	{
    		int l = min(SrLen, BLE_GAP_ADV_SET_DATA_SIZE_MAX);
    
    		memcpy(g_BleAppData.SRManufData.data.p_data, pSrData, l);
    
    		g_BleAppData.SRManufData.data.size = l;
    		g_AdvInstance.adv_data.scan_rsp_data.len = BLE_GAP_ADV_SET_DATA_SIZE_MAX;
    
    		uint32_t err = ble_advdata_encode(&g_BleAppData.SrData, g_AdvInstance.adv_data.scan_rsp_data.p_data,
    										 &g_AdvInstance.adv_data.scan_rsp_data.len);
    		APP_ERROR_CHECK(err);
    	}
    
    	// SDK15 doesn't allow dynamicaly updating adv data.  Have to stop and re-start advertising
    	if (g_BleAppData.bAdvertising == true)
    	{
    		sd_ble_gap_adv_stop(g_AdvInstance.adv_handle);
    	}
    
    	err = sd_ble_gap_adv_set_configure(&g_AdvInstance.adv_handle, &g_AdvInstance.adv_data, NULL);
    	APP_ERROR_CHECK(err);
    
    	if (g_BleAppData.bAdvertising == true)
    	{
    		g_BleAppData.bAdvertising = false;
    		BleAppAdvStart(BLEAPP_ADVMODE_FAST);
    	}
    
    }
    

  • You mean instead of

    advertising_init();
    advertising_start();
    

    do

    BleAppAdvManDataSet();
    advertising_start();

    ?

Related