Tagged: Bluetooth Auto Connect
- 4. July 2017 at 19:58 #29800
I have a Squeezelite instance running on m2p on a Pi3 connected to a Bluetooth speaker.
My Bluetooth speaker (a Samsung R1) has multiple inputs, plus times out after 15 mins or so of inactivity.
Currently, if I change the input on R1 away from Bluetooth, then back to Bluetooth (or if R1 times out, or I switch R1 off, then back on again) the connection is lost but does not automatically reconnect – I have to click Connect button again from Bluetooth tab on Max2Play web UI to get playing again.
Would it not be possible to have a script to run (via cron or otherwise) to reconnect automatically (to last or only paired/trusted device). I managed to create a short script as follows that does a reconnect when I run it (same as clicking Connect button), just not sure how to get it to run the whole time. Can this be added to Max2Play web interface as an option, or help to automate please?
bluetoothctl << EOF
connect XX:XX:XX:XX:XX:XX (MAC of already paired/trusted bluetooth device).
EOF6. July 2017 at 13:36 #29838
In case anyone is interested, I managed to solve this myself.
I had to:
1) Via Max2Play web UI, Update to Beta, then Update Squeezelite
– this was necessary to get the GPIO squeezelite build option that -S command line option depends on.
2) In Squeezelite advanced options, set Command Line Options to -B -S /opt/squeezelite/btrecon.sh
– this tells squeezelite to run my btrecon.sh script passing a 1 or 0 command line arg when player is switched on or off via iPeng / OrangeSqueeze.
3) Create the script below (and make executable) at /opt/squeezelite/btrecon.sh
– the script just runs bluetoothctl and either issues a connect or disconnect command to my BT speaker.
if [ “$power_state” = “1” ]
# echo $(date) ” $power_state Power switch on ” >> /opt/squeezelite/log/btrecon.log
# echo $(date) ” $power_state Power switch off ” >> /opt/squeezelite/log/btrecon.log
Works a treat!6. July 2017 at 14:35 #29842
First of all, thanks for sharing your process and your solution in detail!
I was just about to answer your first post, but its great you got it working yourself. I still wanted to mention that the Plugin Builder is a great option to create solutions for something like this. If you are interested/open to checking this out, you could just share the .tar-file of the plugin with anyone who wants to have the same solution. Here are some more infos: https://www.max2play.com/en/developers-corner/
Nonetheless, great job! We will look into it in more detail as well.
You must be logged in to reply to this topic.