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

Difference between scan_evt_handler and ble_evt_handler, impact of a Whitelist

I am trying to read Manufacturer Specific Data from a non-connectable advertisement packet from a pressure sensor.

I followed the example in https://devzone.nordicsemi.com/f/nordic-q-a/38475/how-can-i-get-manufacturer-specific-data-in-central-with-advertising-packet-sdk15-nrf52832

and used the HRS collector example from the SDK as a base. In my use case there is also a HRS to which the Central will connect to for which a Whitelist might be used.

I wondered why not to implement the decoding of the pressure sensor in the scan_evt_handler instead of the ble_evt_handler.

- What is exactly the difference between the ble_evt_handler and the scan_evt_handler? When does each one get called, are they both called for one packet? And where should I implement functions like the one decoding the Manufacturer Specific Data?

- The Code I will be using has a Whitelist on which "peers" like the HRS will be added with the function "pm_whitelist_get". But as I understood it, the pressure sensor is not a "peer" since its non-connected. Does this mean its packet will no longer be scanned for? Or does it just mean the scan_evt_handler gets called with the report in "scan_evt.params.p_not_found"? Or does only the ble_evt_handler get called?

Thank you very much for any help!

  • Hello,

    The ble_evt_handler() and scan_evt_handler() are a bit different, because the ble_evt_handler() receives events directly from the softdevice, while the scan_evt_handler()'s events are generated by the application (nrf_ble_scan.c). 

    Basically, the nrf_scan_handler is more related to some scan events, such as scan started, scan stopped, filter matched, and so on, while all the advertising packets generate events called BLE_GAP_EVT_ADV_REPORT which is usually handled in the nrf_ble_scan_on_ble_evt() in nrf_ble_scan.h. You could handle (or duplicate) these events in the ble_evt_handler as well, as these receive the same events. Look at how the nrf_ble_scan_on_ble_evt() in nrf_ble_scan.c is generating events for scan_evt_handler(), and how it handles the advertisement packets in the BLE_GAP_EVT_ADV_REPORT events.

    Best regards,

    Edvin

  • Thank you for the explanations.

    For the second question concerning the whitelist: From here  I understood that when using a whitelist, the filtering is performed by hardware and nrf_ble_scan_on_ble_evt() is only called when the scanned packet is from a device on the whitelist.

    -> But what about ble_evt_handler() does it still get called for packets that are NOT on the whitelist? In my application I am using a whitelist but would like to receive ADV_NONCONN_IND packets at the same time. Is this possible

  • It is correct that the whitelist is using hardware to filter the incoming advertisements/connection requests.

    I don't remember whether or not the whitelist is the same for the advertising and the scanning. I guess you can experiment with that. Look at some examples that uses the whitelist.

    peripheral/advertiser: ble_app_gls

    central/scanner: ble_app_hrs_c

    If you are scanning with a whitelist, then you will not get advertisement events from devices not in your whitelist. If you want that, you need to disable the whitelist.

    If you think of it, if you want advertisements from all devices, is there really a point in using a whitelist?

    In my opinion, the only real reason to use a whitelist is when you are advertising, and you know that you only want to connect to a known device, which is in your whitelist. It is always the central/scanner who initiates connections, so the only difference between scanning with and without a whitelist is that you will get more advertising report events when you don't use a whitelist.

    Best regards,

    Edvin

Related