arduino-esp32 icon indicating copy to clipboard operation
arduino-esp32 copied to clipboard

Connecting to 2 or multiple BT serial devices

Open emard opened this issue 4 years ago • 12 comments

I'd like to connect and communicate at the same time with 2 different bluetooth devices each device is providing a single serial port.

Is there some code example how to do it with BluetoothSerial?

emard avatar Jul 24 '21 13:07 emard

[STALE_SET] This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Oct 02 '21 00:10 stale[bot]

I have seen some activity in the source maybe someone else has tried to connect 2 devices, I'd like code example

On 10/2/21, stale[bot] @.***> wrote:

[STALE_SET] This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs. Thank you for your contributions.

-- You are receiving this because you authored the thread. Reply to this email directly or view it on GitHub: https://github.com/espressif/arduino-esp32/issues/5447#issuecomment-932646483

emard avatar Oct 02 '21 08:10 emard

[STALE_CLR] This issue has been removed from the stale queue. Please ensure activity to keep it openin the future.

stale[bot] avatar Oct 02 '21 08:10 stale[bot]

Hi. Anyone have any thoughts on this issue?

Connecting to one device works great, but I'd also like to make multiple Bluetooth classic connections to devices so I can aggregate some sensor readings.

If I simply copy the example code for a single connection and create multiple bluetooth connections, I get an indication that connecting to each of them has succeeded, but when data is received, it is only coming from the last bluetooth device I connected to.

I'm running my app within the Arduino IDE using the .available() function.

 if (btUART2.available()) {
    processMessage(btUART2, 1); 
  }

  if (btUART1.available()) {
    processMessage(btUART1, 0); 
  } 

Here I only see .available() returning true for btUART2 -- the last bluetooth UART I connected to. If I reverse the order of the .connect call, I only see data from btUART1.

Any help would be appreciated. Thanks!

digamesystems avatar Dec 22 '21 16:12 digamesystems

I haven't tested connecting multiple BLE devices simultaneously but I was able to pull data from different sensors by cycling between disconnecting and connecting to the address of the device I want to connect to. Maybe consider that if it works.

khaled147 avatar Jan 20 '22 18:01 khaled147

I haven't tested connecting multiple BLE devices simultaneously but I was able to pull data from different sensors by cycling between disconnecting and connecting to the address of the device I want to connect to. Maybe consider that if it works.

Thanks for the suggestion @khaled147! I can get that to work as well but I'd like it if the sensors could just send me data asynchronously without my having to poll them. Having the .available() function is really nice for situations where a sensor wakes up and transmits only when it has something to say...

digamesystems avatar Jan 20 '22 19:01 digamesystems

Hello, are you able to test your issue on development version 2.0.3-RC1 to check if this is still valid?

Take a look on Docs where is explained how to choose development release version in Arduino IDE.

VojtechBartoska avatar Apr 07 '22 11:04 VojtechBartoska

Hello, are you able to test your issue on development version 2.0.3-RC1 to check if this is still valid? ...

Thanks, @VojtechBartoska . I'll give it a try once my current release is out.

I read through the release notes for 2.0.3-RC1 and didn't see anything directly related to the Bluetooth Serial library except for this issue: https://github.com/espressif/arduino-esp32/pull/6109

This only seems to be getting rid of a compiler warning...

Am I missing something? -- Thanks again for the suggestion!

digamesystems avatar Apr 07 '22 14:04 digamesystems

There have been some changes in ESP-IDF itself which can have an influence on this and also from the issue description I wasn't sure on which version you are running your code so it's reasonable to test it on v2.0.3-RC1 to have actual results.

VojtechBartoska avatar Apr 08 '22 07:04 VojtechBartoska

Thanks, @VojtechBartoska.

I'll give it a try as soon as I get my release out the door.

I’ll also dig into the source for the BluetoothSerial library and see how it’s structured. I suspect there might be a single, global pointer that’s being used to reference the port. This would explain the behavior I'm seeing where the last port to be declared is the one that gets the callbacks. --

Thinking about it, it might just be an architectural issue, where sharing of the Bluetooth hardware resource isn't supported. After all, I don't think you can create multiple, independent instances of Serial with their own callbacks.

digamesystems avatar Apr 08 '22 14:04 digamesystems

2.0.3 stable is out, any chance you gave it a shot?

VojtechBartoska avatar May 05 '22 09:05 VojtechBartoska

@digamesystems Any news?

VojtechBartoska avatar Jul 26 '22 13:07 VojtechBartoska

Closing this issue as expired due to no answer, if needed you can reopen it.

VojtechBartoska avatar Aug 23 '22 10:08 VojtechBartoska