Hi,
I have the NRF52 dongle that is set up as the client and is searching using the ble_app_uart_c (Found in examples\ble_central) example and I am trying to connect a bluetooth device to that client and pair them together so that the characteristics of the bluetooth device can be sent to the client.
However, I am not sure how to approach this problem.
Do you think I have to modify the code in the Bluetooth Stack Event in the main.c file?
I have shown the code below.
static void on_ble_evt(ble_evt_t * p_ble_evt)
{
uint32_t err_code;
const ble_gap_evt_t * p_gap_evt = &p_ble_evt->evt.gap_evt;
switch (p_ble_evt->header.evt_id)
{
case BLE_GAP_EVT_ADV_REPORT:
{
const ble_gap_evt_adv_report_t * p_adv_report = &p_gap_evt->params.adv_report;
if (is_uuid_present(&m_nus_uuid, p_adv_report))
{
err_code = sd_ble_gap_connect(&p_adv_report->peer_addr,
&m_scan_params,
&m_connection_param);
if (err_code == NRF_SUCCESS)
{
// scan is automatically stopped by the connect
err_code = bsp_indication_set(BSP_INDICATE_IDLE);
APP_ERROR_CHECK(err_code);
printf("Connecting to target %02x%02x%02x%02x%02x%02x\r\n",
p_adv_report->peer_addr.addr[0],
p_adv_report->peer_addr.addr[1],
p_adv_report->peer_addr.addr[2],
p_adv_report->peer_addr.addr[3],
p_adv_report->peer_addr.addr[4],
p_adv_report->peer_addr.addr[5]
);
}
}
}break; // BLE_GAP_EVT_ADV_REPORT
case BLE_GAP_EVT_CONNECTED:
//NRF_LOG_DEBUG("Connected to target\r\n");
err_code = bsp_indication_set(BSP_INDICATE_CONNECTED);
APP_ERROR_CHECK(err_code);
// start discovery of services. The NUS Client waits for a discovery result
err_code = ble_db_discovery_start(&m_ble_db_discovery, p_ble_evt->evt.gap_evt.conn_handle);
APP_ERROR_CHECK(err_code);
break; // BLE_GAP_EVT_CONNECTED
case BLE_GAP_EVT_TIMEOUT:
if (p_gap_evt->params.timeout.src == BLE_GAP_TIMEOUT_SRC_SCAN)
{
//NRF_LOG_DEBUG("Scan timed out.\r\n");
scan_start();
}
else if (p_gap_evt->params.timeout.src == BLE_GAP_TIMEOUT_SRC_CONN)
{
printf("Connection Request timed out.\r\n");
}
break; // BLE_GAP_EVT_TIMEOUT
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; // BLE_GAP_EVT_SEC_PARAMS_REQUEST
case BLE_GAP_EVT_CONN_PARAM_UPDATE_REQUEST:
// Accepting parameters requested by peer.
err_code = sd_ble_gap_conn_param_update(p_gap_evt->conn_handle,
&p_gap_evt->params.conn_param_update_request.conn_params);
APP_ERROR_CHECK(err_code);
break; // BLE_GAP_EVT_CONN_PARAM_UPDATE_REQUEST
case BLE_GATTC_EVT_TIMEOUT:
// Disconnect on GATT Client timeout event.
//NRF_LOG_DEBUG("GATT Client Timeout.\r\n");
err_code = sd_ble_gap_disconnect(p_ble_evt->evt.gattc_evt.conn_handle,
BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION);
APP_ERROR_CHECK(err_code);
break; // BLE_GATTC_EVT_TIMEOUT
case BLE_GATTS_EVT_TIMEOUT:
// Disconnect on GATT Server timeout event.
//NRF_LOG_DEBUG("GATT Server Timeout.\r\n");
err_code = sd_ble_gap_disconnect(p_ble_evt->evt.gatts_evt.conn_handle,
BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION);
APP_ERROR_CHECK(err_code);
break; // BLE_GATTS_EVT_TIMEOUT
#if (NRF_SD_BLE_API_VERSION == 3)
case BLE_GATTS_EVT_EXCHANGE_MTU_REQUEST:
err_code = sd_ble_gatts_exchange_mtu_reply(p_ble_evt->evt.gatts_evt.conn_handle,
NRF_BLE_MAX_MTU_SIZE);
APP_ERROR_CHECK(err_code);
break; // BLE_GATTS_EVT_EXCHANGE_MTU_REQUEST
#endif
default:
break;
}
}