I need to write a multi-threading application using D-BUS/BlueZ/GATT Client and want to use libgio/GTK.
I took the scan code from author Parthiban:
His example scans and does not include GATT, but works quite well.
I am able to connect to the remote device easily enough:
result = g_dbus_connection_call_sync((GDBusConnection *)connection,
"org.bluez", // bus name
object_path, // Location of the remote device in DBUS
"org.bluez.Device1", // interface name
"Connect", // method name
NULL, // No parameters
NULL, // Expected reply type
G_DBUS_CALL_FLAGS_NONE, // Flags
10000, // 10 second timeout
NULL, // Cancellable
&error // error
);
Tracing HCI verifies that the open works.
This, as expected, created a bunch of characteristics in D-BUS that were made visible through :
prop_changed = g_dbus_connection_signal_subscribe(con,
“org.bluez”,
“org.freedesktop.DBus.Properties”,
“PropertiesChanged”,
NULL,
“org.bluez.Adapter1”,
G_DBUS_SIGNAL_FLAGS_NONE,
bluez_signal_adapter_changed,
NULL,
NULL);
GATT Characteristics that are discovered have a path that looks like this:
/org/bluez/hci0/dev_CC_F9_57_89_8B_D8/service000b/char000c
I then need to write and read the GATT characteristics. I tried to read a characteristic using this in a loop with repeat trials:
gatt_objects = g_dbus_connection_call_sync(con,
"org.bluez",
"/org/bluez/hci0/dev_CC_F9_57_89_8B_D8/service000b/char000c",
"org.freedesktop.DBus.Properties",
"Get",
NULL, // No parameters
NULL,
G_DBUS_CALL_FLAGS_NONE, // Flags
10000, // 10 second timeout
NULL, // Cancellable
&errorO // error
); // User data for callback
But then I repeatedly get this error every time I attempt the Get:
0x7ff244008360: bluez_device_new_connection: org.bluez,/org/bluez/hci0/dev_CC_F9_57_89_8B_D8/service000b/char000c,org.freedesktop.DBus.Properties,Get FAILED!
0x7ff244008360: print_error: Error message: GDBus.Error:org.freedesktop.DBus.Error.UnknownMethod: Method "Get" with signature "" on interface "org.freedesktop.DBus.Properties" doesn't exist
0x7ff244008360: print_error: Remote error
0x7ff244008360: print_error: Raw message: org.freedesktop.DBus.Error.UnknownMethod
0x7ff244008360: print_error: Stripped message: org.freedesktop.DBus.Error.UnknownMethod
I have been unable to find any GATT client examples using libgio.