-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Description
Describe the bug
Zephyr Host has a function called bt_le_set_auto_conn() which is supposed to auto-reconnect when the ACL connection disconnected.
Unfortunately, the function doesn't work as expected.
There are at least two issues with the current implementation of this function:
- When bt_le_set_auto_conn() is called from the application, the application never gets disconnected callback. The following flow is triggered in this case: the connection state is set to BT_CONN_DISCONNECTED and right after that it is set to BT_CONN_SCAN_BEFORE_INITIATING, so notify_disconnected() handler is never called because it is only called from deferred_work()
- Another issue is that a device never reconnects to the Peripheral. Not sure exactly why it happens, but it looks like some parts of the auto-reconnect feature are missing in conn.c and scan.c
To Reproduce
I modified samples/bluetooth/central sample to reproduce the issue.
The changes include: removed disconnection, added bt_le_set_auto_conn() to device_found(), increased RSSI to -30dBm to connect only to the device located very close.
Steps to reproduce the behavior:
- cd central_auto
- west build -bnrf52840dk_nrf52840
- west flash
It required additional device to be used as a Peripheral
I was using zephyr v3.7.99 but I think the bug is still presented on the v4.0
Expected behavior
The following messages are expected in the sample output:
Device found: 52:84:E1:BC:96:03 (random) (RSSI -30)
Connected: 52:84:E1:BC:96:03 (random)
Disconnected: 52:84:E1:BC:96:03, reason 0x08
Connected: 52:84:E1:BC:96:03 (random)
Observed behavior
Disconnected: 52:84:E1:BC:96:03, reason 0x08
message is never printed when Peripheral is disconnected. It happens because notify_disconnected() is never called.
Also, the second Connected: 52:84:E1:BC:96:03 (random) is not printed.
Suggested solution
I would suggest to just remove this function because the use-cases are unclear. Also it looks like it didn't work as expected for a long time