我想使用从 cron 脚本调用的 python 脚本来扫描 Raspberry 环境中的 ble 设备。但是当我在 cron 中执行此操作时(我的意思是我添加到 sudo crontab -e),我最终总是得到一个空列表。
当我以 pi 用户身份登录时 - btmgmt 可以(仅)在 su 权限下正常工作:
pi@Pluto:~ $ btmgmt find
Unable to start discovery. status 0x14 (Permission Denied)
pi@Pluto:~ $ sudo btmgmt find
Discovery started
hci0 type 7 discovering on
hci0 dev_found: 77:F8:D7:8A:1E:E5 type LE Random rssi -83 flags 0x0000
...
Run Code Online (Sandbox Code Playgroud)
所以在我的python脚本中我写道:
flog.write("P01:\r\n")
out = subprocess.Popen(['sudo', '/usr/bin/btmgmt', 'find'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
stdout, stderr = out.communicate()
flog.write("stderr: " + str(stderr) + "\r\n")
cDvc = stdout.split('\n')
flog.write("Amount …Run Code Online (Sandbox Code Playgroud)