Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bluez Programming

I'm programming in BlueZ on my Raspberry Pi with an USB Bluetooth dongle. I need to be able to programmatically connect to an Arduino BT, the problem is that the Bluetooth module of the Arduino is still using legacy pairing so whenever I try to open a socket to the device I get a Permission Denied. How do I send along a PIN to complete the pairing request through BlueZ?

like image 637
Hatted Rooster Avatar asked Apr 21 '15 08:04

Hatted Rooster


People also ask

What programming language is used for Bluetooth?

The APIs are designed in such a way that developers can use the Java programming language to build new Bluetooth profiles on top of this API as long as the core layer specification does not change.

What is BlueZ and Dbus?

D-Bus allows communication between multiple processes running concurrently on the same machine. In the case of BlueZ this is between the Bluetooth Daemon ( bluetoothd ) and the application you have written.

What is BlueZ in Linux?

BlueZ is the official Linux Bluetooth stack. It provides, in it's modular way, support for the core Bluetooth layers and protocols. Currently BlueZ consists of many separate modules: Bluetooth kernel subsystem core. L2CAP and SCO audio kernel layers.


1 Answers

You might want to check out the main.c file in the client folder of the most recent Bluez source code. It's the source code for the bluetoothctl tool. Run it too. The source code shows exactly how they use GDBus, including proxies, agents, calling methods like described in the API (/doc folder) and all that. It's in C and uses the high level API.

I suggest you step through the code because it took me 2 weeks endlessly trying to understand Bluez in C and the fact that there's no documentation, but when I read that main.c file I was ready in a day. Read up on proper Dbus API documentation and more importantly the concepts. Some documents that helped me:

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

These contain all the calls to gdbus and objects in the main.c file and explain them very well. https://developer.gnome.org/gio/stable/gdbus-convenience.html

D-Feet, an invaluable tool to inspecting and learning about Dbus on your system. Try checking out the /bluez bus. https://wiki.gnome.org/action/show/Apps/DFeet?action=show&redirect=DFeet

or

sudo apt-get install d-feet

Not much of a tutorial, but worth a read to understand some concepts, as the bluetoothctl tool fits into what they're trying to say here. http://dbus.freedesktop.org/doc/dbus-tutorial.html

The bluetoothctl creates an interactive shell though, so it might not be wise to waste time trying to fit in your code, but just pick what you need from it.

like image 156
Zimano Avatar answered Sep 21 '22 10:09

Zimano