简体   繁体   English

我可以在 Raspberry Pi 3 上使用带有 Python 3 的信标工具吗?

[英]Can I use beacontools with Python 3 on Raspberry Pi 3?

I'm trying to use beacontools lib.我正在尝试使用信标工具库。 It works perfectly with python 2.7, but does not with 3.5.它适用于 python 2.7,但不适用于 3.5。

I'm trying to test it with a code provided in examples我正在尝试使用示例中提供的代码对其进行测试

import time
from beacontools import BeaconScanner, IBeaconFilter

def callback(bt_addr, rssi, packet, additional_info):
    print("<%s, %d> %s %s" % (bt_addr, rssi, packet, additional_info))

# scan for all iBeacon advertisements from beacons with the specified uuid
scanner = BeaconScanner(callback,
    device_filter=IBeaconFilter(uuid="05f62a3d-f60f-44bc-b36e-2b80fd6c9679")
)
scanner.start()
time.sleep(5)
scanner.stop()

What I have got is:我得到的是:

Traceback (most recent call last): File "/usr/lib/python3.5/threading.py", line 914, in _bootstrap_inner self.run() File "/home/pi/.local/lib/python3.5/site-packages/beacontools/scanner.py", lin e 98, in run self.set_scan_parameters() File "/home/pi/.local/lib/python3.5/site-packages/beacontools/scanner.py", lin e 151, in set_scan_parameters scan_parameter_pkg) _bluetooth.error: (1, 'Operation not permitted')回溯(最近一次调用):文件“/usr/lib/python3.5/threading.py”,第 914 行,在 _bootstrap_inner self.run() 文件“/home/pi/.local/lib/python3.5/ site-packages/beacontools/scanner.py”,第 98 行,运行中 self.set_scan_parameters() 文件“/home/pi/.local/lib/python3.5/site-packages/beacontools/scanner.py”,lin e 151, in set_scan_parameters scan_parameter_pkg) _bluetooth.error: (1, 'Operation not allowed')

What is the reason of 'Operation not permitted'? “不允许操作”的原因是什么? The same code works with python 2.7相同的代码适用于 python 2.7

I'm not sure about the Python version, but I faced the same issue too. 我不确定Python版本,但是我也遇到了同样的问题。 Running the script with sudo worked. 使用sudo运行脚本有效。

您需要以 root 身份运行 python,例如:

$ sudo python3 <your main.py>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM