问题描述:

I am writing a bluetooth driver for Intel Edison. Board software is latest available, and I am developing using the Eclipse based IDE.

Bluez version number in this edison release is 5.37.

I am designing a system which has to meet the following requirements:

  • Scan for bluetooth devices nearby. [X]
  • Detect sensor devices based on name and MAC address. [X]
  • Pair and connect sensor devices automatically. []

Last item is the problem since I can detect sensor devices but I am not able to pair them using the bluez5 interface. So far I have tried to use the D-BUS interface but it is not working since I keep getting the following error message:

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

Code is presented here. Please note:

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

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);

Any ideas?

网友答案:

To give you an anwser, Pair and Connect are associated with the device-api.txt. To call these methods you can send dbus messages (like you did in the code presented above) or build a Proxy object with the following parameters (found in the documentation) :

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.


Could you explain what you are trying to achieve in the code above ? I understand that you want to find which adapter to use (I see the "FindAdapter" method) however it seems you already knows that your adapter name is "hci0".


I have been working with the DBus API exposed by Bluez recently and I was unfamiliar with the interface "org.bluez.Manager".

After a quick search in the official documentation (https://git.kernel.org/cgit/bluetooth/bluez.git/tree/doc) I was able to find the following commit 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 ), this is very complex API useful to create bindings in other languages. If you can, switch to GLib GDBus for a much simpler API.

相关阅读:
Top