pschatzmann / ESP32-A2DP

A Simple ESP32 Bluetooth A2DP Library (to implement a Music Receiver or Sender) that supports Arduino, PlatformIO and Espressif IDF
Apache License 2.0
1.65k stars 270 forks source link

Trouble with connect_to ... #480

Closed mmar22 closed 1 year ago

mmar22 commented 1 year ago

Problem Description

I start with 1.7.3 my device connects to last and play ok . Then i call `void a2discon() { if(a2dp_sink.is_connected()) a2dp_sink.disconnect(); while(a2dp_sink.is_connected()) delay(10); }

void a2con(uint8_t indexPD) { a2dp_sink.connect_to(storedPD[indexPD].addr); }`

device is disconnected, but next paired in my db not connect, or if i try some delays sometimes connect sometimes not. How is right steps and timing to disconect device 1 and connect device 2 ? From ESP side.

Device Description

ESP32

Sketch

spdif no I2S variant sink

Other Steps to Reproduce

same situation 1.7.4 A2DP

too buggy showed last instead new bool BluetoothA2DPCommon::connect_to(esp_bd_addr_t peer){ ESP_LOGW(BT_AV_TAG, "connect_to to %s", to_str(last_connection));

and FYI build without I2S require patch BluetoothA2DPSink.cpp against error not exist i2s task void ccall_i2s_task_handler(void *arg) { ESP_LOGD(BT_AV_TAG, "%s", __func__); if (actual_bluetooth_a2dp_sink) actual_bluetooth_a2dp_sink->i2s_task_handler(arg); } need add `#if A2DP_I2S_SUPPORT void ccall_i2s_task_handler(void *arg) { ESP_LOGD(BT_AV_TAG, "%s", func); if (actual_bluetooth_a2dp_sink) actual_bluetooth_a2dp_sink->i2s_task_handler(arg); }

endif`

Provide your Version of the EP32 Arduino Core (or the IDF Version)

No response

I have checked existing issues, discussions and online documentation

pschatzmann commented 1 year ago

There is a good reason why I am asking to provide the Arduino ESP32 core version number! So please provide the missing information.

I suggest that you activate the logging and analyse the events: In the end it is up to the device that you want to connect to if a new connection is accepted or not.

mmar22 commented 1 year ago

PACKAGES:

pschatzmann commented 1 year ago

https://github.com/pschatzmann/ESP32-A2DP/commit/2f7b42e00d8cbf8e5937f5bf6dc2de321842644a

ps. 2.0.9 is pretty old now, the latest release is 2.0.13 now

mmar22 commented 1 year ago

Very inteligent reply. Is irelevant here if 2.0.9 or 1234 , your class connect_to require some control of state previous disconnect command. Or if you dont know timing write it .

pschatzmann commented 1 year ago

I think it would be better to rely on the connection state reported by the proper API for your check and wait for the correct disconnected status, or register an event handler for connection status changes.

You are currently only checking if != APP_AV_STATE_CONNECTED which does not really fit