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

Zephyr - Device does not advertise if advertisement data is set

Hello!

I am trying to create a connectable advertiser that can have its advertisement data updated dynamically on a nrf52832. I am creating the advertisement with this code:

constexpr bt_le_adv_param params = BT_LE_ADV_PARAM_INIT(
    BT_LE_ADV_OPT_USE_NAME | BT_LE_ADV_OPT_USE_IDENTITY | BT_LE_ADV_OPT_CONNECTABLE,
    BT_GAP_ADV_FAST_INT_MIN_2,
    BT_GAP_ADV_FAST_INT_MAX_2,
NULL
);

int err = bt_le_ext_adv_create(&params, &cbs, &adv);
__ASSERT(err == 0, "Create advertiser init");

If I then start advertising with 

bt_le_ext_adv_start_param start_params = {
	.timeout = 0,
	.num_events = 0
};

int err = bt_le_ext_adv_start(adv, &start_params);
return err;

It starts advertising and I can see the advertisements in the NRFConnect app. However, if I attempt to set the advertisement before the `bt_le_ext_adv_start` with

static AdvData data {
	AdvField<uint8_t>  { BT_DATA_FLAGS, (BT_LE_AD_GENERAL | BT_LE_AD_NO_BREDR) },
	AdvField<uint16_t> { BT_DATA_MANUFACTURER_DATA, 0x1234 }
};
int err = bt_le_ext_adv_set_data(adv, data.data(), data.size(), 0, 0);



//Also attemted this just to make sure
static bt_data adv_buffer[] = {
	BT_DATA_BYTES(BT_DATA_FLAGS, (BT_LE_AD_GENERAL | BT_LE_AD_NO_BREDR)),
	BT_DATA_BYTES(BT_DATA_MANUFACTURER_DATA, COMPANY_ID_BYTES(0x1234)), 
};
int err = bt_le_ext_adv_set_data(adv, adv_buffer, ARRAY_SIZE(adv_buffer), 0, 0);

There is no error returned, but there is no advertisements. Nothing shows in the NRFConnect application.

How do I correctly set the advertisement data before starting advertising using the `bt_le_ext` methods?

Thanks,

Sam

Parents
  • This code does not work. I can not see any advertisements in the nrfconnect application. However there is no error anywhere being reported.

    constexpr bt_le_adv_param  params =  BT_LE_ADV_PARAM_INIT(
    	BT_LE_ADV_OPT_USE_NAME | BT_LE_ADV_OPT_USE_IDENTITY | BT_LE_ADV_OPT_CONNECTABLE,
    	BT_GAP_ADV_FAST_INT_MIN_2,
    	BT_GAP_ADV_FAST_INT_MAX_2,
    	NULL
    );
    	
    
    int err = bt_le_ext_adv_create(&params, &cbs, &adv);
    __ASSERT(err == 0, "Create advertiser init");
    
    AdvData data {
    	AdvField<uint8_t>  { BT_DATA_FLAGS, (BT_LE_AD_GENERAL | BT_LE_AD_NO_BREDR) },
    	AdvField<uint16_t> { BT_DATA_MANUFACTURER_DATA, 0x1234 }
    };
    err = bt_le_ext_adv_set_data(adv, data.data(), data.size(), 0, 0);
    __ASSERT(err == 0, "advertiser_set_data");
    	
    
    bt_le_ext_adv_start_param start_params = {
    	.timeout = 0,
    	.num_events = 0
    };
    err = bt_le_ext_adv_start(adv, &start_params);
    __ASSERT(err == 0, "advertiser_start_advertising");

    If I either remove the `bt_le_ext_adv_set_data` or remove the `BT_LE_ADV_OPT_CONNECTABLE` flag, the code starts working and I can see the advertisements in the nrfconnect application.

    Its the combination of both setting the data and being connectable that is causing an issue.

    Is there some requirement I am missing?

Reply
  • This code does not work. I can not see any advertisements in the nrfconnect application. However there is no error anywhere being reported.

    constexpr bt_le_adv_param  params =  BT_LE_ADV_PARAM_INIT(
    	BT_LE_ADV_OPT_USE_NAME | BT_LE_ADV_OPT_USE_IDENTITY | BT_LE_ADV_OPT_CONNECTABLE,
    	BT_GAP_ADV_FAST_INT_MIN_2,
    	BT_GAP_ADV_FAST_INT_MAX_2,
    	NULL
    );
    	
    
    int err = bt_le_ext_adv_create(&params, &cbs, &adv);
    __ASSERT(err == 0, "Create advertiser init");
    
    AdvData data {
    	AdvField<uint8_t>  { BT_DATA_FLAGS, (BT_LE_AD_GENERAL | BT_LE_AD_NO_BREDR) },
    	AdvField<uint16_t> { BT_DATA_MANUFACTURER_DATA, 0x1234 }
    };
    err = bt_le_ext_adv_set_data(adv, data.data(), data.size(), 0, 0);
    __ASSERT(err == 0, "advertiser_set_data");
    	
    
    bt_le_ext_adv_start_param start_params = {
    	.timeout = 0,
    	.num_events = 0
    };
    err = bt_le_ext_adv_start(adv, &start_params);
    __ASSERT(err == 0, "advertiser_start_advertising");

    If I either remove the `bt_le_ext_adv_set_data` or remove the `BT_LE_ADV_OPT_CONNECTABLE` flag, the code starts working and I can see the advertisements in the nrfconnect application.

    Its the combination of both setting the data and being connectable that is causing an issue.

    Is there some requirement I am missing?

Children
Related