Pair and connect new devices using Bluez5 DBUS API with C

0 votes

I have an Intel Edison with the latest Board software is latest available, and I am developing a bluetooth driver using the Eclipse based IDE. My Bluez version number in this edison release is 5.37. I am writing it for a system that scans for bluetooth devices nearby, detects sensor devices based on name and MAC address, pairs and connects sensor devices automatically.

But pairing and connecting has been a problem since I can detect sensor devices but I am unable to pair them through the bluez5 interface. I have tried using the D-BUS interface and its no good as I keep getting the following error message:

Method "FindAdapter" with signature "s" on interface "org.bluez.Manager" doesn't exist

Here's the code:

DBusMessage *msg, *reply;
DBusError err;
const char *reply_path;
char *path;

msg = dbus_message_new_method_call("org.bluez", "/","org.bluez.Manager", "FindAdapter");
dbus_message_append_args(msg, DBUS_TYPE_STRING, &adapter,DBUS_TYPE_INVALID);
dbus_error_init(&err);
reply = dbus_connection_send_with_reply_and_block(conn, msg, -1, &err);
dbus_message_unref(msg);

P.S.
DBusConnection *conn -> DBUS_BUS_SYSTEM
const char *adapter -> "hci0".

Oct 8, 2018 in IoT (Internet of Things) by Bharani
• 4,660 points
5,387 views

1 answer to this question.

0 votes

Although high-level APIs like Qt5, which also uses bluez underneath could be more straightforward to use, you should still be able to do what you're attempting. Pair and Connect are associated with the device-api.txt. To call these methods you can send dbus messages as in your code or build a Proxy object with the following parameters:

name : "org.bluez"

interface "org.bluez.Device1"

path : "/org/bluez/dev_AA_BB_CC_DD_EE" where AA_BB_CC_DD_EE is your device mac address.

If you choose to build a proxy object, you can call methods like Pair or Connect through the proxy.

And, I understand that you want to find which adapter to use (because of your "FindAdapter" method) however it seems you already know that your adapter name is "hci0".

Looking at the official documentation (https://git.kernel.org/cgit/bluetooth/bluez.git/tree/doc), I was able to find the following, which specifies that the interface was dropped in 2012: https://git.kernel.org/cgit/bluetooth/bluez.git/commit/doc?id=86a7b07c22f3a595ba3c48092359287905bf0878

I also noticed you were using the DBus low-level API, as advised by freedesktop themselves (read at the bottom of the page here: https://dbus.freedesktop.org/doc/api/html/group__DBus.html ), it's a complex API used for creating bindings in other languages or you can switch to GLib GDBus for a simpler API.

answered Oct 8, 2018 by nirvana
• 3,130 points

Related Questions In IoT (Internet of Things)

0 votes
1 answer

To communicate with multiple BLE devices using Windows 10 UWMP

Not fully sure if you are wanting ...READ MORE

answered Oct 8, 2018 in IoT (Internet of Things) by Upasana
• 8,620 points
1,553 views
+1 vote
1 answer

Configuring Raspberry Pi with Windows 10 IoT App using Rest API

You should use HttpClient instead of WebClient. Try ...READ MORE

answered Oct 10, 2018 in IoT (Internet of Things) by anonymous2
• 4,280 points
718 views
0 votes
1 answer
0 votes
1 answer

Android Ble GATT_ERROR 133 getting often with samsung devices

I tried the following code #!/usr/bin/python import ibmiotf.device from time ...READ MORE

answered Jul 18, 2018 in IoT (Internet of Things) by anonymous2
• 4,280 points
2,134 views
0 votes
1 answer

Intel Galileo Vs. Intel Edison?

Intel Galileo Key Features: Type: Single-Board Computer CPU: Intel Quark ...READ MORE

answered Aug 20, 2018 in IoT (Internet of Things) by DataKing99
• 8,240 points
1,863 views
0 votes
1 answer

Bluetooth RfcommService

Hard code the address on your client ...READ MORE

answered Nov 2, 2018 in IoT (Internet of Things) by nirvana
• 3,130 points
854 views
0 votes
1 answer

How to detect presence of a device in a WiFi network?

Finding the mac-address would probably work. Basically, ...READ MORE

answered Nov 16, 2018 in IoT (Internet of Things) by Shubham
• 13,490 points
3,101 views
0 votes
1 answer

AT commands for Loop

I had a brief look at the AT ...READ MORE

answered Nov 22, 2018 in IoT (Internet of Things) by Shubham
• 13,490 points
795 views
0 votes
1 answer

Displaying Table Schema using Power BI with Azure IoT Hub

Answering your first question, Event Hubs are ...READ MORE

answered Aug 1, 2018 in IoT (Internet of Things) by nirvana
• 3,130 points
990 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP