我在我的raspberry Pi4上用bluepy library为扫描蓝牙设备运行此代码
while True:
try:
#10.0 sec scanning
ble_list = ble.Scanner().scan(10)
for dev in ble_list:
print("rssi: {} ; mac: {}".format(dev.rssi,dev.addr))
except:
raise Exception("Error occured")
但我有一个错误:
Traceback (most recent call last):
File "/home/pi/Desktop/Progetti SIoTD/Bluetooth/prova2.py", line 4, in <module>
devices = scanner.scan(10.0)
File "/home/pi/Desktop/Progetti SIoTD/bluepy/btle.py", line 885, in scan
self.start(passive=passive)
File "/home/pi/Desktop/Progetti SIoTD/bluepy/btle.py", line 823, in start
self._mgmtCmd("le on")
File "/home/pi/Desktop/Progetti SIoTD/bluepy/btle.py", line 325, in _mgmtCmd
raise BTLEManagementError("Failed to execute management command '%s'" % (cmd), rsp)
bluepy.btle.BTLEManagementError: Failed to execute management command 'le on' (code: 20, error: Permission Denied)
Process finished with exit code 1
有人知道错误是什么吗? 提前谢谢
更新:
如果在终端中运行脚本(使用sudo),则会出现以下错误:
Traceback (most recent call last):
File "prova2.py", line 1, in <module>
import bluepy.btle as ble
File "/usr/local/lib/python2.7/dist-packages/bluepy-1.3.0-py2.7.egg/bluepy/__init__.py", line 2, in <module>
from . import btle
File "/usr/local/lib/python2.7/dist-packages/bluepy-1.3.0-py2.7.egg/bluepy/btle.py", line 14, in <module>
from queue import Queue, Empty
ImportError: No module named queue
如果我使用python IDE Pycharm运行相同的脚本,错误是:
Traceback (most recent call last):
File "/home/pi/Desktop/Progetti SIoTD/Bluetooth/prova2.py", line 6, in <module>
ble_list = ble.Scanner().scan(10)
File "/home/pi/Desktop/Progetti SIoTD/bluepy/btle.py", line 885, in scan
self.start(passive=passive)
File "/home/pi/Desktop/Progetti SIoTD/bluepy/btle.py", line 823, in start
self._mgmtCmd("le on")
File "/home/pi/Desktop/Progetti SIoTD/bluepy/btle.py", line 325, in _mgmtCmd
raise BTLEManagementError("Failed to execute management command '%s'" % (cmd), rsp)
bluepy.btle.BTLEManagementError: Failed to execute management command 'le on' (code: 20, error: Permission Denied)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/pi/Desktop/Progetti SIoTD/Bluetooth/prova2.py", line 10, in <module>
raise Exception("Error occured")
Exception: Error occured
相反,如果我使用python3在终端中执行脚本:
Traceback (most recent call last):
File "prova2.py", line 1, in <module>
import bluepy.btle as ble
ModuleNotFoundError: No module named 'bluepy'
目前没有回答
相关问题 更多 >
编程相关推荐