Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 701
Gustavo Corrente Avatar asked Sep 03 '26 01:09

Gustavo Corrente


2 Answers

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.

like image 75
matlo Avatar answered Sep 05 '26 14:09

matlo


I believe bluez supports up to 16 dongles.

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

like image 40
Joe Avatar answered Sep 05 '26 15:09

Joe