通过Python刷新PI蓝牙连接

问题描述 投票:0回答:1

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

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

bluetoothctl

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

python bluetooth-lowenergy raspberry-pi3
1个回答
0
投票

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

不工作:

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

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脚本。


Python中的Shell CommandsThreading

© www.soinside.com 2019 - 2024. All rights reserved.