Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs

BLE connect state to adv state

I use the nRF5 SDK for BLE peripheral development based on a keyboard example. After the peripheral connects and bonds with a central device, I can detect button presses. I want pressing a button to switch the peripheral back to advertising mode. How should I do this? Should I first call sd_ble_gap_disconnectto disconnect, and then directly call advertising_init()and advertising_start()?
I am encountering an issue: as a peripheral, after bonding with a central device, I unilaterally cleared the whitelist. However, when the peripheral re-enters pairing mode, the central device keeps attempting to connect and bond, causing the peripheral to repeatedly connect and then disconnect. How can I avoid this problem? The desired outcome is to prevent connection attempts from this specific central device while still allowing other central devices to scan and connect to the device.

  • Hi,

    For the third question, use a whitelist during advertising and control which bonded devices are allowed. So yes, it limits the scope of who can connect.

    What the whitelist does:

    When a phone/PC first bonds with your device, the Peer Manager stores it and its given a peer ID. From these, you build the whitelist by using pm_whitelist_set(peer_ids, n_peer_ids).

    Then, when advertising uses the whitelist, only devices in this list can connect in fast/slow advertising modes. This works for Windows, iOS, Android, Mac. To combine "pair with any device" + whitelist, there are 2 modes you can use: Normal mode (Whitelist ON) and Pairing Mode. In normal mode, build a whitelist from all peer IDs you want to allow. when advertising module sends BLE_ADV_EVT_WHITELIST_REQUEST, you can then call pm_whitelist_get() and then ble_advertising_whitelist_reply() in order to apply it. This way, only bonded devices are able to reconnect. In pairing mode, you can temporarily turn off whitelist for one connection when you want to pair with a new phone/PC. This way, any Windows/iOS /Android/Mac device will be able to connect and bond once. Advertising automatically will go back to using whitelist after connection ends. When you enter "pairing mode", you can pair with any mainstream OS. Each device after bonding gets a peerID and can be allowed in the whitelist or blocked out. 

    Question about alternative approach:

    Our docs only mention whitelist advertising and disconnecting after connect so there's no mentioned way to inspect and reject a connection. You have to let the connection happen and call sd_ble_gap_disconnect() for dropping it. The only way you can block one specific host is by using peer manger in order to manage bonded peers. Then build a whitelist which does not contain that host's peer ID. After that, enable whitelist advertising. 

    Best Regards,

    Samruddhi

  • “”Our docs only mention whitelist advertising and disconnecting after connect so there's no mentioned way to inspect and reject a connection. You have to let the connection happen and call sd_ble_gap_disconnect() for dropping it. The only way you can block one specific host is by using peer manger in order to manage bonded peers. Then build a whitelist which does not contain that host's peer ID. After that, enable whitelist advertising. “”
    Thank you. You mentioned that if I want to pair a new device while blocking connection requests from the host that still has this slave device on its whitelist, I should enable whitelist broadcasting, remove this device from the whitelist, and include the new device instead. My question is, how can I determine the whitelist of the peer device I want to pair with? Since the peer device could be any Windows or Mac computer, I’m unsure how to define the scope of my whitelist while also excluding devices I don’t want to reconnect to.
  • Hi,

    Apologies for the delay. The solution here would be to keep advertising without use of whitelist. Then when the device connects, check its Bluetooth address. If the device is the one you want to block, disconnect it right away. By doing this, one host gets blocked and the other Windows/MAC/iOS/ Android devices can pair normally. It is not possible to read the whitelist of any Windows or MAC device as it is private to the host and due to this it can't be accessed by a BLE peripheral and you can't design your own whitelist to match the host's whitelist or to decide which hosts are allowed. 

    Best Regards,

    Samruddhi

Related