Hello, we are creating a device on an nRF52832. I started our project based on the examples/ble_peripheral/ble_app_uart project, which worked fine. However, I needed to modify the advertisement data, so I tried to merge in some code from the ble_app_beacon project, and an odd behavior has arisen.
Basically, when I assign manufacturing data, our device name gets truncated by four characters. In our code (again, just a modified ble_app_uart), we set the device name with a call to sd_ble_gap_device_name_set. The intended name is "SmileDevice0.00.017" (See first snippet below.)
What I think I learned from the "beacon" example is how to set up a ble_advdata_manuf_data_t object and assign it to init.advdata.p_manuf_specific_data before calling ble_advdata_encode, and it will assign that data to that field. This code is below, it works well -- I can see the intended manufacturer data in my sniffer.
EXCEPT, I noticed that our device name became truncated to "SmileDevice0.00" when I connected the manufacturing data. This is a direct cause and effect, if I don't assign manufacturer data, then the device name is the correct length. If I assign it, it's truncated. As stated in the code:
// if I comment out the following line of code, then device name advertises as 'SmileDevice0.00.017' and there is no manufacturing data
// if I leave this line of code in, there is advertising data but the device name advertises as 'SmileDevice0.00'
// what is it about the manufacturing data that is *truncating* the device name?
init.advdata.p_manuf_specific_data = &manuf_specific_data;
So... what is it I don't understand about how to set this up, that is causing manufacturing data to corrupt the length of my device name?
Thanks.
////////////////////////////////////////////////// // in the gap_params_init section // m_DeviceName = "SmileDevice0.00.017" // m_DeviceNameLength = 19 ////////////////////////////////////////////////// err_code = sd_ble_gap_device_name_set(&sec_mode, (const uint8_t *) m_DeviceName, m_DeviceNameLength); if (err_code != NRF_SUCCESS) { RETURN_FAULT(2, err_code) } ...
////////////////////////////////////////////////// // in the advertising init section // uint8_t m_MfrData[] = {9,10,11,12,13,14,15} // uint8_t m_MfrDataLength= 7 ////////////////////////////////////////////////// ble_advertising_init_t init; memset(&init, 0, sizeof(init)); init.advdata.name_type = BLE_ADVDATA_FULL_NAME; init.advdata.include_appearance = false; init.advdata.flags = BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE; // set the manufacturing data ble_advdata_manuf_data_t manuf_specific_data; manuf_specific_data.company_identifier = 0x0; manuf_specific_data.data.p_data = (uint8_t *) (m_MfrData); manuf_specific_data.data.size = m_MfrDataLength; // if I comment out the following line of code, then device name advertises as 'SmileDevice0.00.017' and there is no manufacturing data // if I leave this line of code in, there is advertising data but the device name advertises as 'SmileDevice0.00' // what is it about the manufacturing data that is *truncating* the device name? init.advdata.p_manuf_specific_data = &manuf_specific_data; init.srdata.uuids_complete.uuid_cnt = sizeof(m_adv_uuids) / sizeof(m_adv_uuids[0]); init.srdata.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; m_advertising.adv_mode_current = BLE_ADV_MODE_IDLE; m_advertising.adv_modes_config = init.config; m_advertising.conn_cfg_tag = BLE_CONN_CFG_TAG_DEFAULT; m_advertising.evt_handler = init.evt_handler; m_advertising.error_handler = init.error_handler; m_advertising.current_slave_link_conn_handle = BLE_CONN_HANDLE_INVALID; m_advertising.p_adv_data = &(m_advertising.adv_data); memset(&(m_advertising.peer_address), 0, sizeof(m_advertising.peer_address)); // Copy advertising data. if (!m_advertising.initialized) { m_advertising.adv_handle = BLE_GAP_ADV_SET_HANDLE_NOT_SET; } m_advertising.adv_data.adv_data.p_data = m_advertising.enc_advdata[0]; m_advertising.adv_data.adv_data.len = adv_set_data_size_max_get(&(m_advertising)); err_code = ble_advdata_encode(&(init.advdata), m_advertising.enc_advdata[0], &(m_advertising.adv_data.adv_data.len)); if (err_code != NRF_SUCCESS) { RETURN_FAULT(2, err_code) } m_advertising.adv_data.scan_rsp_data.p_data = m_advertising.enc_scan_rsp_data[0]; m_advertising.adv_data.scan_rsp_data.len = adv_set_data_size_max_get(&(m_advertising)); err_code = ble_advdata_encode(&(init.srdata), m_advertising.adv_data.scan_rsp_data.p_data, &(m_advertising.adv_data.scan_rsp_data.len)); if (err_code != NRF_SUCCESS) { RETURN_FAULT(2, err_code) } // Configure a initial advertising configuration. The advertising data and and advertising // parameters will be changed later when we call @ref ble_advertising_start, but must be set // to legal values here to define an advertising handle. m_advertising.adv_params.primary_phy = BLE_GAP_PHY_1MBPS; m_advertising.adv_params.duration = m_advertising.adv_modes_config.ble_adv_fast_timeout; m_advertising.adv_params.properties.type = BLE_GAP_ADV_TYPE_CONNECTABLE_SCANNABLE_UNDIRECTED; m_advertising.adv_params.p_peer_addr = NULL; m_advertising.adv_params.filter_policy = BLE_GAP_ADV_FP_ANY; m_advertising.adv_params.interval = m_advertising.adv_modes_config.ble_adv_fast_interval; err_code = sd_ble_gap_adv_set_configure(&(m_advertising.adv_handle), NULL, &(m_advertising.adv_params)); if (err_code != NRF_SUCCESS) { RETURN_FAULT(2, err_code) } m_advertising.initialized = true; ble_advertising_conn_cfg_tag_set(&m_advertising, APP_BLE_CONN_CFG_TAG);