Multiple BLE connections using Linux and Bluez 5.0

I am currently trying to connect to multiple BLE devices using BlueZ 5.0 and Linux. I have one BLE adapter for the host, and I modified gatttool to connect and execute this function. If I run an instance of a modified gatttool, I successfully connect and receive data from a BLE device. If I run another instance of the modified gatttool and connect to another BLE device, this application will start receiving data from both BLE devices, and the original application will no longer receive any data. I believe that this is due to the setting of the socket, where both applications configure their sockets to the same address and PSM (the last instance receives data, and the other is hungry). Is there a way to prevent this condition? Ideally, I want a single application to connect to multiple devices.I assume that an application can only have one socket for the reason that multiple sockets will have the same problem as multiple instances above. My BLE device is the TI CC2540 keychain, acting as a heart rate monitor.

+5
source share
2 answers

I began to answer so that I had more space ...

I use a combination of Python and C to make my code work, so my "code" may look funny because it can come from anyone. In addition, I used Bluez 4, since 5 did not support the kernel that I used. Let me know if there is a problem and I can clarify.

It seems that there are several ways to do something, but in the end I opened separate sockets for different tasks. You can open one socket and then set the socket options to filter them, and you should get all the packets in one place. However, this was my initial way of doing this, and I found that my connections would die within seconds.

, socket(AF_BLUETOOTH, SOCK_RAW, BTPROTO_HCI), bind 0. ( , hci_get_route, ). hci_le_set_scan_parameters setsockopt(SOL_HCI, HCI_FILTER, filter), LE-, hci_le_set_scan_enable, .

socket(AF_BLUETOOTH, SOCK_SEQPACKET, BTPROTO_L2CAP), , connect struct sockaddr_l2, . . ( ... , . , . BUSY errno )

... , Bluez 5, DBUS. , , . , , , - ​​ 5 ( configure). lib , DBUS .

+2

hcitool gatttool. 2- (, hci_le_create_conn gatt_connect). , .

1 Start cmd_lescan (from hcitool.c)
2.For each device scanned - 
      cmd_lecc (from hcitool.c)
      gatt_connect (from gatttool.c)

, BLE. , :

        if (meta->subevent != 0x02)
                continue; 

.

+1

All Articles