5

I have a headless raspberry pi (it's networked but not plugged into any keyboard or monitor). I've previously used it to play music through a wired speaker plugged into the headphone socket.

I was wondering if it would be possible to connect the raspberry pi to a bluetooth speaker. But irritatingly all the information I can find about bluetooth and linux want do give me a GUI solution.

I'm looking for instructions on how to connect a debian (raspbian) machine to a blue tooth device (bluetooth speaker) from the command line only. The aim will be to do this over SSH.

Can anyone suggest a direction or tutorial for how to do this?

6
  • Do your speakers have a button with the Bluetooth symbol on it?
    – Seamus
    Feb 22, 2019 at 7:59
  • @Seamus yes. They are Bluetooth speakers, as stated in the question. Feb 22, 2019 at 9:16
  • I got that... I just wanted to verify they had the push button to facilitate the pairing process. Have you been able to accomplish that yet?
    – Seamus
    Feb 22, 2019 at 11:13
  • @Seamus I've honestly never seen a Bluetooth device without a pairing button or soft-button equivalent. It looks like bluetoothctl might be the start of it, but might be only step one of two. I will need to pair with the speaker, and I will need to set up the speaker as a sound device. Before I play around with bluetoothctl, I don't know if the second step is automatic. Feb 22, 2019 at 11:19
  • Thinking about it, there might be a step 3 where I choose which sound device to use. One thing at a time I guess. Feb 22, 2019 at 11:20

2 Answers 2

4

You can do it using bluetoothctl. There is a guide for it: https://bluedot.readthedocs.io/en/latest/pairpipi.html#using-the-command-line

0

Late to this, but: https://gist.github.com/simlei/226fdfec2063dd3bdae47b2c6ae6aca1

  • This "just" reconnects to bluetooth devices; for pairing and setting up a bluetooth device, use the method from this gist: (or adapt the expect script from this solution)

  • This uses expect, bluetoothctl and pactl (pulseaudio). It differes from the aforementioned stuff by also instrumenting pulseaudio. I found that just bluetoothctl did not get a bluetooth device that was out of range and disconnected, to reconnect and also play current audio through it. This is where pactl comes in.

  • it then scans pulseaudio cards and sinks to:

    • set the bluetooth device as default sink
    • change the profile to a2dp (substitute your own)
    • map all existing sources (like chrome+youtube, etc) to the bluetooth device so sound is routed through it
  • it shows self-closing message boxes if zenity is installed

works for my pc, yours may differ: untested & to be minimally reconfigured and tweaked ;)

2
  • Please answer the question with an answer that can stand for it self! The URLs can vanish and then the answer is unusable. So please add the missing info to your answer!
    – MatsK
    Nov 22, 2021 at 20:00
  • In this case the URL points to some source code whose usefulness is explained in the post. Re-posting source instead has worse pitfalls than an upstream link. We already very commonly refer to libraries, modules, and scripts such as this the same way.
    – goldilocks
    Nov 23, 2021 at 21:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.