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

Pairing mode - Disable bonded connections and allow non-bonded only

Hi,

I’m developing an application using the SDK V16 , the nRF52DK (52832) as central, and a couple of Sparkfun nRF52832 breakout boards as peripherals (both peripherals behave the same way).

I have right now a central system that deletes bonds at the start of the program and scans for my Custom Service UUID. The other boards are peripherals advertising the custom service and waiting for connection.

When a connection is stablished the devices bond, the devices exchange some information, the central disconnect, and following the central starts scanning applying a whitelist.

I want to have a “pairing mode” where I can disable the whitelist and scan using the Custom UUID filter for other peripherals, but I want to avoid connecting to devices that I have already bonded with.

My question is:

  • Is it possible to set up a paring mode that can scan for devices with a filter for my Custom Service UUID but avoid any connection that is already whitelisted/bonded? If so, are there parameter to look for only non-bonded devices or do I have to disconnect at some point during the scan, db discovery and connection process?

I though I could stop scan mid connection process when I receive the NRF_BLE_SCAN_EVT_FILTER_MATCH event if the peer address is already whitelisted, but that did not have any good outcome.  Something similar to this question https://devzone.nordicsemi.com/f/nordic-q-a/21453/how-to-temporarily-disable-the-already-bonded-peers-but-allow-new-peer-to-bond but as is a post from 3 years ago, has it been implemented a better way to do this?

My bonding part of my project is based on hrs example. Any extra information or specific code please let me know.

Thanks,

Parents
  • Hello,

    So what you want is basically a blacklist, right? This is not something that is part of the softdevice, but it is possible to do something like this from your application

    What you have to do is to disable the whitelist when you want to scan for new devices.

    When you scan without a whitelist, you will get all the advertising reports in the event called BLE_GAP_EVT_ADV_REPORT. It is this event in nrf_ble_scan.c that usually decides whether or not to connect. You can see there is a lot of filter stuff in the nrf_ble_scan_on_adv_report() function called in this event. It boils down to setting is_filter_matched = true or false. 

    So if you are looking for a particular UUID you can use this filter as before. Look inside the function nrf_ble_scan_connect_with_target() function. You see there is a p_scan_ctx->connect_if_match. If this is set to true, it will try to connect. See if you can use this to not connect automatically, but check the address, whether it is present in the whitelist (that is currently not active) before you call sd_ble_gap_connect.

    As a helper, you see that this function (nrf_ble_scan_on_adv_report()) will also generate the event NRF_BLE_SCAN_EVT_FILTER_MATCH() that is forwarded to the p_scan_ctx->evt_handler. Use this event to see only devices that has a filter match, and then decide whether you want to connect or not.

    Best regards,

    Edvin

  • Hi Edvin,

    I solved the problem. First I did was to disable the connect_if_match during the scan_init() function.

    Then I was able to use sd_ble_gap_connect() during the NRF_BLE_SCAN_EVT_FILTER_MATCH and NRF_BLE_SCAN_EVT_WHITELIST_ADV_REPORT depending if I have the whitelist active or not and if the MAC address scanned is in the whitelist or not.

    Thanks for the help

Reply Children
No Data
Related