This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Added Peer Manage to ble_app_blinky

Hi All,

I want to add pairing and binding functions to the blinky project.

But nothing happens when I connect.

Please help me,thank you.

Here is my project => Lab10_PeerManager_pairing.zip

I'm using SDK v17.1.0

Best regards,

Kai

Parents
  • Hi Kai,

    I had a biref look at your project and see one issue that is clearly incorrect. In your handling of the BLE_GAP_EVT_SEC_PARAMS_REQUEST you reply that pairing is not supported. You need to remove this. In fact, there is no need to handle this event at all, as it is handled by the peer manger library.

    Einar

Reply
  • Hi Kai,

    I had a biref look at your project and see one issue that is clearly incorrect. In your handling of the BLE_GAP_EVT_SEC_PARAMS_REQUEST you reply that pairing is not supported. You need to remove this. In fact, there is no need to handle this event at all, as it is handled by the peer manger library.

    Einar

Children
  • Hi Einar,

    Finally I refer to the example of gls.

    I observed that pairing needs to use these few lines of code =>

    err_code = pm_conn_secure(p_ble_evt->evt.gap_evt.conn_handle, false);
                if (err_code != NRF_ERROR_BUSY)
                {
                    APP_ERROR_CHECK(err_code);
                }

    Now I have two questions : 1. why bps example does not use this API.

                                                2. My program has a pairing function after adding that API, but the phone will jump 2 times to                                                      notify before it can be connected.

    Best regards,

    Kai

  • Hi Einar,

    Is there any news?

  • Hi,

    I am sorry for the late reply (there has been Easter holiday in Norway so DevZone has had reduced staffing).

    kai19960504 said:
    1. why bps example does not use this API.

    The call to pm_conn_secure() ins used to initiate security on the link, either pairing if it is the first time, or just encrypting the link if an old bond exists. If the peer initiates security (which is often the case if it is for instance a mobile phone), then this is not needed.

    kai19960504 said:
    2. My program has a pairing function after adding that API, but the phone will jump 2 times to                                                      notify before it can be connected.

    I do not full understand what this is. Can you elaborate?

  • Hi Einar,

    I do not full understand what this is. Can you elaborate?

    I think you can refer to my current project and actually connect with the mobile phone to see what I mean.

    Projects to be tested => 7652.Lab10_PeerManager_pairing.zip

    Another problem is that when I remove the lines of main.c (509~513), the pairing function will not work.

    // Kai
    err_code = pm_conn_secure(p_ble_evt->evt.gap_evt.conn_handle, false);
    if (err_code != NRF_ERROR_BUSY)
    {
        APP_ERROR_CHECK(err_code);
    }
    // Kai

    Best regards,

    Kai

  • Hi Kai,

    I tested your project briefly (just connecting and pairing) and that seems to work as expected. With the unmodified project, I connect, and then the nRF initiates pairing and that proceeds successfully when I test with an iPhone with the nRF Connect app.

    After commenting out the call to pm_conn_secure() the nRF no longer initiates pairing, so that is now up to the central. iOS only pairs when needed (after not being allowed to access a characteristic due to too low security level). So in order to make the iPhone pair I did a small change to your LBS service so that reading or writing to the button or LED requires security, and thus makes the iPhone pair:

    diff --git a/ble_lbs/ble_lbs.c b/ble_lbs/ble_lbs.c
    index f2a72f9..c255ede 100644
    --- a/ble_lbs/ble_lbs.c
    +++ b/ble_lbs/ble_lbs.c
    @@ -107,8 +107,8 @@ uint32_t ble_lbs_init(ble_lbs_t * p_lbs, const ble_lbs_init_t * p_lbs_init)
         add_char_params.char_props.read   = 1;
         add_char_params.char_props.notify = 1;
     
    -    add_char_params.read_access       = SEC_OPEN;
    -    add_char_params.cccd_write_access = SEC_OPEN;
    +    add_char_params.read_access       = SEC_JUST_WORKS;
    +    add_char_params.cccd_write_access = SEC_JUST_WORKS;
     
         err_code = characteristic_add(p_lbs->service_handle,
                                       &add_char_params,
    @@ -127,8 +127,8 @@ uint32_t ble_lbs_init(ble_lbs_t * p_lbs, const ble_lbs_init_t * p_lbs_init)
         add_char_params.char_props.read  = 1;
         add_char_params.char_props.write = 1;
     
    -    add_char_params.read_access  = SEC_OPEN;
    -    add_char_params.write_access = SEC_OPEN;
    +    add_char_params.read_access  = SEC_JUST_WORKS;
    +    add_char_params.write_access = SEC_JUST_WORKS;
     
         return characteristic_add(p_lbs->service_handle, &add_char_params, &p_lbs->led_char_handles);
     }
    

    (This change is not needed when using Android or nRF Connect for Desktop, where you can force pairing as you like).

Related