Connect two devices together without pre-determined Master/Slave

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Anonymous
Not applicable

My product is neither a master nor a slave.  I am trying to connect two of my identical peripheral devices to each other without a third-party central.  When pairing the devices, how do I pick which one should advertise and which one should scan for the connection?  I can press a button on the dev kits to make one a master (scanning for advertisements) and the other a slave (sending advertisements), but I would rather just let them both be masters and slaves to each other, at the same time.  In other words, they both send advertisements and scan for advertisements from at the same time.  When they find each other, they are both master/slave to each other over the two connections.

Is this possible?

I tried to modify hello_client to do exactly that and it failed.  Device A was master to device B, but when I tried to kick off another connection where device B was master to device A, it failed.  Device B found advertisements from device A just fine, but I never got to connection up.  Note that I did program the BD_ADDR differently for each dev kit to ensure that they are different.  

0 Likes
1 Solution

In Bluetooth world the communication is always between a master and a slave.  And it is not possible to have 2 connections between 2 devices.  So you will have to live with that.  Meanwhile I wonder if this is what you need.  Regardless of the link role both devices can be GATT client and GATT server.  So if you have exactly the same databases on 2 devices they will both be able to use exactly the same code to read, write, send notifications, or whatever you want.

View solution in original post

0 Likes
4 Replies
BoonT_56
Employee
Employee
500 likes received 250 likes received 100 likes received

This scenario is unlikely. If both are Master, then who will initiate the connection and who will accept? Depending on your application, both roles can scan and advertise, but only the master can initiate connection.

However, a device can be a Master in one piconet and a Slave in another which is a different story from yours. Check out the below...

Testing Master and Slave Roles

0 Likes

In Bluetooth world the communication is always between a master and a slave.  And it is not possible to have 2 connections between 2 devices.  So you will have to live with that.  Meanwhile I wonder if this is what you need.  Regardless of the link role both devices can be GATT client and GATT server.  So if you have exactly the same databases on 2 devices they will both be able to use exactly the same code to read, write, send notifications, or whatever you want.

0 Likes
Anonymous
Not applicable

I figured out that all I need to do is make both devices scan and advertise at the same time.  In the "connection up" callback function, I stop all advertising and scanning.  Each device will be assigned a role (master or slave) by the stack and I use that role to figure out if I want to send write requests or indications.  So now two peer devices can share the same functionality and talk to each other over a BLE link.

Whomever becomes slave first will not allow another connection from a master, as victorz says. There could be a race condition there where they both wind up as slaves and neither is master or vice versa, but I haven't seen it.

0 Likes

A connection between 2 masters or 2 slaves is not theoretically possible. On the other hand both sides can be GATT server and GATT client. So you can send write requests from both sides and notifications from both sides. This assumes that GATT databases on both devices allow that.

0 Likes