mw.
mw.

Reputation: 367

Establishing multiple BLE connections simultaneously using BlueZ

I have a Linux C application which requires making multiple connections to BLE devices. The application uses a library stripped from gatttool. The BLE devices have a very slow advertising rate, so it takes a long time for a to connect to be established. As a result I need to be able to make multiple gatt_connect requests at the same time.

gatt_connect uses the standard socket/connect to set up a L2CAP connection to the devices. Although this method allows you to have multiple active connections, it only allows you to be establishing one connection at a time. Using the HCI interface you can can be establishing multiple interface at the same time (i.e. hcitool lecc --whitelist), however I can't figure a way to get this to work with the gatttool library L2CAP socket/connect.

Can anyone suggest a way to integrate the gatttool L2CAP socket/connect with the hci interface (hci_open_dev/hci_le_create_conn) handles used by "hcitool lecc --whitelist", or an alernative method to establish multiple connections simultaneously?

Upvotes: 6

Views: 3936

Answers (1)

Tim Tisdall
Tim Tisdall

Reputation: 10382

I think the whitelist method is the only way to handle establishing multiple connections at once. HCI is only able to handle establishing one connection at a time as (if I remember correctly) you don't have any connection handle until the connection is established.

The L2CAP socket is a kernel abstraction that utilizes the HCI method. If you try to start another connection while one is pending I think you get an error.

I suspect even the DBUS method mention is just an abstraction over the HCI method and it's still a process of making connections in sequence.

Even if you used the whitelist method, though, I'm not sure how much faster it'd actually be as the issue is the connection interval along with the advertising interval. The whitelist works by listening for advertising packets and establishing connections as they're detected. I've also never used the whitelist method, but you'd probably have to use an HCI socket and handle multiplexing the different devices over that one socket yourself.

Most hardware will allow you to establish connections while still scanning, so you can be collecting new ad packets while waiting for the current connection to establish. When a connection is finished establishing you can move to the next. As long as connection can be established relatively quickly, there's no benefit over using a whitelist. (the actual underlying implementation may be the same any way)

Upvotes: 8

Related Questions