I'm trying to create BLE GATT services on my Raspberry Pi 4 using C++. Have searched for a while but wasn't able to find useful hints/examples.
More details: I'm able to create GATT services and characteristics using commands:
#bluetoothctl
[bluetoothctl] menu gatt
[bluetoothctl] register-service 0xFFFF #
[bluetoothctl] register-characteristic 0xAAAA read,write #
[bluetoothctl] register-application #
and I want to achieve the same using C++ codes.
I have found the definition for void RegisterApplication(object application, dict options)
in https://github.com/Vudentz/BlueZ/blob/master/doc/gatt-api.txt, but it doesn't provide many details. My question is:
For this RegisterApplication function, what should I put for the 'object application' and 'dic options'? Is there any example in the format of
g_dbus_proxy_call(
Proxy,
"RegisterApplication",
Params,
G_DBUS_CALL_FLAGS_NONE,
-1,
NULL,
NULL,
NULL);
showing how the "params" should be constructed for my service and characteristic (registered using commands) above?
You need to build your BLE GATT service hierarchy in D-Bus and then with the RegisterApplication
tell BlueZ where the top-level of the service is located on D-Bus.
To use D-Bus parlance, the local BlueZ service needs to be created with D-Bus objects and then published. It is the D-Bus object of the published local BlueZ service hierarchy you've created that is the first argument of RegisterApplication
More information at: https://github.com/Kistler-Group/sdbus-cpp/blob/master/docs/using-sdbus-c++.md#using-d-bus-connections-on-the-server-side
You might also want to look at the following project to see how they did it: https://github.com/nettlep/gobbledegook