Hi,
I have a project which was originally written using SDK12, and have updated it to SDK16, I am sorry I know this question seems to have been asked in many different ways already.
I have one problem left.
I need to dynamically update manufacture specific data for the advertisement, and the code below used to work fine.
I know things have changed now and I have to use the ble_advdata_encode function, but it is not clear how exactly and I cannot find any direct examples.
The searched turn up hundreds of results from the forum which are all slightly different, some use ble_advertising_init, others sd_ble_gap_adv_start and a ton inbetweeners.
The migration guide is also not clear on the matter.
I am using short names and fast advertising, I previously had the following init function and an update function - could someone indicate to me, or point me to a proper example of how I can change this code from SDK12 style to SDK16 and achieve exactly the same result with as little change as possible?
I think I have to continue to use the ble_advertising_init due to the fast advertising options, I would also prefer not to have to stop and start the advertisement every time I want to update it (i believe I will also have to update the interval times as per the change of units mentioned in the migration guide)
BLE_ADVERTISING_DEF(m_advertising); /**< Advertising module instance. */ static ble_manufacturer_data_t m_manufacturer_data; static ble_uuid_t m_adv_uuids[] = /**< Universally unique service identifiers. */ { { BLE_UUID_DEVICE_INFORMATION_SERVICE, BLE_UUID_TYPE_BLE } //, //{BLE_UUID_CALLPOINT_SERVICE, BLE_UUID_TYPE_VENDOR_BEGIN} }; /**@brief Function for initializing the Advertising functionality. */ static void advertising_init(void) { ret_code_t err_code; ble_advdata_manuf_data_t adv_manuf_data; uint8_array_t adv_manuf_data_array; uint8_t adv_manuf_data_data[sizeof(ble_manufacturer_data_t) - 2]; memset(&m_adv_init, 0, sizeof(m_adv_init)); m_adv_init.advdata.name_type = BLE_ADVDATA_SHORT_NAME; m_adv_init.advdata.short_name_len = 3; m_adv_init.advdata.include_appearance = true; m_adv_init.advdata.flags = BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE; m_adv_init.advdata.uuids_complete.uuid_cnt = sizeof(m_adv_uuids) / sizeof(m_adv_uuids[0]); m_adv_init.advdata.uuids_complete.p_uuids = m_adv_uuids; // Configuration of manufacturer specific data memcpy((uint8_t*) adv_manuf_data_data, (uint8_t*) &m_manufacturer_data.DeviceType, sizeof(ble_manufacturer_data_t) - 2); adv_manuf_data_array.p_data = adv_manuf_data_data; adv_manuf_data_array.size = sizeof(ble_manufacturer_data_t) - 2; adv_manuf_data.company_identifier = LI_COMPANY; adv_manuf_data.data = adv_manuf_data_array; m_adv_init.advdata.p_manuf_specific_data = &adv_manuf_data; m_adv_init.config.ble_adv_fast_enabled = true; m_adv_init.config.ble_adv_fast_interval = APP_ADV_INTERVAL; m_adv_init.config.ble_adv_fast_timeout = APP_ADV_TIMEOUT_IN_SECONDS; m_adv_init.evt_handler = on_adv_evt; err_code = ble_advertising_init(&m_advertising, &m_adv_init); APP_ERROR_CHECK(err_code); ble_advertising_conn_cfg_tag_set(&m_advertising, APP_BLE_CONN_CFG_TAG); } static void update_advertisment(void) { ret_code_t err_code; ble_advdata_manuf_data_t adv_manuf_data; uint8_array_t adv_manuf_data_array; uint8_t adv_manuf_data_data[sizeof(ble_manufacturer_data_t) - 2]; // Configuration of manufacturer specific data memcpy((uint8_t*) adv_manuf_data_data, (uint8_t*) &m_manufacturer_data.DeviceType, sizeof(ble_manufacturer_data_t) - 2); adv_manuf_data_array.p_data = adv_manuf_data_data; adv_manuf_data_array.size = sizeof(ble_manufacturer_data_t) - 2; adv_manuf_data.company_identifier = LI_COMPANY; adv_manuf_data.data = adv_manuf_data_array; m_adv_init.advdata.p_manuf_specific_data = &adv_manuf_data; err_code = ble_advdata_set(&m_adv_init.advdata, NULL); APP_ERROR_CHECK(err_code); }
Many thanks