ESP32-A2DP: Cant connect to esp32 receiver from source after restarting receiver
` #include “BluetoothA2DPSink.h”
BluetoothA2DPSink a2dp_sink;
void read_data(const uint8_t *data, uint32_t len){ }
void setup() { Serial.begin(115200); a2dp_sink.set_stream_reader(read_data); }
void loop() { a2dp_sink.start(“ESP32_SPEAKER_TEST”,false); Serial.println(“started”); delay(60000); if(a2dp_sink.isConnected()) a2dp_sink.disconnect(); a2dp_sink.end(); Serial.println(“turned off”); delay(10000); } ` After starting the Bluetooth receiver I can’t connect to it from my phone. The library works perfectly if I’m not stopping and then starting the Bluetooth receiver but i need it for my project, any fixes?
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 20 (10 by maintainers)
Commits related to this issue
- Auto-reconnect issue workaround See this for details: https://github.com/pschatzmann/ESP32-A2DP/issues/97#issuecomment-992484405 — committed to jokubasver/saab-93NG-bluetooth-aux by jokubasver 3 years ago
- issue #97 — committed to pschatzmann/ESP32-A2DP by pschatzmann 3 years ago
- Update WIP (#245) * support restart after end * combile warnings * i2s_init as separate method * fix broken analog output * use set_mono_downmix in set_channels * compile errors for ES... — committed to pschatzmann/ESP32-A2DP by pschatzmann 2 years ago
Just to clarify, my use case is that i want the esp32 to only connect to a specific device, and to accept frequently disconnections/connections, but my esp32 was crashing by many connections, and the ESP.restart() along with disabling the clean_last_connection(), worked very well for me ❤️ @jokubasver you’re my hero 👍
@jokubasver Thank you so much for the sketch you provided, it worked like a charm for me using both the
ESP.restart();and theclean_last_connection();, along with the sketch logic you wrote, thank you so much!I moved the setting to config.h and increased it to 10 In addition I added the new method set_try_reconnect_max_count()
If I modify
void BluetoothA2DPCommon::clean_last_connection()in BluetoothA2DPCommon.cpp to:and in my sketch I add:
Then the auto-reconnect issue when the phone is out of BT range, goes away. This gives a 10 second window to attempt a reconnection, and if it fails - the ESP reboots and tries again. The time window could probably be reduced, but 10 seconds works fine in my case.
Seems like not clearing the last connection together with a reboot let’s the phone reconnect at any given time.
Just doing that restart after 10 seconds on it’s own did not fix the issue, neither did the removal of
clean_last_connection();I had to use both in order to fix the issue (albeit it’s a hacky, dumb and bad solution, but hey… it works)I thought that by removing
clean_last_connection();it wouldn’t let a different device to connect to the A2DP sink, but it still works fine (tested with two phones)Unfortunately,
clean_last_connection();is a protected function, so it would be great if this function could be disabled in the sketch, without modding the library.