bluetooth.sh 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #!/bin/bash
  2. # Used documentation
  3. # https://www.sigmdel.ca/michel/ha/rpi/bluetooth_n_buster_01_en.html
  4. # https://www.sigmdel.ca/michel/ha/rpi/bluetooth_01_en.html
  5. # Update system and install software
  6. sudo apt update && sudo apt --yes upgrade
  7. sudo apt install --yes bluealsa
  8. # Allow user pi to use bluetooth
  9. sudo adduser pi bluetooth
  10. # Enable as a2dp source and sink
  11. sudo sed -e '/^ExecStart.*/s/$/ -p a2dp-source -p a2dp-sink/' \
  12. -i /lib/systemd/system/bluealsa.service
  13. # Disable SIM access profile
  14. sudo sed -e '/^ExecStart.*/s/$/ --noplugin=sap/' \
  15. -i /lib/systemd/system/bluetooth.service
  16. # Load new kernel/bt modules, apply group access and restart services
  17. sudo reboot
  18. ## Interactive
  19. # sudo bluetoothctl
  20. # scan on
  21. # scan off
  22. # pair 50:18:06:52:53:C5
  23. # connect 50:18:06:52:53:C5
  24. # trust 50:18:06:52:53:C5
  25. # quit
  26. # btid="50:18:06:52:53:C5"
  27. # Test Playback
  28. aplay -D bluealsa:DEV=$btid /usr/share/sounds/alsa/Noise.wav
  29. # Set system-wide default device and test again
  30. # Alternative same file works in the in user context: ~/.asoundrc
  31. cat <<EOF | sudo tee /etc/asound.conf
  32. pcm.!default {
  33. type plug
  34. slave.pcm {
  35. type bluealsa
  36. device "$btid"
  37. profile "a2dp"
  38. }
  39. }
  40. EOF
  41. aplay /usr/share/sounds/alsa/Noise.wav