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

Confusion about new style of manufacturer specific data updating

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

Parents
  • It is SO much easier to update now!  Here's how I do it.  Change the options in new_data to match your init function.

    /**@brief Function for updating manufacturer data in the Advertising payload.
     */
    static void advertising_update_mfg_data(void)
    {
        ret_code_t             err_code;
    
        static ble_advdata_t new_data; // SDK 16.x.x implementation is similar to advertising_init
    
        new_data.name_type               = BLE_ADVDATA_FULL_NAME;
        new_data.include_appearance      = false;
        new_data.flags                   = BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE;
        new_data.uuids_complete.uuid_cnt = 0;
            
        // Variables used for manufacturer specific data
        ble_advdata_manuf_data_t p_manuf_specific_data;
        uint8_array_t            adv_manuf_data_array;
        uint8_t                  adv_manuf_data_data[2];
    
        // Configuration of manufacturer specific data
        adv_manuf_data_data[0] = <<<<your first byte here>>>>;
        adv_manuf_data_data[1] = <<<<your second byte here>>>>;
    
        adv_manuf_data_array.p_data = adv_manuf_data_data;
        adv_manuf_data_array.size = sizeof(adv_manuf_data_data);
    
        p_manuf_specific_data.company_identifier = BLE_COMPANY_IDENTIFIER;
        p_manuf_specific_data.data = adv_manuf_data_array;
        
        new_data.p_manuf_specific_data = &p_manuf_specific_data;
    
        //SDK16.x.x implementation will handle all buffering and encoding inside the update function
        err_code = ble_advertising_advdata_update(&m_advertising, &new_data, NULL);  
        APP_ERROR_CHECK(err_code);
    
    }

Reply Children
No Data
Related