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

Updating Advertisement data in nrf52840 using SDK 16

Hi,

I am trying to update my advertisement data as well as scan response data (i want to put some custom advertisement data and the device name in scan response data).

// Stop advertisement
err_code=sd_ble_gap_adv_stop(m_advertising.adv_handle);
APP_ERROR_CHECK(err_code);


// encoding BLE adv data
new_advdata.adv_data.len = BLE_GAP_ADV_SET_DATA_SIZE_MAX;
err_code = ble_advdata_encode(&init.advdata, new_advdata.adv_data.p_data, &new_advdata.adv_data.len);
APP_ERROR_CHECK(err_code);

// encoding BLE scan response data
new_advdata.scan_rsp_data.len = BLE_GAP_ADV_SET_DATA_SIZE_MAX;
err_code = ble_advdata_encode(&init.srdata, new_advdata.scan_rsp_data.p_data, &new_advdata.scan_rsp_data.len);
APP_ERROR_CHECK(err_code);

//configure advertisement
err_code= sd_ble_gap_adv_set_configure(&m_advertising.adv_handle, &new_advdata, &m_advertising.adv_params);
APP_ERROR_CHECK(err_code);

// start Advertisement
err_code = sd_ble_gap_adv_start(m_advertising.adv_handle, APP_BLE_CONN_CFG_TAG);
APP_ERROR_CHECK(err_code);

After populating ble_advertising_init_t this structure i am using this code, but ble_advdata_encode is returning error code 16.