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

Update advertisement data with the help of radio notification

Hi!

We are using ble_radio_notification for changing the advertisement data after every advertisement. The problem is that it doesn't work, the device freezes when trying to do this.

Here are some code snippets that might give you a better understanding.

void radio_notification_evt_handler(bool radio_evt)
{
 	if (radio_evt) {
		//radio going active
		//turn on LED
		LEDS_ON(BSP_LED_2_MASK);
	} else {
		//radio inactive
		//turn off LED
		counter += 1;
		LEDS_OFF(BSP_LED_2_MASK);
		advertising_set_data(&counter, sizeof(uint8_t));    // This is where we die!!
	}
}

All we want is to set a number that is increased by one for every advertisement. So this is the code that tells us when to "update" the advertisement data, it is initialized by:

err_code = ble_radio_notification_init(RADIO_NOTIFICATION_IRQ_PRIORITY, NRF_RADIO_NOTIFICATION_DISTANCE_5500US, radio_notification_evt_handler);

where priority is 3 and the distance at the moment is 5500us (all combinations tested).

advertising_set_data looks like this

static void advertising_set_data(const uint8_t* p_in_data, size_t dlen)
{
	uint32_t						err_code;
	ble_advdata_t					advdata;
	ble_advdata_t					scanrsp;
	ble_advdata_manuf_data_t        manuf_data; // Variable to hold manufacturer specific data

	uint8_t data[8] = {0};
	memcpy(data, p_in_data, dlen);						// Our data to advertise
	manuf_data.company_identifier = 0x1337;		// "Random" company id
	manuf_data.data.p_data = data;
	manuf_data.data.size = sizeof(data);

	ble_uuid_t adv_uuids[] = { { LBS_UUID_SERVICE, m_lbs.uuid_type } };

	// Build and set advertising data
	memset(&advdata, 0, sizeof(advdata));

	advdata.name_type = BLE_ADVDATA_FULL_NAME;
	advdata.include_appearance = true;
	advdata.flags = BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE;
	advdata.p_manuf_specific_data = &manuf_data;

	memset(&scanrsp, 0, sizeof(scanrsp));
	scanrsp.uuids_complete.uuid_cnt = 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);
}

It is only when we do this in radio_notification_evt_handler that the device dies/freezes. Doing it in for example here doesn't give us this issue.

// Enter main loop.
    for (;;)
    {
        power_manage();
		advertising_set_data(&counter, sizeof(uint8_t));
    }

All feedback that could help us avoid this issue is greatly appreciated.

Parents Reply Children
No Data
Related