BlueZ D-Bus C or C ++ Sample

I am trying to write an application that searches for Bluetooth devices nearby and communicates with them. My application will be written in C ++ and is designed to work under Linux.

4 years ago I used BlueZ. But now, as I see it, the API has changed a lot, and now it uses D-Bus. I was not familiar with D-Bus. I looked at some tutorials related to the client / server model. Now everything is fine with the D-Bus.

But I could not find a single example explaining how to use BlueZ with D-Bus. I need a guide to use BlueZ and D-Bus together.

Is there any tutorial or sample for working with BlueZ via D-Bus in C or C ++?

(note: already sent to Google)

+4
source share
1 answer

You might want to check the file main.cin the folder of clientthe latest Bluez source code. This is the source code for the tool bluetoothctl. Run it too. The source code shows how they use GDBus, including proxies, agents, calling methods described in the API documentation (folder / doc), and all that. It is in C and uses a high level API.

I suggest you go through the code because it took me 2 weeks, endlessly trying to understand Bluez in C and the fact that there is no documentation there, but when I read this main.c file, I was ready in a day. Read the correct DBus API documentation and, more importantly, the concepts. Some documents that helped me:

gdbus: https://developer.gnome.org/gio/stable/gdbus.html

gdbus main.c . https://developer.gnome.org/gio/stable/gdbus-convenience.html

D-Feet - Dbus . /bluez. https://wiki.gnome.org/action/show/Apps/DFeet?action=show&redirect=DFeet

sudo apt-get install d-feet

, , , bluetoothctl , . http://dbus.freedesktop.org/doc/dbus-tutorial.html

bluetoothctl , , , , , , .

+14

Source: https://habr.com/ru/post/1618288/


All Articles