Hi Everyone.
IDE : Vs Code
SDK : nrfConnect SDK
I have tried to connect peripheral device based on address. User gives input , address of ble device and based on that, I would start ble connection request.
I was successfull to connect, If I call below api inside scan_response function. But, If I wait for user input and call for same api, the connection callback throws error -2 and sometimes by luck it connects.
I suppose central can only start connection request while peripheral is still adversting.
Now, I wish to know how to start a connection at my will, and make sure it connects. Also, what should be min max intervals, so that connection request would wait for sometime.
tm_bool_t bt_connect(const bt_addr_le_t *addr,struct bt_conn **conn)
{
int err;
struct bt_le_conn_param param2,*param;
param = BT_LE_CONN_PARAM_DEFAULT;
// param->latency = 400;
// param->timeout = 400;
param2.interval_max = 0x28;
param2.interval_min = 0x18;
param2.latency = 10;
param2.timeout = 400;
err = bt_conn_le_create(addr, BT_CONN_LE_CREATE_CONN,
¶m2, conn);
if (err)
{
sprintf(tx_buf,"Create conn failed (err %d)\n", err);
DPRINTF(tx_buf); /* Debug print in uart */
return FALSE;
}
sprintf(tx_buf,"Create conn success (err %d)\n", err);
DPRINTF(tx_buf);
return TRUE;
}
Edit:
If connection timeout's I get error 2 inside connection_callback;
After that If I try again to connect using same address, I get -EINVAL(22) response and connection doesn't create.
if (bt_conn_exists_le(BT_ID_DEFAULT, peer)) {
return -EINVAL;
}
how to prevent this happening again?