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

sd_ble_gap_connect is throwing an error

Hi 

I am using nrf52832 .i am trying to connect to a device using sd_ble_gap_connect but i am getting NRF_ERROR_INVALID_ADDR error.

i am modifying ble_app_cli to achieve my requirements.

below is the code :

static void ble_evt_handler(ble_evt_t const * p_ble_evt, void * p_context)
{
ret_code_t err_code;

// For readability
ble_gap_evt_t const * p_gap_evt = &p_ble_evt->evt.gap_evt;
nrf_ble_scan_t * p_scan_ctx = (nrf_ble_scan_t *)p_context;
ble_gap_evt_adv_report_t const * p_adv_report = &p_ble_evt->evt.gap_evt.params.adv_report;


switch (p_ble_evt->header.evt_id)
{

case BLE_GAP_EVT_ADV_REPORT:
{

//bool res = device_uuid_search(&p_gap_evt->params.adv_report);

device_to_list_add(&p_gap_evt->params.adv_report);

// For readability.
ble_gap_addr_t const * p_addr = &p_adv_report->peer_addr;
ble_gap_scan_params_t const * p_scan_params = &p_scan_ctx->scan_params;
ble_gap_conn_params_t const * p_conn_params = &p_scan_ctx->conn_params;
uint8_t con_cfg_tag = p_scan_ctx->conn_cfg_tag;
scan_evt_t scan_evt;

con_cfg_tag = p_scan_ctx->conn_cfg_tag;


// Stop scanning.
nrf_ble_scan_stop();

memset(&scan_evt, 0, sizeof(scan_evt));

// Establish connection.
err_code = sd_ble_gap_connect(p_addr,
p_scan_params,
p_conn_params,
con_cfg_tag);

if (err_code == NRF_ERROR_INVALID_ADDR)
{
NRF_LOG_INFO("Connecting not success1"); ///Error occured here
}
if(err_code == NRF_ERROR_INVALID_PARAM)
{
NRF_LOG_INFO("Connecting not success2");
}
if(err_code == NRF_ERROR_NOT_FOUND)
{
NRF_LOG_INFO("Connecting not success3");
}

please suggest me what is wrong.

scan_evt.scan_evt_id = NRF_BLE_SCAN_EVT_CONNECTING_ERROR;
scan_evt.params.connecting_err.err_code = err_code;

NRF_LOG_DEBUG("Connection status: %d", err_code);

// If an error occurred, send an event to the event handler.
if ((err_code != NRF_SUCCESS) && (p_scan_ctx->evt_handler != NULL))
{
p_scan_ctx->evt_handler(&scan_evt);
}
nrf_ble_scan_start(&m_scan);
}
}
break;

Related