I am working with:
NRF52840 boards
nRF Connect SDKwith Zephyr
On Ubuntu
Desired behaviour would be:
- Establish connection with Codded PHY
- After some time disconnect
- Connect back to the device in the same way as it was done in step 1. (with Codded PHY)
Scanner initialisation:
struct bt_le_scan_param scan_param = { .type = BT_LE_SCAN_TYPE_ACTIVE, .interval = BT_GAP_SCAN_FAST_INTERVAL, .window = BT_GAP_SCAN_FAST_WINDOW, .options = BT_LE_SCAN_OPT_CODED | BT_LE_SCAN_OPT_NO_1M | BT_LE_SCAN_OPT_FILTER_DUPLICATE }; struct bt_scan_init_param scan_init = { .connect_if_match = 0, // Original code .scan_param = &scan_param, .conn_param = NULL }; bt_scan_init(&scan_init); bt_scan_cb_register(&scan_cb);
And activation with:
err = bt_scan_start(BT_SCAN_TYPE_SCAN_ACTIVE); if (err) { printk("Starting scanning failed (err %d)\n", err); return; }
When discovered I try to connect in the following way:
err = bt_scan_stop(); if (err) { printk("Stop LE scan failed (err %d)\n", err); } conn_params = BT_CONN_LE_CREATE_PARAM( BT_CONN_LE_OPT_CODED | BT_CONN_LE_OPT_NO_1M, BT_GAP_SCAN_FAST_INTERVAL, BT_GAP_SCAN_FAST_INTERVAL); err = bt_conn_le_create(device_info->recv_info->addr, conn_params, BT_LE_CONN_PARAM_DEFAULT, &default_conn); if (err) { printk("Create conn failed (err %d)\n", err); err = bt_scan_start(BT_SCAN_TYPE_SCAN_ACTIVE); if (err) { printk("Scanning failed to start (err %d)\n", err); return; } }
To disconnect, I call following function:
err = bt_conn_disconnect(default_conn,BT_HCI_ERR_REMOTE_USER_TERM_CONN); if (err) { printk("Could not disconnect(err %d)\n", err); return; }
I am able to successfully connect to device which advertise on Codded PHY.
Then I successfuly disconnect ( the callback disconnected is called)
But when I try to reconnect again I get the following error:
W: Found valid connection in disconnected state Create conn failed (err -22) Connection pending