繁体   English   中英

通过Python刷新PI蓝牙连接

[英]Refreshing PI Bluetooth Connection via Python

在运行python脚本5-15分钟后,Raspberry PI似乎正在放弃与(某些?)配对设备的连接。

可以使用以下shell命令重新创建Connection:

bluetoothctl

但要输入此命令,脚本必须在之后被杀死并重新启动。

注意:经过一段时间的测试后,我发现它并没有解决这个问题

不工作:

虽然我没有测试运行我的程序几个小时,但这似乎可以解决问题。

from threading import Thread
from time import sleep
import subprocess

def bluetooth_stay_awake():
    """Ping the bluetooth compontent to keep all connections up"""
    thread= Thread(target=(lambda:subprocess.run(["watch", "bluetoothctl"])))
    thread.start()

使用shell命令watch bluetoothctl在这里很重要,否则bluetoothctl进程会阻止你的python脚本。


Shell命令和Python中的线程

暂无
暂无

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

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