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

PM_EVT_CONN_SEC_SUCCEEDED twice in every connection

Hello,

I'm using a custom board with nrf52 using sdk12.1 and SD132 v3.0.0. and the nordic's nus peripheral service.

I am able able to read and send data without any problem, but now I am experimenting a weird situation:

Every time the central (android app) connects with the custom board I have some sensor setting to do, after this setting have finished the custom board sends a "ready" message to the app. The problem is that the "ready" message is being received twice by the app the first connection after power on, afterwards, the following connections the message is received only once.

I set the flags to perform the notification inside the peer manager event handler, concretely inside the case PM_EVT_CONN_SEC_SUCCEEDED:

case PM_EVT_CONN_SEC_SUCCEEDED:
    {
        /*Check if the link is authenticated (meaning at least MITM)*/
        pm_conn_sec_status_t conn_sec_status;
        err_code = pm_conn_sec_status_get(p_evt->conn_handle, &conn_sec_status);
        APP_ERROR_CHECK(err_code);
        if (!conn_sec_status.mitm_protected)
        {
            /*The peer did not use MITM, disconnect*/
            err_code = pm_peer_id_get(m_conn_handle, &peer_to_be_deleted);
            APP_ERROR_CHECK(err_code);
            err_code = sd_ble_gap_disconnect(m_conn_handle,
                                             BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION);
            APP_ERROR_CHECK(err_code);
        }
        else
        {
            err_code = pm_peer_rank_highest(p_evt->peer_id);
            if (err_code == NRF_SUCCESS)
            {
           //SET NOTIFICATION FLAGS							
               mode_act+=14; //Indicate device ready to app.
								
            }
							
							
        }
    } break; // PM_EVT_CONN_SEC_SUCCEEDED

I debug the code and the notificiation flags are being enabled twice in every connection . Also, ble_nus_string_send(...) with the "ready" message is executed twice in every connection with NRF_SUCCES return but only sent twice in the first connection. After this message the following interactions with the app work properly.

Why the peer manager does twice the same event in the same connection?

I hope you folks can help me out.

Related