【问题标题】:Add SDP Service Record to Raspberry Pi 3将 SDP 服务记录添加到树莓派 3
【发布时间】:2018-08-15 15:41:21
【问题描述】:

我正在尝试将 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() 函数有什么问题。

有什么想法吗?

【问题讨论】:

    标签: python raspberry-pi bluetooth-lowenergy dbus bluez


    【解决方案1】:

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

    如果您想在现代 linux 中使用现代 Bluez 完成相同的操作,请查看 Profile API 以及 example tool 如何添加服务记录。

    【讨论】:

      【解决方案2】:
       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)
      

      【讨论】:

        猜你喜欢
        • 2017-02-04
        • 1970-01-01
        • 2018-02-07
        • 2017-03-30
        • 2023-01-30
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多