Created
June 17, 2022 03:03
-
-
Save rcbadiale/fe5b0ee06e0b543f3cef09425e949406 to your computer and use it in GitHub Desktop.
Install pulseaudio on RaspberryPi OS, pair and connect BT speaker, download/enable autoconnect and create cronjob to play a 1Hz sound for 1s in order to keep BT Speaker always on.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| echo "Installing PulseAudio and BT Module" | |
| sudo apt update | |
| sudo apt upgrade -y | |
| sudo apt install -y git pulseaudio pulseaudio-module-bluetooth | |
| systemctl --user enable --now pulseaudio.service | |
| MAC_ADDRESS=<MAC_ADDRESS> | |
| echo "Pairing and connecting to $MAC_ADDRESS" | |
| coproc bluetoothctl | |
| echo -e 'agent on\npair $MAC_ADDRESS\ntrust $MAC_ADDRESS\nconnect $MAC_ADDRESS\nexit' >&p | |
| output=$(cat <&p) | |
| echo $output | |
| echo "Lowering the volume to 40% and testing speaker" | |
| amixer set Master 40% | |
| speaker-test -S5 -c2 -l1 -twav | |
| echo "Setting up auto connect" | |
| git clone https://github.com/jrouleau/bluetooth-autoconnect.git | |
| sudo apt install -y python3 python3-dbus python3-prctl | |
| sudo cp bluetooth-autoconnect/bluetooth-autoconnect /usr/local/bin | |
| sudo cp bluetooth-autoconnect/bluetooth-autoconnect.service /lib/systemd/system/ | |
| sudo cp bluetooth-autoconnect/pulseaudio-bluetooth-autoconnect.service /lib/systemd/user/ | |
| sudo systemctl enable --now bluetooth-autoconnect | |
| systemctl --user enable --now pulseaudio-bluetooth-autoconnect.service | |
| echo "Setting up cronjob to keep BT Speaker always on" | |
| sudo apt install -y sox | |
| ( crontab -l 2>/dev/null; echo "*/10 * * * * XDG_RUNTIME_DIR=/run/user/1000 /usr/bin/play -n synth 1 sin 1" ) | crontab - |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment