0
我想在Raspbian Linux上运行一个非常简单的蓝牙服务器。如果它有什么区别,我正在使用Raspberry Pi 3的蓝牙适配器,而不是加密狗。Linux上的Pybluez RFCOMM服务器没有可推广的服务
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.
我见过很多人用这个确切的代码,所以我有点惊讶我还没有发现这个任何提及具体问题。此外,这个客户端版本工作得很好。
谢谢,我应该提到去年我想通了这一点。原来我没有串口配置文件,需要在兼容模式下运行守护进程。对于其他任何人来说,答案可以在这里找到https://www.raspberrypi.org/forums/viewtopic.php?f=63&t=133263 – user3781314