Due to high demand expect some shipping delays at this time, orders may not ship for 1-2 business days.
0

Connecting multiple bluetooth devices simultaneously
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Connecting multiple bluetooth devices simultaneously

by gruthor on Tue Oct 26, 2021 8:58 pm

Hi,
I am working on a project where multiple peripheral devices would run the same code, reporting back to a central device that would collect the data from all these peripherals.

I'm trying to think about how I would set things up in the most efficient manner.

I currently have things working great with one external device, with a BLEClientService and a series of custom BLEClientCharacteristics under this service...so that's good.

Here's an example of what I have on my central device right now:

BLEClientService _senseService = BLEClientService("1d5b4d40-e725-11eb-ba80-0242ac130004");
BLEClientCharacteristic _eulerChar = BLEClientCharacteristic("7bbe9708-0e19-4626-9fbc-29527f154732");//xyz euler angles
BLEClientCharacteristic _accelChar = BLEClientCharacteristic("b41b58e8-382e-442e-b0fd-01115e8f29f8");//xyz accel
BLEClientCharacteristic _micChar = BLEClientCharacteristic("c0a5e59d-27f8-44a7-9316-fb902bc17577");//microphone
BLEClientCharacteristic _lightChar = BLEClientCharacteristic("3341bef2-a2df-4f98-a2cf-a12c62a73ece");//brightness
BLEClientCharacteristic _humidityChar = BLEClientCharacteristic("7a854f1f-013f-4e29-ac49-4d7809d49119");//humidity

And on the peripheral, I've got the same GUIDs registered to the service/characteristics.

I want to think about how I would create an array of Adafruit Sense devices that talk back to central, without going in and creating special characteristics for each individual device. I don't want to get into repeating myself in the code!

I'm wondering if multiple peripherals can all talk to the central device if they have the same services/characteristics registered to them.

Do I need to create an array of ClientServices/Characteristics on the central device, one per device I expect to connect? Or is it enough just to start up the Service+Characteristics and relevant callback functions (one time) and then all my peripherals will just be sending messages back to the central device on the appropriate callbacks? I could maybe include in my messages from the peripherals something like a device index so the central device could know who is talking to it.

I guess long story short: trying to think about how to do this in the least code possible, and in the most extensible way possible so I can continue to add devices to my system.

Unfortunately don't have a second "Sense" on hand to test this out with, but could buy one if necessary...it'll probably happen sooner or later but thought I might think about things first.

gruthor
 
Posts: 12
Joined: Mon May 03, 2021 10:21 am

Please be positive and constructive with your questions and comments.