Way to enumerate advertisements

Hello,

Our peripheral device (52840) broadcasts BLE extended advertisements with 1 Hz frequency. Each advertisement has a "manufacturer data" with sensor readings.
To estimate data loss I'd like to attach to each advertisement a sequential ID - to see by its increment, how many advertisements were really issued during the given period of time, and which we have missed.

Is there any way to achieve that after 2.6.0 (with radio notification API removed)?

Thanks,
Dmitry 

Parents
  • I guess you should be able to use the Bluetooth Event Trigger API for this. The example Bluetooth: Event Trigger is setting up triggers on Connection Events. If you change the function `setup_connection_event_trigger()` to something like the following code snippet, you should be able to trigger at Advertising Events instead.

    static int setup_advertisement_event_trigger(struct bt_le_ext_adv *adv_set, bool enable)
    {
    	int err;
    	sdc_hci_cmd_vs_set_event_start_task_t cmd_params = {};
    	uint8_t adv_handle;
    
    	err = bt_hci_get_adv_handle(adv_set, &adv_handle);
    	if (err) {
    		printk("Failed obtaining handle: %s (%d)\n", strerror(-err), err);
    		return err;
    	}
    
    	cmd_params.handle_type = SDC_HCI_VS_SET_EVENT_START_TASK_HANDLE_TYPE_ADV;
    	cmd_params.handle = adv_handle;
    
    	if (enable) {
    		cmd_params.task_address = nrf_egu_task_address_get(NRF_EGU, NRF_EGU_TASK_TRIGGER0);
    
    		IRQ_DIRECT_CONNECT(DT_IRQN(EGU_NODE), 5, egu_handler, 0);
    		nrf_egu_int_enable(NRF_EGU, NRF_EGU_INT_TRIGGERED0);
    		NVIC_EnableIRQ(DT_IRQN(EGU_NODE));
    	} else {
    		cmd_params.task_address = 0;
    		nrf_egu_int_disable(NRF_EGU, NRF_EGU_INT_TRIGGERED0);
    		NVIC_DisableIRQ(DT_IRQN(EGU_NODE));
    	}
    
    	err = hci_vs_sdc_set_event_start_task(&cmd_params);
    	if (err) {
    		printk("Error for command hci_vs_sdc_set_event_start_task(): %s (%d)\n",
    		       strerror(-err), err);
    		return err;
    	}
    
    	printk("Successfully configured event trigger\n");
    
    	return 0;
    }

    Call that function after you have created your Extended Adverisement Set. Create a worker callback function that updates your Advertisement Data by using the function `bt_le_ext_adv_set_data()` every time the event is triggered.

    Note that Extended Advertisements are sent out with a small random delay added to your chosen interval (1 second). If that is a problem you may want to have a look at Periodic Advertising (Bluetooth 5.0). Also Periodic Advertising with Responses (PAwR, Bluetooth 5.4) is a very powerful feature for connecting multiple sensors to one access point.

Reply
  • I guess you should be able to use the Bluetooth Event Trigger API for this. The example Bluetooth: Event Trigger is setting up triggers on Connection Events. If you change the function `setup_connection_event_trigger()` to something like the following code snippet, you should be able to trigger at Advertising Events instead.

    static int setup_advertisement_event_trigger(struct bt_le_ext_adv *adv_set, bool enable)
    {
    	int err;
    	sdc_hci_cmd_vs_set_event_start_task_t cmd_params = {};
    	uint8_t adv_handle;
    
    	err = bt_hci_get_adv_handle(adv_set, &adv_handle);
    	if (err) {
    		printk("Failed obtaining handle: %s (%d)\n", strerror(-err), err);
    		return err;
    	}
    
    	cmd_params.handle_type = SDC_HCI_VS_SET_EVENT_START_TASK_HANDLE_TYPE_ADV;
    	cmd_params.handle = adv_handle;
    
    	if (enable) {
    		cmd_params.task_address = nrf_egu_task_address_get(NRF_EGU, NRF_EGU_TASK_TRIGGER0);
    
    		IRQ_DIRECT_CONNECT(DT_IRQN(EGU_NODE), 5, egu_handler, 0);
    		nrf_egu_int_enable(NRF_EGU, NRF_EGU_INT_TRIGGERED0);
    		NVIC_EnableIRQ(DT_IRQN(EGU_NODE));
    	} else {
    		cmd_params.task_address = 0;
    		nrf_egu_int_disable(NRF_EGU, NRF_EGU_INT_TRIGGERED0);
    		NVIC_DisableIRQ(DT_IRQN(EGU_NODE));
    	}
    
    	err = hci_vs_sdc_set_event_start_task(&cmd_params);
    	if (err) {
    		printk("Error for command hci_vs_sdc_set_event_start_task(): %s (%d)\n",
    		       strerror(-err), err);
    		return err;
    	}
    
    	printk("Successfully configured event trigger\n");
    
    	return 0;
    }

    Call that function after you have created your Extended Adverisement Set. Create a worker callback function that updates your Advertisement Data by using the function `bt_le_ext_adv_set_data()` every time the event is triggered.

    Note that Extended Advertisements are sent out with a small random delay added to your chosen interval (1 second). If that is a problem you may want to have a look at Periodic Advertising (Bluetooth 5.0). Also Periodic Advertising with Responses (PAwR, Bluetooth 5.4) is a very powerful feature for connecting multiple sensors to one access point.

Children
No Data
Related