I'm trying to make a call to a BLE device using DBus in Ubuntu Desktop 23.10.
This is DBus definition of the device in bluez:
user@machine-desktop:~$ sudo busctl introspect org.bluez /org/bluez/hci0/dev_00_12_05_FF_13_A0
NAME TYPE SIGNATURE RESULT/VALUE FLAGS
org.bluez.Device1 interface - - -
.CancelPairing method - - -
.Connect method - - -
.ConnectProfile method s - -
.Disconnect method - - -
.DisconnectProfile method s - -
.Pair method - - -
.Adapter property o "/org/bluez/hci0" emits-change
.Address property s "00:1C:05:FF:13:A0" emits-change
.AddressType property s "public" emits-change
.Alias property s "Nonin3230_502726737" emits-change writable
.Appearance property q 3137 emits-change
.Blocked property b false emits-change writable
.Bonded property b true emits-change
.Class property u - emits-change
.Connected property b false emits-change
.Icon property s - emits-change
.LegacyPairing property b false emits-change
.ManufacturerData property a{qv} - emits-change
.Modalias property s - emits-change
.Name property s "Nonin3230_502726737" emits-change
.Paired property b true emits-change
.RSSI property n - emits-change
.ServiceData property a{sv} - emits-change
.ServicesResolved property b false emits-change
.Sets property a{oa{sv}} - emits-change
.Trusted property b true emits-change writable
.TxPower property n - emits-change
.UUIDs property as 6 "00001800-0000-1000-8000-00805f9b34fb… emits-change
.WakeAllowed property b - emits-change writable
org.freedesktop.DBus.Introspectable interface - - -
.Introspect method - s -
org.freedesktop.DBus.Properties interface - - -
.Get method ss v -
.GetAll method s a{sv} -
.Set method ssv - -
I'm trying to get ServiceData property value, using :
user@machine-desktop:~$ dbus-send --system --dest=org.bluez --print-reply /org/bluez/hci0/dev_00_1C_05_FF_13_A0 org.freedesktop.DBus.Properties.Get string:org.bluez.Device1 string:ServiceData
Error org.freedesktop.DBus.Error.InvalidArgs: No such property 'ServiceData'
Shouldn't I be able to invoke property and get value?
Regards.
EDIT: forget to say archis arm64. Raspberry PI 4b
After skimming through the BlueZ source code (src/device.c), it seems that the service reports properties as non-existent when the corresponding struct field is null.
They remain visible in the "introspection" XML as that is defined statically, but BlueZ has its own handler for the Get() method which will "manually" return a D-Bus error in case the field is null.
(Most likely the reason for doing so is because D-Bus has neither nullable types nor 'maybe' types, so perhaps the BlueZ developers wanted to avoid confusion that might occur if null properties returned 0
or ""
when they're empty?)
So it seems you should either consider the error to be expected and handle it in your code – or, alternatively, use GetAll() to get a dict with all properties that "exist".