harvey_slash
Posts: 34
Joined: Fri Apr 04, 2014 10:17 am

Multiple connections from a single Bluetooth Dongle

Tue Mar 31, 2015 8:12 am

I am using a usb bluetooth adapter on my PI 2 , which communicates to an arduino using HC-06 Bluetooth module. This script runs to connect to that module:

Code: Select all

#! /usr/bin/python

import serial
from time import sleep

    bluetoothSerial = serial.Serial( "/dev/rfcomm1", baudrate=9600 )

    count = None
    while count == None:
        try:
            count = int(raw_input( "Please enter the number of times to blink the L$
        except:
            pass    # Ignore any errors that may occur and try again


    bluetoothSerial.write( str(count) )
    print bluetoothSerial.readline()
And this is what my /etc/bluetooth/rfcomm.conf looks like :

Code: Select all

rfcomm1 {
    bind yes;
    device xx:xx:xx:xx:xx:xx;
    channel 1;
    comment "Connection to Bluetooth serial module";
}
Now, I want another arduino and another HC-6 connected to my usb blutooth. Is it possible to do that simultaneously ? I want two and fro data connection from both these HC-06's at the same time.

For more reference, this tutorial is what I followed to get the first bluetooth running : http://www.uugear.com/portfolio/bluetoo ... d-arduino/

User avatar
MarkHaysHarris777
Posts: 1820
Joined: Mon Mar 23, 2015 7:39 am
Location: Rochester, MN
Contact: Website

Re: Multiple connections from a single Bluetooth Dongle

Tue Mar 31, 2015 9:18 am

No.

Blue tooth would not be secure in that case. Normally blue tooth send/receive pairs need to be "paired" ... at any rate, its a serial connection ( full duplex ) but not multiple connections...
not at the same time.
marcus
:ugeek:

harvey_slash
Posts: 34
Joined: Fri Apr 04, 2014 10:17 am

Re: Multiple connections from a single Bluetooth Dongle

Tue Mar 31, 2015 9:46 am

Security apart,can it be done ? If not , I want to know how to send and receive data from multiple Bluetooth modules from a single adapter.

I read that in BT 4.0+ ,its possible to connect to multiple Bluetooth devices simultaneously. What are they meaning by this ?

danjperron
Posts: 3503
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: Multiple connections from a single Bluetooth Dongle

Tue Mar 31, 2015 11:22 am

Normally you should be able to pair the other bluetooth device on /dev/rfcom2.

Each pair need to have it's specific device.

So add a rfcomm2 definition and now you have access to your second bluetooth device.

All depends how you interpret simultaneously! It isn't but you have two file handles to take care.


Daniel

harvey_slash
Posts: 34
Joined: Fri Apr 04, 2014 10:17 am

Re: Multiple connections from a single Bluetooth Dongle

Tue Mar 31, 2015 11:48 am

So,I'll add an rfcomm2 definition, will connect BOTH at the same time. Can I pass data to and fro serial data at the same time ?

danjperron
Posts: 3503
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: Multiple connections from a single Bluetooth Dongle

Tue Mar 31, 2015 12:49 pm

Yes and no.

You could receive from one and then send to the other. It is physically impossible to send and receive at the same time.

Thing about same time means?

It has to be sequential.

harvey_slash
Posts: 34
Joined: Fri Apr 04, 2014 10:17 am

Re: Multiple connections from a single Bluetooth Dongle

Tue Mar 31, 2015 1:27 pm

okay, im trying to clarify

this is something i am using:

Code: Select all

bluetoothSerial = serial.Serial( "/dev/rfcomm1", baudrate=9600 )
bluetoothSerial.write( 'works')
print bluetoothSerial.readline()
Now, If I add another module, and add a /dev/rfcomm2 , then write another python file similar to the one above, can I run both of them? will running the 2nd one cause the first 1 to disconnect from rfcomm1 ?

danjperron
Posts: 3503
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: Multiple connections from a single Bluetooth Dongle

Tue Mar 31, 2015 2:29 pm

Yes you could have both open !

You could read or write with any of them. But it is sequential.

You read or write one device at the time. Not both at exactly the same time.

Really take out the term "same time"

What you mean is can we have more than one connection on a bluetooth device? And the answer is Yes!

harvey_slash
Posts: 34
Joined: Fri Apr 04, 2014 10:17 am

Re: Multiple connections from a single Bluetooth Dongle

Tue Mar 31, 2015 2:54 pm

i mean, when you are saying not at the 'same time' , it means the same thing as a processor running 'one thing at a time' , right ?
it will seem to be immediate, but technically, 'same time' not possible . Please correct me if I am wrong.

Also, suppose i run just this file

Code: Select all

 bluetoothSerial = serial.Serial( "/dev/rfcomm1", baudrate=9600 )


    bluetoothSerial.write( str(count) )
. What I notice ,is that it takes around 3to 5 seconds to 'connect' (the light on the hc -06 gets solid). But , when I run :

Code: Select all

 bluetoothSerial = serial.Serial( "/dev/rfcomm1", baudrate=9600 )

while True: 
on one file, and THEN that above file seperately , the result is immediate.


So, will multiple connections cause this 5 sec delay ?

danjperron
Posts: 3503
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: Multiple connections from a single Bluetooth Dongle

Tue Mar 31, 2015 3:09 pm

On one processor ,single core, same times is impossible since everything is sequential. It is one operation at at time.

Now try to implement the second rfcomm .

open /dev/rfcomm0
open /dev/rfcomm1
read or write on first arduimo using the handle for /dev/rfcomm0
read or write on second arduino using the handle for /dev/rfcomm1

If you look it is a sequence ! it is not at the same times!

Same times means exactly at the same moment. 1 pico second later is not.

harvey_slash
Posts: 34
Joined: Fri Apr 04, 2014 10:17 am

Re: Multiple connections from a single Bluetooth Dongle

Tue Mar 31, 2015 3:21 pm

thanks!

so final verdict is,

I CAN have two files with rfcomm1 and rfcomm2 open respectively and who are 'listening' for data from 2 hc06 modules CAN receive data together , right ?

danjperron
Posts: 3503
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: Multiple connections from a single Bluetooth Dongle

Tue Mar 31, 2015 4:26 pm

yes up to 7 connections per bluetooth dongle.

Return to “Python”