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

Updating advertising data (manuf. spec. data) in SDK15

Hello guys! And girls Slight smile

My project is working as expected in SDK14.2.
I'm updating adv data (manuf. spec. data) without any problem with this function

static void advertising_data_update(uint8_t adv_manuf_byte)
{
		ret_code_t err_code;

		ble_advertising_init_t 		init;
		ble_advdata_manuf_data_t 	adv_manuf_data;
		uint8_array_t            	adv_manuf_data_array;
		uint8_t                  	adv_manuf_data_data[1];
		adv_manuf_data_data[0] 		= adv_manuf_byte;

		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;
		init.advdata.uuids_complete.uuid_cnt = sizeof(m_adv_uuids) / sizeof(m_adv_uuids[0]);
		init.advdata.uuids_complete.p_uuids  = m_adv_uuids;

		adv_manuf_data_array.p_data 							 = adv_manuf_data_data;
		adv_manuf_data_array.size 								 = sizeof(adv_manuf_data_data);
		adv_manuf_data.company_identifier 				 = APP_COMPANY_IDENTIFIER;
		adv_manuf_data.data 											 = adv_manuf_data_array;
		init.advdata.p_manuf_specific_data 				 = &adv_manuf_data;

		init.config.ble_adv_whitelist_enabled      = true;
		init.config.ble_adv_directed_enabled       = true;
		init.config.ble_adv_directed_slow_enabled  = false;
		init.config.ble_adv_directed_slow_interval = 0;
		init.config.ble_adv_directed_slow_timeout  = 0;
		init.config.ble_adv_fast_enabled  				 = true;
		init.config.ble_adv_fast_interval 				 = APP_ADV_INTERVAL;
		init.config.ble_adv_fast_timeout  				 = APP_ADV_TIMEOUT_IN_SECONDS;
							
		err_code = ble_advdata_set(&init.advdata, NULL);
		APP_ERROR_CHECK(err_code);	   
}


But in SDK15 the function ble_advdata_set() has been deprecated.
The migration guide is says to use ble_advdata_encode() and sd_ble_gap_adv_set_configure() instead.

So I changed it to something like this

static void advertising_data_update(uint8_t adv_manuf_byte)
{
		ret_code_t err_code;

		ble_advertising_init_t 		init;
		ble_advdata_manuf_data_t 	adv_manuf_data;
		uint8_array_t            	adv_manuf_data_array;
		adv_manuf_data_data[0] 		= adv_manuf_byte;

		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_LIMITED_DISC_MODE;
    init.advdata.uuids_complete.uuid_cnt = sizeof(m_adv_uuids) / sizeof(m_adv_uuids[0]);
    init.advdata.uuids_complete.p_uuids  = m_adv_uuids;
			
		adv_manuf_data_array.p_data 							 = adv_manuf_data_data;
		adv_manuf_data_array.size 								 = sizeof(adv_manuf_data_data);
		adv_manuf_data.company_identifier 				 = APP_COMPANY_IDENTIFIER;
		adv_manuf_data.data 											 = adv_manuf_data_array;
		init.advdata.p_manuf_specific_data 				 = &adv_manuf_data;

    init.config.ble_adv_whitelist_enabled      			= true;
		init.config.ble_adv_directed_high_duty_enabled 	= true;
    init.config.ble_adv_directed_enabled       			= false;
    init.config.ble_adv_fast_enabled  				 			= true;
    init.config.ble_adv_fast_interval 				 			= APP_ADV_INTERVAL;
    init.config.ble_adv_fast_timeout  				 			= APP_ADV_FAST_DURATION;

		//err_code = sd_ble_gap_adv_stop(m_advertising.adv_handle);
		//APP_ERROR_CHECK(err_code);
			
		err_code = ble_advdata_encode(&init.advdata, m_adv_data.adv_data.p_data, &m_adv_data.adv_data.len);	
		APP_ERROR_CHECK(err_code);

		err_code = sd_ble_gap_adv_set_configure(&m_advertising.adv_handle, &m_adv_data, NULL);
		APP_ERROR_CHECK(err_code);
		
		//err_code = sd_ble_gap_adv_start(m_advertising.adv_handle, APP_BLE_CONN_CFG_TAG);
		//APP_ERROR_CHECK(err_code);
}


And of course... it's not working. :)
I'm getting a very strange error at sd_ble_gap_adv_set_configure() --> app: ERROR 12801 [Unknown error code]

Any idea why?
What I'm doing wrong?
What I have to change to get this working like in the SDK14.2?

Parents Reply Children
  • , tnx for info, I will try without a module to.

    Can you please show me your adv_init funciton?
    EDIT: I saw now your function in the other topic.

    Do you have any of your project(s) on some-sort-of github too?

  • I posted some explanation to the function here, but if you just need the code:

    BLE_ADVERTISING_DEF(m_advModuleInstance);
    
    extern void advertising_init (void)
    {
      uint32_t      err_code = NRF_SUCCESS;
      ble_advdata_t advInitData;
      ble_advdata_t srInitData;
    
      /* Initialize structs. */
      memset(&advInitData, 0, sizeof(ble_advdata_t));
      memset(&srInitData, 0, sizeof(ble_advdata_t));
    
      /* Prepare advertising data. */
      advInitData.xxx = xxx; // configure the data you want here
    
      /* Prepare scan response data. */
      srInitData.xxx = xxx; // configure the data you want here
    
      /* Set advertising and scan response data. */
      m_advModuleInstance.adv_handle = BLE_GAP_ADV_SET_HANDLE_NOT_SET;
      m_advModuleInstance.adv_mode_current = BLE_ADV_MODE_IDLE;
    
      m_advModuleInstance.adv_data.adv_data.p_data = m_advModuleInstance.enc_advdata;
      m_advModuleInstance.adv_data.adv_data.len    = BLE_GAP_ADV_SET_DATA_SIZE_MAX;
    
      err_code = ble_advdata_encode(&advInitData, m_advModuleInstance.adv_data.adv_data.p_data, &m_advModuleInstance.adv_data.adv_data.len);
      APP_ERROR_CHECK(err_code);
      BLEPE_LOG_PRINTF_WARNING("adv_data.len 0x%X",m_advModuleInstance.adv_data.adv_data.len);
    
      m_advModuleInstance.adv_data.scan_rsp_data.p_data = m_advModuleInstance.enc_scan_rsp_data;
      m_advModuleInstance.adv_data.scan_rsp_data.len    = BLE_GAP_ADV_SET_DATA_SIZE_MAX;
    
      err_code = ble_advdata_encode(&srInitData, m_advModuleInstance.adv_data.scan_rsp_data.p_data, &m_advModuleInstance.adv_data.scan_rsp_data.len);
      APP_ERROR_CHECK(err_code);
      BLEPE_LOG_PRINTF_WARNING("scan_rsp_data.len 0x%X",m_advModuleInstance.adv_data.scan_rsp_data.len);
    
      /*
       *  Configure a initial advertising configuration. The advertising data and advertising parameters
       *  can be changed later, but must be set to legal values here to define an advertising handle.
       */
      m_advModuleInstance.adv_params.primary_phy     = BLE_GAP_PHY_1MBPS;
      m_advModuleInstance.adv_params.duration        = BLE_GAP_ADV_TIMEOUT_GENERAL_UNLIMITED;
      m_advModuleInstance.adv_params.properties.type = BLE_GAP_ADV_TYPE_CONNECTABLE_SCANNABLE_UNDIRECTED;
      m_advModuleInstance.adv_params.p_peer_addr     = NULL;
      m_advModuleInstance.adv_params.filter_policy   = BLE_GAP_ADV_FP_ANY;
      m_advModuleInstance.adv_params.interval        = BLE_GAP_ADV_INTERVAL_MIN;
    
      err_code = sd_ble_gap_adv_set_configure(&m_advModuleInstance.adv_handle, &m_advModuleInstance.adv_data, &m_advModuleInstance.adv_params);
      APP_ERROR_CHECK(err_code);
    
      m_advModuleInstance.initialized = true;
    }

    EDIT: Sorry, but I have no github projects.

  • Guys, I don't know if you already seen that, but... in the SDK15.1 the Advertising module has a new function - ble_advertising_advdata_update ;)

Related