Gustavo Corrente
Gustavo Corrente

Reputation: 43

Bluetooth connection using socket rfcomm

I have two Bluetooth devices and I'm trying to make two rfcomm connections, one connection per device.

I'm using bluez rfcomm socket

addr.rc_family = AF_BLUETOOTH;
addr.rc_channel = (uint8_t) 1;
str2ba( dest, &addr.rc_bdaddr );

// connect to server
s = socket(AF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM);

// set disconnect timeout to 2sec
struct timeval tv;
tv.tv_sec = 2;
setsockopt(s, SOL_SOCKET, SO_RCVTIMEO,(struct timeval *)&tv,sizeof(struct timeval));

// make connection
status = connect(s, (struct sockaddr *)&addr, sizeof(addr));

How I select a device to make the connection?

Upvotes: 3

Views: 7701

Answers (3)

matlo
matlo

Reputation: 21

You have to call bind() before connect().

Have a look at this:

https://github.com/matlo/l2cap_proxy/blob/master/l2cap_con.c#L197

It's l2cap, but I guess it's also possible for rfcomm.

Upvotes: 2

Joe
Joe

Reputation: 11

I believe bluez supports up to 16 dongles.

You might be interested in the code in this project: http://diy-machine.blogspot.com/

Upvotes: 1

Dennis Mathews
Dennis Mathews

Reputation: 6975

you cannot do this, the bluez bluetooth stack will work on only one dongle i.e local bluetooth device at any time.

To be able to have a singe instance of the bluetooth stack control 2 bluetooth local dongles will be a big change to the bluez stack.

Upvotes: -1

Related Questions