将 SDP 服务记录添加到 Raspberry Pi 3

Add SDP Service Record to Raspberry Pi 3

我正在尝试将 sdp 服务记录添加到我的 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)

但我总是遇到这个错误:

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

不知道AddRecord()函数有什么问题

有什么想法吗?

您的代码基于一些非常 旧的 Bluez API:org.bluez.Service 接口在很多年前就被删除了。

如果您想在现代 linux 中使用现代 Bluez 完成相同的任务,请查看 Profile API and how the example tool 添加服务记录。

 UUID = "00000000-0000-1000-8000-00805F9B34FB"
 service_record = self.read_sdp_service_record()
 opts = {
        "AutoConnect": True,
        "RequireAuthentication":False,
        "RequireAuthorization":False,
        "ServiceRecord": service_record
 }
 bus = dbus.SystemBus()
 manager = dbus.Interface(bus.get_object(
        "org.bluez", "/org/bluez"), "org.bluez.ProfileManager1")
 manager.RegisterProfile("/org/bluez/hci0", UUID, opts)