0

The Raspberry PI seems to be dropping the connection to (some?) paired devices after 5-15 minutes of running a python script.

The Connection can be recreated with this shell command:

bluetoothctl

But to enter this command, the script would have to be killed and restarted afterwards.

kilian579
  • 68
  • 2
  • 11

1 Answers1

0

Attention: After testing this approach for a while I found out it didn't fix the problem in general

NOT WORKING:

Although I didn't test running my program for several hours, this seems to do the trick.

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

Using the shell command watch bluetoothctl is important here, otherwise the bluetoothctl process would block you python script.


Shell Commands & Threading in Python

Community
  • 1
  • 1
kilian579
  • 68
  • 2
  • 11