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

BLE peripheral with multiple centrals and peer manager

Hello,

I am developing application which allows multiple central devices (phones) connect to a single peripheral device (custom board with nRF52840). I took example from /ble_peripheral/experimental/ble_app_multiperipheral as reference for my project. So far I have succeeded in connecting multiple centrals to the board and reading services and characteristics.

Also I need to have one service with public characteristics and another one - with private. I don't use bonding, I use SEC_JUST_WORKS with custom PIN code. Before experimenting with central count, I used module ble_advertising for more simple setup. My app with private, public characteristics was working fine.

Now I use ble setup code from the mentioned example. Using peer manager causes application to crash with code NRF_ERROR_INVALID_STATE on first connection event. How should I setup peer manager to work with multiple centrals?

Here is my current initialization code for peer manager:

static void peer_manager_init(void)
{
    ble_gap_sec_params_t sec_param;
    ret_code_t           err_code;

    err_code = pm_init();
    APP_ERROR_CHECK(err_code);

    memset(&sec_param, 0, sizeof(ble_gap_sec_params_t));

    // Security parameters to be used for all security procedures.
    sec_param.bond           = SEC_PARAM_BOND;
    sec_param.mitm           = SEC_PARAM_MITM;
    sec_param.lesc           = SEC_PARAM_LESC;
    sec_param.keypress       = SEC_PARAM_KEYPRESS;
    sec_param.io_caps        = SEC_PARAM_IO_CAPABILITIES;
    sec_param.oob            = SEC_PARAM_OOB;
    sec_param.min_key_size   = SEC_PARAM_MIN_KEY_SIZE;
    sec_param.max_key_size   = SEC_PARAM_MAX_KEY_SIZE;
    sec_param.kdist_own.enc  = 0;
    sec_param.kdist_own.id   = 0;
    sec_param.kdist_peer.enc = 0;
    sec_param.kdist_peer.id  = 0;

    err_code = pm_sec_params_set(&sec_param);
    APP_ERROR_CHECK(err_code);

    err_code = pm_register(pm_evt_handler);
    APP_ERROR_CHECK(err_code);
}
 

Parents
  • Hi

    If you see our examples using this bonding they all use key distribution, but you are not. Could you please try replacing the 0 in the kdist functions with a 1?

    sec_param.kdist_own.enc  = 1;
    sec_param.kdist_own.id   = 1;
    sec_param.kdist_peer.enc = 1;
    sec_param.kdist_peer.id  = 1;

    Best regards,

    Simon

  • Hello Simon,

    Thank you for your reply. I don't use key distribution because I don't need device bonding. In my use case scenario I want users to type pin code for each connection when they intend to access protected characteristics. (Pin code changes after each disconnect event)

    Actually it looks like I found the cause of my problem. I took ble event handler code from the ble_app_multiperipheral example. And it had following lines: 

    case BLE_GAP_EVT_SEC_PARAMS_REQUEST:
        // Pairing not supported
        err_code = sd_ble_gap_sec_params_reply(p_ble_evt->evt.gap_evt.conn_handle,
                                               BLE_GAP_SEC_STATUS_PAIRING_NOT_SUPP,
                                               NULL,
                                               NULL);
        APP_ERROR_CHECK(err_code);
        break;

    I didn't have handling for BLE_GAP_EVT_SEC_PARAMS_REQUEST previously, and I just missed this part when I moved to ble_app_multiperipheral . So I just removed them and pairing now works fine.

  • Great job! Glad you found a solution.

    Best regards,

    Simon

Reply Children
No Data
Related