Search code examples
pythonraspberry-pibluetooth-lowenergydbusbluez

Add SDP Service Record to Raspberry Pi 3


I'm trying to add sdp service record to my Raspberry Pi 3


import dbus

SERVICE_RECORD ="""
<?xml version="1.0" encoding="UTF-8" ?><record>
<attribute id="0x0000"><uint32 value="0x00010270" /></attribute><attribute id="0x0001"><sequence><uuid value="0x1124" /></sequence>
</attribute><attribute id="0x0004"><sequence><sequence><uuid value="0x0100" /><uint16 value="0x0011" /></sequence>
<sequence><uuid value="0x0011" /></sequence></sequence></attribute><attribute id="0x0005"><sequence><uuid value="0x1002" /></sequence>
</attribute><attribute id="0x0006"><sequence><uint16 value="0x656e" /><uint16 value="0x006a" /><uint16 value="0x0100" /></sequence>
</attribute><attribute id="0x0009"><sequence><sequence><uuid value="0x1124" /><uint16 value="0x0100" /></sequence></sequence>
</attribute><attribute id="0x000d"><sequence><sequence><sequence><uuid value="0x0100" /><uint16 value="0x0013" /></sequence>
<sequence><uuid value="0x0011" /></sequence></sequence></sequence></attribute><attribute id="0x0100"><text value="HID Device " />
</attribute><attribute id="0x0200"><uint16 value="0x0140" /></attribute><attribute id="0x0201"><uint16 value="0x0100" /></attribute>
<attribute id="0x0202"><uint8 value="0x40" /></attribute><attribute id="0x0203"><uint8 value="0x21" /></attribute><attribute id="0x0204"><boolean value="false"/>
</attribute><attribute id="0x0205"><boolean value="true" /></attribute><attribute id="0x0206"><sequence><sequence><uint8 value="0x22" />
<text encoding="hex" value="05010906a1010507850119e029e71500250175019508810295017508810195057501050819012905910295017503910195067508150026a4000507190029a48100c005010902a1010901a10085020509190129031500250195037501810295017505810305010930093109381581257f750895038106c0c0050c0901a101857f0600ff75089503150026ff001a00fc2a02fcb102c0" />
</sequence></sequence></attribute><attribute id="0x0207"><sequence><sequence><uint16 value="0x0309" /><uint16 value="0x0100" /></sequence></sequence>
</attribute><attribute id="0x0208"><boolean value="false" /></attribute><attribute id="0x020b"><uint16 value="0x0100" /></attribute>
<attribute id="0x020d"><boolean value="false" /></attribute><attribute id="0x020e"><boolean value="false" /></attribute></record>
"""

bus = dbus.SystemBus()

service = dbus.Interface(self.bus.get_object("org.bluez", "/org/bluez/hci0"),"org.bluez.Service")

service.AddRecord(SERVICE_RECORD)

But I always get this error :

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.7/dist-packages/dbus/proxies.py", line 70, in __call__
    return self._proxy_method(*args, **keywords)
  File "/usr/lib/python2.7/dist-packages/dbus/proxies.py", line 145, in __call__
    **keywords)
  File "/usr/lib/python2.7/dist-packages/dbus/connection.py", line 651, in call_blocking
    message, timeout)
dbus.exceptions.DBusException: org.freedesktop.DBus.Error.UnknownMethod: Method "AddRecord" with signature "s" on interface "org.bluez.Service" doesn't exist

I don't know what's the problem with AddRecord() function.

Any idea?


Solution

  • Your code is based on some very old Bluez API: The org.bluez.Service interface was removed many years ago.

    If you want to accomplish the same in modern linux with modern Bluez, take a look at the Profile API and how the example tool adds a service record.