在python中使用raspberry-pi蓝牙时遇到问题

2024-10-05 13:13:59 发布

您现在位置:Python中文网/ 问答频道 /正文

首先,如果有人知道在我的raspberry pi zero w上用python编写蓝牙代码的好教程,可以打开发现、监听配对请求、连接并保存配对设备等等,那将是非常棒的。我测试蓝牙发现的代码如下。在

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')))

回溯如下

^{pr2}$

Tags: 代码nameimporttruepi教程raspberryaddr
1条回答
网友
1楼 · 发布于 2024-10-05 13:13:59

(“访问蓝牙设备时出错”)就是线索。 是的-如前所述,您需要提升权限。 只需使用sudo运行脚本。。。 例如sudo pythonmyscript.py 输入您的密码 它现在应该可以工作了…用于测试目的。 用户将创建一个具有特权的bin/用户,并将其添加为false。 然后使用该用户运行所有脚本。。在

相关问题 更多 >

    热门问题