Reply To: [SOLVED] Pi3 Bluetooth Auto-Reconnect option / script?

Max2Play Home Forums Max2Play on Raspberry PI [SOLVED] Pi3 Bluetooth Auto-Reconnect option / script? Reply To: [SOLVED] Pi3 Bluetooth Auto-Reconnect option / script?

6. Juli 2017 at 13:36 #29838

Hi.
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.

#!/bin/bash
power_state=$1
if [ „$power_state“ = „1“ ]
then
# echo $(date) “ $power_state Power switch on “ >> /opt/squeezelite/log/btrecon.log
bluetoothctl <<EOF
connect CC:B1:1A:8C:45:E6
EOF

else
# echo $(date) “ $power_state Power switch off “ >> /opt/squeezelite/log/btrecon.log
bluetoothctl <<EOF
disconnect CC:B1:1A:8C:45:E6
EOF
fi

Works a treat!