Moode Forum
Detect if Bluetooth is active/playing using python - Printable Version

+- Moode Forum (https://moodeaudio.org/forum)
+-- Forum: moOde audio player (https://moodeaudio.org/forum/forumdisplay.php?fid=3)
+--- Forum: Support (https://moodeaudio.org/forum/forumdisplay.php?fid=7)
+--- Thread: Detect if Bluetooth is active/playing using python (/showthread.php?tid=3743)



Detect if Bluetooth is active/playing using python - Max Schmeling - 04-26-2021

How can I, using python(3), check if the Bluetooth connection is active and, and if a device is connected?


RE: Detect if Bluetooth is active/playing using python - Tim Curtis - 04-26-2021

The active flags are below. "1" = active.

Code:
pi@rp2:~ $ moodeutl -q "select * from cfg_system where param like '%active%'"
17|rbactive|0
50|aplactive|0
83|btactive|0
94|slactive|0
103|spotactive|0
120|inpactive|0
pi@rp2:~ $

To get the name of a connected Bluetooth device use the command below and parse the output.

Code:
# No device connected
pi@rp2:~ $ sudo /var/www/command/bt.sh -c
** Connected devices
**
**
pi@rp2:~ $

# Device connected
pi@rp2:~ $ sudo /var/www/command/bt.sh -c
** Connected devices
**
** XX:XX:XX:XX:XX:XX Tim's iPhone
**
pi@rp2:~ $ 



RE: Detect if Bluetooth is active/playing using python - Max Schmeling - 04-26-2021

Is it in any way possible to do this in Python?


RE: Detect if Bluetooth is active/playing using python - TookaFace - 04-27-2021

For sqlite: https://docs.python.org/3/library/sqlite3.html
For sudo /var/www/command/bt.sh -c, you can use subprocess: https://docs.python.org/fr/3/library/subprocess.html