Hello,
I'm writing a BLE app that acts as a peripheral and a broadcaster. If a connection is established, I'd like to continue advertising but update the advertising parameters from connectable to non-connectable. Following the broadcaster example I wrote the following code to setup and start advertising.
static int advertising_init(void)
{
uint32_t err_code;
ble_advdata_t advdata;
memset(&advdata, 0, sizeof(ble_advdata_t));
advdata.name_type = BLE_ADVDATA_FULL_NAME;
advdata.flags = BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE;
ble_uuid_t adv_uuid = {BLE_UUID_NUS_SERVICE, m_nus.uuid_type};
advdata.uuids_complete.uuid_cnt = 1;
advdata.uuids_complete.p_uuids = &adv_uuid;
// encode the adv data for use when updating adv data
m_adv_data.adv_data.len = BLE_GAP_ADV_SET_DATA_SIZE_MAX;
err_code = ble_advdata_encode(&advdata, m_encoded_adv_data[0], &m_adv_data.adv_data.len);
APP_VIEWER_ERROR_CHECK(err_code);
err_code = ble_advdata_encode(&advdata, m_encoded_adv_data[1], &m_adv_data.adv_data.len);
APP_VIEWER_ERROR_CHECK(err_code);
// Initialize advertising parameters (used when starting advertising).
memset(&m_adv_params, 0, sizeof(m_adv_params));
m_adv_params.properties.type = BLE_GAP_ADV_TYPE_CONNECTABLE_SCANNABLE_UNDIRECTED;
m_adv_params.p_peer_addr = NULL;
m_adv_params.filter_policy = BLE_GAP_ADV_FP_ANY;
m_adv_params.interval = MSEC_TO_UNITS(1000, UNIT_0_625_MS);
m_adv_params.duration = 0;
err_code = sd_ble_gap_adv_set_configure(&m_adv_handle, &m_adv_data, &m_adv_params);
APP_ERROR_CHECK(err_code);
err_code = sd_ble_gap_adv_start(m_adv_handle, 1);
APP_ERROR_CHECK(err_code);
return 0;
}
When a connection is established, the below function is called to update the advertising parameters.
void app_viewer_on_connected(uint16_t ch)
{
uint32_t err_code;
NRF_LOG_INFO("Viewer Connected.");
conn_handle = ch;
m_adv_params.properties.type = BLE_GAP_ADV_TYPE_NONCONNECTABLE_SCANNABLE_UNDIRECTED;
err_code = sd_ble_gap_adv_set_configure(&m_adv_handle, &m_adv_data, &m_adv_params);
APP_ERROR_CHECK(err_code);
err_code = sd_ble_gap_adv_start(m_adv_handle, 1);
APP_ERROR_CHECK(err_code);
}
The issue I'm encountering is that the device still advertises as a connectable device. I'm not seeing any errors returned from the Softdevice. Is sd_ble_gap_adv_set_configure() the correct function to update advertising parameters and am I using it properly?
I'm using:
- nRF52832
- SDK 15.2
- S132 6.1.0
Thanks,
Eric