-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Bad handling of multiple devices connecting to BluetoothSerial. How to set a max limit of allowed BT connections. #2055
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
This appears to affect BLE. Does it apply to BT classic also? |
This is controller setting so it is affecting both, BR/EDR and BLE: |
@mouridis please open a pull request with your changes, this is very helpful =) |
Addressed on commit 0d564d7 |
This is still a problem in the 4.4.2 framework. There is no way to tell it to only support 1 connection?! I have tried setting CONFIG_BT_ACL_CONNECTIONS to 1 and it only works the first time you connect. IE: If you connect then disconnect, you have to reset the chip to connect again. A warning appears in the log for this second attempt: |
Reopening and adding to 2.0.6 milestone, we will investigate this issue for next bugsfix release @travis012 :) |
I have the correct fix for this now. I didn't realize that I was posting on the Arduino esp32 project. When I did, I re-posted on the espidf project: Basically you should just have to set |
This seems to be solved already, @P-R-O-C-H-Y will retest it. |
Hi @travis012, I have retested the BluetoothSerial and if 1 device is connected to ESP, than to be able to connect another device, the device 1 must be disconnected first and this issue was about BTSerial. The advice you sent about |
Hardware:
Board: WeMOS Lolin32 v.1.0.0 (using revision 1 ESP-WROOM-32 module)
Core Installation/update date: Commit 85032b2
IDE name: Arduino IDE 1.8.6
Flash Frequency: 80MHz
PSRAM enabled: No
Upload Speed: 921600
Computer OS: Windows 10 x64
Description:
Using BluetoothSerial, it's allowed for more than one device to pair and connect at the same time to ESP32. As it is now, if indeed a second device connects to ESP32, essentially it hijacks the connection. ESP32 receives data from both connected devices but all outgoing data is directed to the second (last) device that connected to it.
Searching through the library code, it seems the reason for this behavior is that the library only stores the BT handle of the last connected device and discards the old one. The following lines in BluetoothSerial.cpp are responsible for this:
I understand that modifying the library to handle multiple simultaneous connections, and offering methods to identify the source device of incoming data and recipient device for outgoing data, would require a huge overhaul of the library.
In the meantime, and in order to avoid BluetoothSerial misbehavior, maybe it would be a good idea to limit the number of allowed simultaneous connections to only 1.
The quick dirty fix that I did in my project is modifying this part of the BluetoothSerial.cpp:
to this:
and of course adding the needed declaration for secondConnectionAttempt somewhere on the declarations section:
static boolean secondConnectionAttempt;
In this way, when a second device attempts to connect, ESP32 disconnects from it immediately after connection and does not store it's BT handle.
The question is if the IDF offers a cleaner way to implement similar functionality by limiting the number of allowed simultaneous connections.
The text was updated successfully, but these errors were encountered: