"Peer to peer" communication between Serial bluetooth modules

Hi everyone,

I have bought a Serial Bluetooth module (HC-05) which can be set as master or slave with AT commands.

All I want to do is a "peer to peer" transfer between two of those beauties when a button is pressed on each sides (both arduino controlled). I can't stick to just set a module to slave and the other to master because I have a lot more of those, and this will not work when trying a "master to master" or "slave to slave" communication.

The only idea I have here is maybe an "election" process which is going to elect a master and a slave for each communication. But how can I do this ? How can I decide ?
I didn't see that too, but I think that depending on the current mode (master or slave) some functions (scanning, pairing, etc.) might not be available, am I right ?

Maybe something like this has been done before but I didn't found anything. If you heard of something, or can help, many thanks.

I believe the only time you actually need the master mode is when the pairing and connection is established and you only need one to be a master in order to do that. If that function can be confined to one module, which is likely, there would never be any need for either to switch between master and slave, i.e. one HC-05 can stay permanently in the default slave mode. It never needs to be set to slave unless it been made a master. Once connection is established it doesn't matter who is master, they both do their job irrespective.

You can be sure you will have to give the slave a new name if it is an HC-05. I imagine you then need to incorporate that name in the master's initialisation facility. This would then mean the master knows what to look for, and absolves you from having to provide a screen, menu, butttons etc. etc.

If you have only one HC-05, the next module could be an HC-06. This is permanently a slave and already comes with a different name, linvor, no settings needed.

Thanks for your answer, but as I said, I cannot have some "master device" (arduino + BT module set to master) and some "slave device" (arduino + HC-06 or HC-05 set to slave), if I have a bag of 100 devices, I should have the ability to take two of them and do a transmission.

In "my mind", here is what I want to do:

  1. Each module start at slave
  2. Each module detect the other device (can they do that as slave ?)
  3. One module goes to master mode (How can they decide which one ? They cannot share informations for now !) and initiate the transfer (pair + send)
  4. Transfer succeed, go back to sleep mode.

Dammoul:
Thanks for your answer, but as I said, I cannot have some "master device" (arduino + BT module set to master) and some "slave device" (arduino + HC-06 or HC-05 set to slave), if I have a bag of 100 devices, I should have the ability to take two of them and do a transmission.

What you said was

All I want to do is a "peer to peer" transfer between two of those beauties

and the rest is irrelevant. One bluetooth will only talk to one other bluetooth at a time. That is what "pairing' means. If you actually want to bring another 100 into the game, you will surely be better off considering another means of communication before you buy them. Indeed, while I believe two Arduinos can talk to each other via HC-05, I can't recall it ever being done. I suspect a principal reason for this is that it is easier to use NRF24, if only because there is plenty of information about that, so that is what everybody does.

OTOH the principal reason for using peer-to-peer bluetooth is likely to be that it uses less memory, which doesn't amount to much if you are already obliged to use a Mega.

  1. Each module start at slave
  2. Each module detect the other device (can they do that as slave ?)
  3. One module goes to master mode (How can they decide which one ? They cannot share informations for now !) and initiate the transfer (pair + send)
  4. Transfer succeed, go back to sleep mode.
  1. Forget it. One must be a master in order to establish a connection.

  2. No

  3. I don't think it is possible and I'm certain it is pointless. I don't think you can send AT+ commands while the device is connected. The only way the decision could be made is by you writing a programme that enables it.

  4. It surely didn't succeed.

Note also that, if by sleep mode you imply a power-saving state and that is important to you, the HC-05 isn't famous for its low power consumption, but the NRF24 is. The cost is much the same.

In short: I think you might be on the wrong tram.

Bluetooth is an excellent way for a single Arduino to talk to other devices. If you want several Arduinos to talk amongst themselves, you are surely better off using other means. Since you already have an HC-05, here is some background on the former, which you might find useful.

http://homepages.ihug.com.au/~npyner/Arduino/GUIDE_2BT.pdf

http://homepages.ihug.com.au/~npyner/Arduino/BT2way.ino

Note also this Phillipe Cantin: Arduino Bluetooth Link but he is not using HC-05s

One bluetooth will only talk to one other bluetooth at a time. That is what "pairing' means. If you actually want to bring another 100 into the game, you will surely be better off considering another means of communication before you buy them.

if I have a bag of 100 devices, I should have the ability to take two of them and do a transmission.

As I said before, it's a point to point communication between TWO device. My example goal was to counter the "set one device to slave and the other to master" solution.

I suspect a principal reason for this is that it is easier to use NRF24, if only because there is plenty of information about that, so that is what everybody does.

Thanks for the solution but Bluetooth is what I need (mobile compatibility on the balance).

OTOH the principal reason for using peer-to-peer bluetooth is likely to be that it uses less memory, which doesn't amount to much if you are already obliged to use a Mega.

Not here. What I looking for is a quick serial communication between two devices with the same code on both of them, that's all.

I found on:

Auto-connect ANY Mode (SM,5)
This mode must be set by command. This mode operates like Auto-connect DTR mode, except that
each time the Switch/PIO is set, an inquiry is performed and the first device found is connected.
The stored address is NOT used, and the found address is never stored.

That is something that can do the trick ! (but I have to recreate it on HC-05)
The main question remains: can a master device detect a master device, and can a slave device detect a slave device ?
The same PDF point the fact that a slave device CAN BE detected.

If so, the schematic would be:

  1. Each module start as slave.
  2. Each module start an research
  3. If a module found the other, it saves its MAC address (on Arduino)
  4. The module restart at master
  5. The module initiate a connection with the MAC address it saves.

I haven't tested it yet but according to the bluetooth documentation provided by Sparkfun, that would probably works. The only problem is how to select which module gonna restart as Master and initiate the connection ? If we use the "first to discover" rule, the risk is that due to lag, the modules both restarts as master.

Dammoul:
As I said before, it's a point to point communication between TWO device. My example goal was to counter the "set one device to slave and the other to master" solution.

In that case I don't know why you are talking about 100 but, so long as you understand that only two modules can work together at one time, I guess it doesn't matter

Thanks for the solution but Bluetooth is what I need (mobile compatibility on the balance).
What I looking for is a quick serial communication between two devices with the same code on both of them, that's all.

Gobbledygook. And probably not a case against the NRF24 either.

Auto-connect ANY Mode (SM,5)
This mode must be set by command.
That is something that can do the trick ! (but I have to recreate it on HC-05)

I believe that RN is the same as Bluesmirf They aren't the same as HC-05 and can do things the HC-05 cannot. I imagine this is because they have a more comprehensive set of commands. This doesn't mean you cannot connect between two HC-05, it just does mean it's a blind alley.

The main question remains: can a master device detect a master device,

Yes

and can a slave device detect a slave device ?

No

The same PDF point the fact that a slave device CAN BE detected.

I guess it would say that. Being detected is what slaves do.

I suggest you do some serious research into disproving my previous comment that you cannot send AT+ commands while the device is in communication mode. I imagine that would apply to all bluetooth modules.

Nick_Pyner:
In that case I don't know why you are talking about 100 but, so long as you understand that only two modules can work together at one time, I guess it doesn't matter

I understand it was not clear, my bad. To resume the idea in a easier way: "Each device must run the same code."
And it's a one-to-one communinication, we agree on that.

Gobbledygook. And probably not a case against the NRF24 either.

Bluetooth can be found on every smartphone on the market, that is the main reason of my choice.

I believe that RN is the same as Bluesmirf They aren't the same as HC-05 and can do things the HC-05 cannot. I imagine this is because they have a more comprehensive set of commands. This doesn't mean you cannot connect between two HC-05, it just does mean it's a blind alley.

The HC-05 choice is all about money for this prototype (< 10$). I can't put 25$ for a bluetooth module... :~

The main question remains: can a master device detect a master device,

Yes

Then the steps are:

  1. Each module start as master
  2. Each module start an research
  3. If a module found the other, it saves its MAC address (on Arduino)
  4. The other module restart at slave
  5. The master module initiate a connection with the MAC address it saves.

I can do something like this with some random but it will not be reliable nor pretty nor very useful.

Dammoul:
Bluetooth can be found on every smartphone on the market, that is the main reason of my choice.

That changes the picture completely, hence my comment in reply#3. Previously you said

(both arduino controlled)

While yes, Bluetooth can be found on every smartphone on the market, you might be aware that a lot of them are iPhones, and you can forget about using those. The link I alluded to previously covers HC-05<>Android phone.

The HC-05 choice is all about money for this prototype (< 10$).

Indeed

The main question remains: can a master device detect a master device,

Yes

Then the steps are:
[/quote]

Possibly; but I don't know anything about MAC addresses for bluetooth and I get the impression that the people who wrote the datasheets for the HC-05 don't know either.