【发布时间】:2018-03-10 20:25:09
【问题描述】:
首先,如果有人知道使用 python 在我的树莓派零 w 上编写蓝牙以打开发现、侦听配对请求、连接并保存配对设备等的好教程,那将是很棒的。我测试蓝牙发现的代码如下。
import bluetooth
print("performing inquiry...")
nearby_devices = bluetooth.discover_devices(
duration=8, lookup_names=True, flush_cache=True)
print("found %d devices" % len(nearby_devices))
for addr, name in nearby_devices:
try:
print(" %s - %s" % (addr, name))
except UnicodeEncodeError:
print(" %s - %s" % (addr, name.encode('utf-8', 'replace')))
TraceBack 在下面
Traceback (most recent call last):
File "bluetoothConnect.py", line 6, in <module>
duration=8, lookup_names=True, flush_cache=True)
File "/usr/lib/python2.7/dist-packages/bluetooth/bluez.py", line 17, in discover_devices
sock = _gethcisock ()
File "/usr/lib/python2.7/dist-packages/bluetooth/bluez.py", line 226, in _gethcisock
raise BluetoothError ("error accessing bluetooth device")
bluetooth.btcommon.BluetoothError: error accessing bluetooth device
【问题讨论】:
-
您使用的是哪种树莓派?它有蓝牙设备吗?您是否尝试过以 root 身份运行?
-
树莓派零 w,是的,它有蓝牙。
-
以 root 身份运行怎么样?这可能是这里的关键之一
-
那我该怎么做呢?
-
如果其他人知道我可以尝试解决此问题的任何其他内容。 pi zero w 带有蓝牙,但我必须安装蓝牙和 python-bluez 包。我不明白为什么会出现此错误
标签: python bluetooth raspberry-pi