BlueZ 5.30: D-Bus GATT API - Simply Discover and Connect to a BLE device in C

s2c97 picture s2c97 · Jun 12, 2015 · Viewed 11.8k times · Source

With the last release of BlueZ (5.30) the highlight was the completion of the GATT D-Bus apis. My goal is to programmatically (in C), as a BLE client:

  1. scan for ble devices (which I can do with the hci layer)
  2. Connect to an advertising BLE device
  3. Get the UUIDs
  4. Execute Read and Write to handles

The BlueZ community is strongly suggesting to use the GATT-Dbus api to accomplish this. After multiple searches and head scratching I was not successful to find a proper way or example that would perform this through GATT-DBUs api. It seems more complicate than just use directly the GATT layer. Unfortunately BlueZ removed direct access to make calls to gatt.

I'm very close to just pull the GATT source files out from Bluez, compile it as it's own independent library and directly use the GATT layer and calls to connect and execute reads/writes to ble device server. I know it is not the suggested way compared to the DBUS-GATT api but I'm out of options.

If anybody has any input on this or suggestion (with some sample code) please advise.

thank you in advance!

Answer

Jorge Martinez picture Jorge Martinez · Jun 15, 2015

The best way to start with DBUS GATT API is to hace a look at the source code here: http://git.kernel.org/cgit/bluetooth/bluez.git/tree/

Under client folder you can find a full sample of how to use the DBUS GATT API. Actually that is the source of bluetoothctl tool.

Note that DBUS GATT API is still experimental but you can enable it running bluetoothd service with -E flag.