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

How to add bond function to SDK12.3.0\app_ble_uart


Hi,
I am trying to add numeric comparison function to the project nRF5_SDK_12.3.0_d7731ad\examples\ble_peripheral\app_ble_uart\pca10028\s130.
in the project, there is no support for bonding.so i added the fds and peer_manager reference to the project app_ble_hrs. but there are something wrong with my code.
 
i was modified ble_evt_dispatch :
static void ble_evt_dispatch(ble_evt_t * p_ble_evt)
{
    ble_conn_params_on_ble_evt(p_ble_evt);
    ble_nus_on_ble_evt(&m_nus, p_ble_evt);
    on_ble_evt(p_ble_evt);
    ble_advertising_on_ble_evt(p_ble_evt);
    //bsp_btn_ble_on_ble_evt(p_ble_evt);
    pm_on_ble_evt(p_ble_evt);
    
    dbgPrint("evt id = %d\n", p_ble_evt->header.evt_id);//testonly
}

i printed the ble_evt_id in ble_evt_dispatch() as follows:
 connected
 evt id = 16
 evt id = 18
 evt id = 18
 evt id = 18
 evt id = 19//BLE_GAP_EVT_SEC_PARAMS_REQUEST
 evt id = 18
 disconnected//out of 30 seconds so the link has been disconnected
 evt id = 17
 
by debug i found there is a error in pm_evt_handler() {case PM_EVT_ERROR_UNEXPECTED:},i don't know why this error occurs.
can i get an example of app_ble_uart with bond function?

any sugestions would be helpful.
Best Regards.

Parents
  • Hi,

    There are quite a few things you need to remember when adding the peer manager to a project. It is difficult to know exactly what you have done without seeing more of your code, but you can use this modified ble_app_uart example (sdk_12.3_ble_app_uart_with_bonding.zip), which adds bonding support using the peer manager as well as logging (using RTT backend).

  • Hi Einar,

    Thank you for your help.it is very useful!
    I used the project you modified,and modified some code to trigger the pairing (shown PIN and confirmed on the device side,shown PIN only on the cellphone, i.e. numeric comparison) when I turned on the notify.

    1,changed the function rx_char_add(),use BLE_GAP_CONN_SEC_MODE_SET_ENC_WITH_MITM(&cccd_md.write_perm);instead of BLE_GAP_CONN_SEC_MODE_SET_OPEN(&cccd_md.write_perm);

    2,changed some micro defines
    #define SEC_PARAM_BOND                   1                                           /**< Perform bonding. */
    #define SEC_PARAM_MITM                   1                                           /**< Man In The Middle protection required. */
    #define SEC_PARAM_LESC                   1                                           /**< LE Secure Connections enabled. */
    #define SEC_PARAM_KEYPRESS               0                                           /**< Keypress notifications not enabled. */
    #define SEC_PARAM_IO_CAPABILITIES        BLE_GAP_IO_CAPS_DISPLAY_YESNO                        /**< have display and key to confirm. */
    #define SEC_PARAM_OOB                    0                                           /**< Out Of Band data not available. */
    #define SEC_PARAM_MIN_KEY_SIZE           7                                           /**< Minimum encryption key size. */
    #define SEC_PARAM_MAX_KEY_SIZE           16                                          /**< Maximum encryption key size. */

    3,add NRF_LOG_INFO("evt_id = %d\r\n", p_ble_evt->header.evt_id) in ble_evt_dispatch()

    and the LOG_INFO is:
    0> APP:INFO:NUS example started!
    0> APP:INFO:Connected to a previously bonded device.
    0> APP:INFO:Connected.
    0> APP:INFO:evt_id = 16
    0> APP:INFO:evt_id = 18
    0> APP:INFO:evt_id = 18
    0> APP:INFO:evt_id = 18
    //now open the notify
    0> APP:INFO:evt_id = 19
    0> APP:INFO:evt_id = 25
    0> APP:INFO:evt_id = 18
    0> APP:INFO:Disconnected.
    0> APP:INFO:evt_id = 17
    0>

    Then i connect the device and open the notify again.the LOG_INFO is
    0> APP:INFO:Connected to a previously bonded device.
    0> APP:INFO:Connected.
    0> APP:INFO:evt_id = 16
    0> APP:INFO:evt_id = 18
    0> APP:INFO:evt_id = 18
    //now open the notify
    0> APP:INFO:evt_id = 19
    0> APP:INFO:evt_id = 21
    0> APP:INFO:evt_id = 18
    0> APP:INFO:evt_id = 25
    0> APP:INFO:Disconnected.
    0> APP:INFO:evt_id = 17
    0>
    and there a pairing window poped on the cellphone, not the numeric comparison but the passkey entry.
    how can i make the pairing as numeric comparison?

Reply
  • Hi Einar,

    Thank you for your help.it is very useful!
    I used the project you modified,and modified some code to trigger the pairing (shown PIN and confirmed on the device side,shown PIN only on the cellphone, i.e. numeric comparison) when I turned on the notify.

    1,changed the function rx_char_add(),use BLE_GAP_CONN_SEC_MODE_SET_ENC_WITH_MITM(&cccd_md.write_perm);instead of BLE_GAP_CONN_SEC_MODE_SET_OPEN(&cccd_md.write_perm);

    2,changed some micro defines
    #define SEC_PARAM_BOND                   1                                           /**< Perform bonding. */
    #define SEC_PARAM_MITM                   1                                           /**< Man In The Middle protection required. */
    #define SEC_PARAM_LESC                   1                                           /**< LE Secure Connections enabled. */
    #define SEC_PARAM_KEYPRESS               0                                           /**< Keypress notifications not enabled. */
    #define SEC_PARAM_IO_CAPABILITIES        BLE_GAP_IO_CAPS_DISPLAY_YESNO                        /**< have display and key to confirm. */
    #define SEC_PARAM_OOB                    0                                           /**< Out Of Band data not available. */
    #define SEC_PARAM_MIN_KEY_SIZE           7                                           /**< Minimum encryption key size. */
    #define SEC_PARAM_MAX_KEY_SIZE           16                                          /**< Maximum encryption key size. */

    3,add NRF_LOG_INFO("evt_id = %d\r\n", p_ble_evt->header.evt_id) in ble_evt_dispatch()

    and the LOG_INFO is:
    0> APP:INFO:NUS example started!
    0> APP:INFO:Connected to a previously bonded device.
    0> APP:INFO:Connected.
    0> APP:INFO:evt_id = 16
    0> APP:INFO:evt_id = 18
    0> APP:INFO:evt_id = 18
    0> APP:INFO:evt_id = 18
    //now open the notify
    0> APP:INFO:evt_id = 19
    0> APP:INFO:evt_id = 25
    0> APP:INFO:evt_id = 18
    0> APP:INFO:Disconnected.
    0> APP:INFO:evt_id = 17
    0>

    Then i connect the device and open the notify again.the LOG_INFO is
    0> APP:INFO:Connected to a previously bonded device.
    0> APP:INFO:Connected.
    0> APP:INFO:evt_id = 16
    0> APP:INFO:evt_id = 18
    0> APP:INFO:evt_id = 18
    //now open the notify
    0> APP:INFO:evt_id = 19
    0> APP:INFO:evt_id = 21
    0> APP:INFO:evt_id = 18
    0> APP:INFO:evt_id = 25
    0> APP:INFO:Disconnected.
    0> APP:INFO:evt_id = 17
    0>
    and there a pairing window poped on the cellphone, not the numeric comparison but the passkey entry.
    how can i make the pairing as numeric comparison?

Children
Related