Why connecting to remote Bluetooth devices takes a long time?

Ivan32
Posts: 6
Joined: Fri Aug 16, 2024 1:28 am

Why connecting to remote Bluetooth devices takes a long time?

Postby Ivan32 » Tue May 06, 2025 11:01 pm

We are using Audio Source example A2DP_SOURCE with ESP32 development board. Connecting to remote external headphones takes too long time: anywhere from 20 seconds to 1 minute. I have 4 different headsets from 4 different manufacturers, but the A2DP_SOURCE example has trouble to connect to most of them most of the time.

Sometimes it locks in the discovery phase and no any discovery events come after the call to esp_bt_gap_start_discovery. The discovery phase will restart 3-7 times before it will finally discover the headset. This is especially consistent when I restart the headsets while ESP32 keeps running - then it will take much longer for it to re-discover headsets - about a minute. If I reboot ESP32 while headphones are On, ESP32 discovers them much faster.

Sometimes the esp_a2d_source_connect function will keep failing for about 5 times before it finally connects. This happens very consistently if I call esp_a2d_source_connect without discovering headsets first: If I bypass the discovery and call esp_a2d_source_connect using a known BT device address, it takes about 7 retries to connect, or sometimes it will never connect.
A typical log in this case looks like:

Code: Select all

W (11723) BT_APPL: reset flags
W (16843) BT_SDP: SDP - Rcvd conn cnf with error: 0x4  CID 0x40
W (16843) BT_HCI: hcif conn complete: hdl 0xfff, st 0x4
W (16853) BT_BTC: BTA_AV_OPEN_EVT::FAILED status: 2
The headsets are present in the esp_bt_gap_get_bond_device_list.

At all times, when the connection is finally established, it works OK and is very stable. I can walk away from the ESP32 development board with the headsets 10 meters away and there are no any connection drops. Hence it is not an issue with the signal strength or RF interference. I also tested it with different development boards (chip revision 3.0) and other chip ESP32U4WDH with hardware revision 3.1. It is all the same. ESP-IDF version 5.4.1.

When I use same headsets with a Windows desktop computer, all of them work fine. The connection with all of them is always established within one second.

So what I am doing wrong? Should I do some sort of pairing with the headsets first, same as Windows does? But how to do it?

Thanks!

Who is online

Users browsing this forum: Applebot, Google [Bot], PetalBot, Qwantbot and 15 guests