【问题标题】:Pybluez RFCOMM server on Linux no advertisable serviceLinux 上的 Pybluez RFCOMM 服务器没有广告服务
【发布时间】:2016-07-05 18:00:54
【问题描述】:

我正在尝试在 Raspbian Linux 上运行一个非常简单的蓝牙服务器。如果有什么不同,我使用的是 Raspberry Pi 3 的蓝牙适配器而不是加密狗。

from bluetooth import *

server_sock=BluetoothSocket( RFCOMM )
server_sock.bind(("",PORT_ANY))
server_sock.listen(1)

port = server_sock.getsockname()[1]

uuid = "94f39d29-7d6d-437d-973b-fba39e49d4ee"

advertise_service( server_sock, "SampleServer",
               service_id = uuid,
               service_classes = [ uuid, SERIAL_PORT_CLASS ],
               profiles = [ SERIAL_PORT_PROFILE ], 
#                   protocols = [ OBEX_UUID ] 
                )

print("Waiting for connection on RFCOMM channel %d" % port)

client_sock, client_info = server_sock.accept()
print("Accepted connection from ", client_info)

try:
    while True:
        data = client_sock.recv(1024)
        if len(data) == 0: break
        print("received [%s]" % data)
except IOError:
    pass

print("disconnected")

client_sock.close()
server_sock.close()
print("all done")

运行时会产生以下错误:

Traceback (most recent call last):
  File "rfcomm-server.py", line 15, in <module>
    profiles = [ SERIAL_PORT_PROFILE ], 
  File "build/bdist.linux-armv7l/egg/bluetooth/bluez.py", line 268, in    advertise_service
bluetooth.btcommon.BluetoothError: error no advertisable device.

我看到很多人都使用这个确切的代码,所以我有点惊讶我没有发现任何关于这个特定问题的提及。客户端版本也可以正常工作。

【问题讨论】:

    标签: linux raspbian rfcomm pybluez


    【解决方案1】:

    通过以下命令启用“启用页面和查询扫描”:

    $ hciconfig hciX piscan
    

    【讨论】:

    猜你喜欢
    • 2013-06-28
    • 1970-01-01
    • 1970-01-01
    • 2014-01-08
    • 1970-01-01
    • 1970-01-01
    • 2013-07-14
    • 1970-01-01
    相关资源
    最近更新 更多