Thank you for your donation!


Cloudsmith graciously provides open-source package management and distribution for our project.


Detect if Bluetooth is active/playing using python
#1
How can I, using python(3), check if the Bluetooth connection is active and, and if a device is connected?
Reply
#2
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:~ $ 
Enjoy the Music!
moodeaudio.org | Mastodon Feed | GitHub
Reply
#3
Is it in any way possible to do this in Python?
Reply
#4
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
Reply


Forum Jump: