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

Modifications on Advertising initialization

Hello,

I try to modify the advertising initialization to advertise only my custom service (BTS_UUID_SERVICE ). Objective is to hide (just during adv) others sig services.

I tried different things ( with and without scan response, with different number of uuids) but every time i add my own service, device refuse to advertise anything...

Thanks


**@brief Function for initializing the Advertising functionality.
 *
 * @details Encodes the required advertising data and passes it to the stack.
 *          Also builds a structure to be passed to the stack when starting advertising.
 */
static void advertising_init(void)
{
	
    uint32_t      err_code;
    ble_advdata_t advdata;
    ble_advdata_t scanrsp;
    uint8_t       flags = BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE;
		int8_t       	tx_power_level = TX_POWER_LEVEL;
    
		//===========Choix des services que l'on veut adv ==========================
    ble_uuid_t adv_uuids[] = {{BTS_UUID_SERVICE, m_bts.uuid_type}};
		
		/*
    ble_uuid_t adv_uuids[] ={
			//	{BTS_UUID_SERVICE, 								 m_bts.uuid_type},
       {BLE_UUID_TX_POWER_SERVICE,        BLE_UUID_TYPE_BLE}, 
       {BLE_UUID_IMMEDIATE_ALERT_SERVICE, BLE_UUID_TYPE_BLE},
			 {BLE_UUID_LINK_LOSS_SERVICE,       BLE_UUID_TYPE_BLE}
    };
		*/
	
    // Build and set advertising data
    memset(&advdata, 0, sizeof(advdata));
		
    advdata.name_type               = BLE_ADVDATA_FULL_NAME;
    advdata.include_appearance      = true;
    advdata.flags.size              = sizeof(flags);
    advdata.flags.p_data            = &flags;
		//advdata.p_tx_power_level        = &tx_power_level;
		//advdata.uuids_complete.uuid_cnt = 1 ; //sizeof(adv_uuids) / sizeof(adv_uuids[0]);
		//advdata.uuids_complete.p_uuids  = adv_uuids;
		
    memset(&scanrsp, 0, sizeof(scanrsp));		
    scanrsp.uuids_complete.uuid_cnt = 1;//sizeof(adv_uuids) / sizeof(adv_uuids[0]);
    scanrsp.uuids_complete.p_uuids  = adv_uuids;
    
    err_code = ble_advdata_set(&advdata,&scanrsp);
    APP_ERROR_CHECK(err_code);
}

Parents
  • Could it be that m_bts.uuid_type have not been set at the time of advertising_init()? If so, you'll get NRF_ERROR_INVALID_PARAMS back from ble_advdata_set(), which you can easily see by following the suggestion here.

    If this is the problem, you can most likely fix it by changing the order of services_init() and advertising_init() in main, assuming that the call to sd_ble_uuid_vs_add() gets called from services_init().

Reply
  • Could it be that m_bts.uuid_type have not been set at the time of advertising_init()? If so, you'll get NRF_ERROR_INVALID_PARAMS back from ble_advdata_set(), which you can easily see by following the suggestion here.

    If this is the problem, you can most likely fix it by changing the order of services_init() and advertising_init() in main, assuming that the call to sd_ble_uuid_vs_add() gets called from services_init().

Children
No Data
Related