Hi
When I try to use bt_conn_le_create to reconnect a Peripheral device, sometimes it returns -22.
bool blea_connect(const bt_addr_le_t *addr)
{
bool scanning = (bt_le_scan_stop() == 0);
struct bt_conn *conn = NULL;
int err = bt_conn_le_create(addr, &create_param, &conn_param, &conn);
if (err) {
char addr_str[BT_ADDR_LE_STR_LEN];
bt_addr_le_to_str(addr, addr_str, sizeof(addr_str));
LOG_WRN("Create conn to %s failed (%d)", log_strdup(addr_str), err);
if(scanning) {
start_scan();
}
}
return (err==0);
}
After debugging, I found the bt_conn_exists_le return true with log: Found valid connection in disconnected state
bool bt_conn_exists_le(uint8_t id, const bt_addr_le_t *peer)
{
struct bt_conn *conn = bt_conn_lookup_addr_le(id, peer);
if (conn) {
/* Connection object already exists.
* If the connection state is not "disconnected",then the
* connection was created but has not yet been disconnected.
* If the connection state is "disconnected" then the connection
* still has valid references. The last reference of the stack
* is released after the disconnected callback.
*/
BT_WARN("Found valid connection in %s state",
state2str(conn->state));
bt_conn_unref(conn);
return true;
}
return false;
}
How can I get the disconnected devices reconnected?
How to handle this issue?
logo