I am making a central application which connects to a peripheral and uses Peer Manager. The first time I connect, I have to call pm_conn_secure() to secure the link, basically any time after connecting, but before reading a (protected) characteristic, that works fine.
When the peer has already bonded before, then Peer manager automatically secures the link and I do not have to call pm_conn_secure(). That also works fine with the function commented out. If I call pm_conn_secure() it looks like the security proceduer is executed twice (I get the PM_EVT_CONN_SEC_SUCCEEDED event twice, on the central and on the peripheral).
Now I wonder how to handle these different cases, so that the procedure is executed only once. What would be the best event to start pm_conn_secure() only when needed?