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

BLE Scan with filtering - how to get the content of filtered advertisement messages

Hello guys,

We are performing BLE Scan with filtering by using the device name as a filter.

We are aware of the following facts:

  1. All the advertising packets will be forwarded to the application from the SoftDevice. Not only advertising packets from filtered devices (link).
  2. When advertising packet is received, BLE_GAP_EVT_ADV_REPORT BLE event is triggered (link). Advertising data can be extracted from  p_ble_evt->evt.gap_evt.params.adv_report.data structure.
  3. When scan filter matches, NRF_BLE_SCAN_EVT_FILTER_MATCH scan event is triggered inside scan_evt_handler() function (link).

Now, in our application code, we would like to extract the content only of the advertising packets that match the scan filter (i.e. advertisement packets from BLE devices with particular name).

How can we actually do it? We can successfully detect both BLE_GAP_EVT_ADV_REPORT and NRF_BLE_SCAN_EVT_FILTER_MATCH events but what is the connection between those? Should I set some flag when NRF_BLE_SCAN_EVT_FILTER_MATCH event occurs and extract advertisement data when next BLE_GAP_EVT_ADV_REPORT event happens?

Thanks in advance for your time and efforst.

Cheers,

Bojan.

Parents
  • Hello Bojan,

    The the adv. report pointer is included in the event structure for the NRF_BLE_SCAN_EVT_FILTER_MATCH event, so you don't need to handle the "unfiltered"  BLE_GAP_EVT_ADV_REPORT event separately. I've tried to illustrate this with the code snippet below. Let me know if something is still unclear.

    static void scan_evt_handler(scan_evt_t const * p_scan_evt)
    {
        ret_code_t err_code;
    
        switch(p_scan_evt->scan_evt_id)
        {
            case NRF_BLE_SCAN_EVT_FILTER_MATCH:
             {
                 ble_gap_evt_adv_report_t const * p_adv_report;
                 
                adv. report from a device that passed the filter criteria
                 p_adv_report = p_scan_evt->params.filter_match.p_adv_report;
                 
                 //TODO: parse adv report data with "Advertising data encoder" module. Ref. https://infocenter.nordicsemi.com/topic/sdk_nrf5_v17.0.2/group__ble__sdk__lib__advdata.html
             }
             break;
        ...
    ...

    Cheers,

    Vidar

  • Thank you very much, !

    The explanation seems pretty clear. Let me try to implement and see if I face any obstacle.

    Cheers!

Reply Children
No Data
Related