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?
I believe bluez supports up to 16 dongles.
You might be interested in the code in this project: http://diy-machine.blogspot.com/
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.
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.
精彩评论