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

How to only allow a maximum of one bonded connection

If I only wanted to allow one bond at a time, how could I do this?

For example when someone connects for the first time they would pair and bond, by entering the passkey. If someone else wanted to pair and bond, the previous person who bonded should be deleted from the nRF side.

I know there are the two functions for deleting peers pm_peer_delete() / pm_peers_delete(). The problem is the previous peer should only be deleted, only after the new peer has paired and bonded, by typing in the correct passkey.

How would I go about implementing this? I don't know if there's somewhere that I can change the total number of allowed bonded connections (to 1), or if I would have to delete the previous peer using pm_peer_delete.

Parents
  • Hi,

    The peer manager itself does not support a hard limit of the number of connections, so you need to do what you describe. After the second peer is bonded, delete the bond for the first (oldest) peer. 

    In practice, this involves using pm_peer_delete() as you write, and calling it with the ID of that peer. There are several way you could do this. Either obtain the peer ID that you do not want to delete. The most robust would probably be to use pm_peer_ranks_get(), to get the ID of the peer that has not been seen for the longest and delete it. Or in case you risk ending up in a state with more bonds and want to avoid it, use the same function to get the ID of the most recently seen peer, and keep that, but delete all others (which you get a list of with pm_peer_id_list()). There are also other possible approaches, as you can get a lot of information from the peer manager (take a look at peer_manager.h).

Reply
  • Hi,

    The peer manager itself does not support a hard limit of the number of connections, so you need to do what you describe. After the second peer is bonded, delete the bond for the first (oldest) peer. 

    In practice, this involves using pm_peer_delete() as you write, and calling it with the ID of that peer. There are several way you could do this. Either obtain the peer ID that you do not want to delete. The most robust would probably be to use pm_peer_ranks_get(), to get the ID of the peer that has not been seen for the longest and delete it. Or in case you risk ending up in a state with more bonds and want to avoid it, use the same function to get the ID of the most recently seen peer, and keep that, but delete all others (which you get a list of with pm_peer_id_list()). There are also other possible approaches, as you can get a lot of information from the peer manager (take a look at peer_manager.h).

Children
No Data
Related