Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 23131

Controlling raspberry pi bluetooth with a python script

$
0
0

I have a raspberry pi 4 model b running raspbian-lite 64-bit with Operating System: Debian GNU/Linux 12 (bookworm) and Kernel: Linux 6.6.20+rpt-rpi-v8.I have to control the Bluetooth of the raspberry with a python script.The script has to be able to enable/disable Bluetooth and rename the raspberry pi.

Currently, I use os.system(f"sudo hostnamectl set-hostname '{name}'") to rename the device and os.system(f"sudo systemctl restart bluetooth") to restart bluetooth.This only works some of the time, and often times I manually have to enter more commands in the console:

pi@One:~ $ bluetoothctl[bluetooth]# discoverable on[bluetooth]# exit

Is there a more elegant solution to do this, that may also allow for more functionality?


Viewing all articles
Browse latest Browse all 23131

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>