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

Only one device is getting paired with nrf51422

I have read the previous questions regarding the above subject, i found that changing the maximum bonding devices limit defined in device_manager_cnfg.h will work, but it did not worked for me. I have edited the ble_app_uart example code to support passkey pairing.

I also found the bounding info is stored in flash memory. So I erased the flash and reprogrammed it but still it is pairing with only that device which was paired before erasing flash. Kindly help to fix this

iam attaching my project file, kindly find the same.nRF_DK.rar

Thanks in advance, Sunil Kumar

  • static void gap_params_init(void) { uint32_t err_code; ble_gap_conn_params_t gap_conn_params; ble_gap_conn_sec_mode_t sec_mode;

        BLE_GAP_CONN_SEC_MODE_SET_OPEN(&sec_mode);
        
        err_code = sd_ble_gap_device_name_set(&sec_mode,
                                              (const uint8_t *) DEVICE_NAME,
                                              strlen(DEVICE_NAME));
        APP_ERROR_CHECK(err_code);
    
        memset(&gap_conn_params, 0, sizeof(gap_conn_params));
    
        gap_conn_params.min_conn_interval = MIN_CONN_INTERVAL;
        gap_conn_params.max_conn_interval = MAX_CONN_INTERVAL;
        gap_conn_params.slave_latency     = SLAVE_LATENCY;
        gap_conn_params.conn_sup_timeout  = CONN_SUP_TIMEOUT;
    
        err_code = sd_ble_gap_ppcp_set(&gap_conn_params);
        APP_ERROR_CHECK(err_code);
                                              
        //Static key implementation                                                                                     STATIC KEY IMPLEMENTATION
        m_static_pin_option.gap_opt.passkey.p_passkey = &passkey[0];
        err_code_temp = sd_ble_opt_set(BLE_GAP_OPT_PASSKEY, &m_static_pin_option);
        APP_ERROR_CHECK(err_code_temp);                                            
    }
    
  • static void on_ble_evt(ble_evt_t * p_ble_evt) { uint32_t err_code;

    switch (p_ble_evt->header.evt_id)
    {
        case BLE_GAP_EVT_CONNECTED:
            err_code = bsp_indication_set(BSP_INDICATE_CONNECTED);
            APP_ERROR_CHECK(err_code);
            m_conn_handle = p_ble_evt->evt.gap_evt.conn_handle;
            xl_appl_send_rtc_time();
            xl_isconnectec_to_app_b = true;
            send_active_event_num_flag_b = true;
            break;
        case BLE_GAP_EVT_DISCONNECTED:
            err_code = bsp_indication_set(BSP_INDICATE_IDLE);
            APP_ERROR_CHECK(err_code);
            m_conn_handle = BLE_CONN_HANDLE_INVALID;
    
            xl_isconnectec_to_app_b = false;
            break;
    
        case BLE_GAP_EVT_SEC_PARAMS_REQUEST:
            // Pairing not supported       
           
      //      sec_param_ret = sd_ble_gap_sec_params_reply(m_conn_handle, BLE_GAP_SEC_STATUS_BR_EDR_IN_PROG,&register_param.sec_param , &p_sec_keyset);
            APP_ERROR_CHECK(sec_param_ret);
            break;
        case BLE_GATTS_EVT_SYS_ATTR_MISSING:
           //  No system attributes have been stored.
            err_code = sd_ble_gatts_sys_attr_set(m_conn_handle, NULL, 0, 0);
            APP_ERROR_CHECK(err_code);
            break;
    
        case BLE_GAP_EVT_AUTH_KEY_REQUEST:
            sd_ble_gap_auth_key_reply(m_conn_handle,BLE_GAP_AUTH_KEY_TYPE_PASSKEY,passkey);
        break;//todo: PASSKEY
        
        case BLE_GAP_EVT_PASSKEY_DISPLAY:{
                 //       memcpy(passkey1, p_ble_evt->evt.gap_evt.params.passkey_display.passkey, PASSKEY_LENGTH);
                //        passkey1[PASSKEY_LENGTH] = 0;
                 //       break;
            }
        default:
            // No implementation needed.
            break;
    }
    

    }

  • static void ble_evt_dispatch(ble_evt_t * p_ble_evt) {

        dm_ble_evt_handler(p_ble_evt); 
        ble_conn_params_on_ble_evt(p_ble_evt);
        ble_bas_on_ble_evt(&m_bas, p_ble_evt);
        ble_nus_on_ble_evt(&m_nus, p_ble_evt);
        //bsp_btn_ble_on_ble_evt(p_ble_evt);
    
        #ifdef BLE_DFU_APP_SUPPORT
        /** @snippet [Propagating BLE Stack events to DFU Service] */
        ble_dfu_on_ble_evt(&m_dfus, p_ble_evt);
        /** @snippet [Propagating BLE Stack events to DFU Service] */
        #endif // BLE_DFU_APP_SUPPORT
        on_ble_evt(p_ble_evt);
        ble_advertising_on_ble_evt(p_ble_evt);
    }
    
  • static uint32_t device_manager_evt_handler(dm_handle_t const * p_handle, dm_event_t const * p_event, ret_code_t event_result) {

        APP_ERROR_CHECK(event_result);
    
        #ifdef BLE_DFU_APP_SUPPORT
        if (p_event->event_id == DM_EVT_LINK_SECURED)
        {
            app_context_load(p_handle);
        }
        #endif // BLE_DFU_APP_SUPPORT
    
        return NRF_SUCCESS;
    }
    
  • static void device_manager_init(bool erase_bonds) { uint32_t err_code; dm_init_param_t init_param = {.clear_persistent_data = erase_bonds}; dm_application_param_t register_param;

    // Initialize persistent storage module.
    err_code = pstorage_init();
    APP_ERROR_CHECK(err_code);
    
    err_code = dm_init(&init_param);
    APP_ERROR_CHECK(err_code);
    
    memset(&register_param.sec_param, 0, sizeof(ble_gap_sec_params_t));
    
    register_param.sec_param.bond         = SEC_PARAM_BOND;
    register_param.sec_param.mitm         = SEC_PARAM_MITM;
    register_param.sec_param.io_caps      = SEC_PARAM_IO_CAPABILITIES;
    register_param.sec_param.oob          = SEC_PARAM_OOB;
    register_param.sec_param.min_key_size = SEC_PARAM_MIN_KEY_SIZE;
    register_param.sec_param.max_key_size = SEC_PARAM_MAX_KEY_SIZE;
    register_param.evt_handler            = device_manager_evt_handler;
    register_param.service_type           = DM_PROTOCOL_CNTXT_GATT_SRVR_ID;
    
    err_code = dm_register(&m_app_handle, &register_param);
    APP_ERROR_CHECK(err_code);
    

    }

Related