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: 2At 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!