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

connect a device and disconnect and try to connect another ,cannot connect

hi ,

   I'm a newer ,  using nRF5_SDK_15.3.0_59ac345. we are using nrf52832 to get about 100 of heart rate sensors.

so first we do a scan ,and get all of  there addrs. and than ,try to connect one ,get hrs value and disconnect this one, and connect next one .

but Unfortunately , when disconnected successfully, connect next one will no success.

  here is our code ,   <disconnect_current_addr> be called when events of BLE_HRS_C_EVT_HRM_NOTIFICATION happened.

and when BLE_GAP_EVT_DISCONNECTED happened, call <connect_current_addr> to connect next one.

void connect_current_addr(void)
{
int ret;
ret_code_t err_code;
scan_evt_t scan_evt;

// For readability.
ble_gap_addr_t peer_addr;

// Stop scanning.
nrf_ble_scan_stop();
DBGPRINT(DEBUG_TRACE,"connect_current_addr ++ \n");

ret = GetNextActiveAddr(&peer_addr);

if(ret != 0)
{
DBGPRINT(DEBUG_ERROR,"No active device !\n");
return;
}

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

// Establish connection.
err_code = sd_ble_gap_connect(&peer_addr,
&m_scan_param,
&m_conn_params,
1);

// DBGPRINT(DEBUG_TRACE,"Connecting\n");
DBGPRINT(DEBUG_TRACE,"Connecting: %02X:%02X:%02X:%02X:%02X:%02X\n",
peer_addr.addr[5],
peer_addr.addr[4],
peer_addr.addr[3],
peer_addr.addr[2],
peer_addr.addr[1],
peer_addr.addr[0]);
}

void disconnect_current_addr(void)
{
ret_code_t err_code;
if(m_conn_handle != BLE_CONN_HANDLE_INVALID)
{
err_code = sd_ble_gap_disconnect(m_conn_handle, BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION);

APP_ERROR_CHECK(err_code);
m_conn_handle = BLE_CONN_HANDLE_INVALID;
}
}

  

[21:04:11.522]收←◆K4\0 \0Bconnect_current_addr ++
Connecting: A0:9E:1A:17:40:F8

[21:04:11.636]收←◆Connected: A0:9E:1A:17:40:F8

[21:04:11.694]收←◆GATT ATT MTU on connection 0x0 changed to 232

[21:04:12.234]收←◆Data length for connection 0x0 updated to 236
Disconnected, reason 0x16
connect_current_addr ++
Connecting: A0:9E:1A:17:40:DC

  

Parents Reply Children
Related