jivex5k
Posts: 20
Joined: Thu May 12, 2016 5:06 pm

RPi 3 onboard bluetooth to multiple speakers working (hacky)

Thu May 12, 2016 5:09 pm

UPDATE 9/8/16
I managed to hack my way into getting this working with the onboard bluetooth. It involves installing bluez5, running an hciattach command

Code: Select all

 sudo /usr/bin/hciattach /dev/ttyAMA0 bcm43xx 921600 noflow -
, uninstalling bluez5, and finally pairing the bluetooth speakers. I can confirm this works with bluez 4 sending audio to multiple speakers from the onboard bluetooth, however upon restarting it will not work.

I am now attempting to patch in support for bcm43xx in bluez 4, I think this is the last step required to get this at least working without having to have bluez 5 (which conflicts with 4 of course) installed at all. The pi-bluetooth package is simply a service that runs the above hciattach command, it requires bluez 5 because bluez4 doesn't support bcm43xx.

------------OLD STUFF----------------------------------------------------------------------------------------------------------------------------
I'm trying to get two bluetooth speakers connected via the native bluetooth controller. The first one connects and plays audio just fine. The second one never connects. Since I've searched and found some others are having an issue getting a single speaker working, allow me to explain the steps I took to achieve this:

Factory install raspbian jessie onto the raspberry pi 3. Run raspi-config in terminal and expand the filesystem, then reboot. Install pulseaudio bluetooth support via the following command.

Code: Select all

sudo apt-get install pulseaudio-module-bluetooth
You may want to update apt-get first using the command:

Code: Select all

sudo apt-get update
Restart the system. Once it reboots we will enter the bluetooth administration tool using the following command:

Code: Select all

bluetoothctl
This will enter a bluetooth administration console. From here we can scan for our speaker and pair it. Pulseaudio must be running for this to work, but it will start by default after you install the packages above. From the bluetooth console run the following command:

Code: Select all

scan on
After a bit you should see your speaker(s) listed. To pair and connect, issue the following commands:

Code: Select all

trust 00:02:3C:45:05:E7
pair 00:02:3C:45:05:E7
connect 00:02:3C:45:05:E7
You may not need to issue the trust and pair commands, but several searches showed attempting those commands should any issues arise in pairing. If it still doesn't work make sure the pulseaudio daemon is running, and pulseaudio-module-bluetooth is installed. After you are connected to the speaker you can exit by simply typing exit in the bluetooth console.

Now you can get your pulseaudio sinks by issuing the command:

Code: Select all

pactl list sinks
You should see the speaker listed. You can use this information to configure other applications to route their audio through it. Also, if you install the graphical interface for pulseaudio then you can easily manage the devices for your main desktop, and route the audio from the graphical inteface to the bluetooth speaker. You install it via this command:

Code: Select all

sudo apt-get install pavucontrol
You should see the option to manage pulse audio settings afterwards in the main raspbian menu on the desktop.

Now that we have gotten this far, my problem is I cannot connect to a second speaker when the first is connected. I am getting the following error:

Code: Select all

Attempting to connect to 00:02:3C:45:05:E7
[CHG] Device 00:02:3C:45:05:E7 Connected: yes
Failed to connect: org.bluez.Error.Failed
[CHG] Device 00:02:3C:45:05:E7 Connected: no
A look into the system logs provide a little insight, but I haven't found much info on how to fix this error besides downgrading bluez which is a very undesirable fix.

Code: Select all

 bluetoothd[670]: Unable to select SEP
So that's where I am right now. I'm unsure if the raspberry pi 3 onboard bluetooth interface can support multiple connections to speakers. Any help or nudge in the right direction would be greatly appreciated.
Last edited by jivex5k on Thu Sep 08, 2016 8:37 pm, edited 8 times in total.

jivex5k
Posts: 20
Joined: Thu May 12, 2016 5:06 pm

Re: RPi 3 can't connect more than 1 speaker with bluetooth.

Thu May 12, 2016 7:17 pm

For a bit more information on this, I was previously able to connect more than one speaker using bluez 4 and the ALSA plugin. I would pair the speakers using the simple-agent python script, and from there was able to configure asound.conf for each bluetooth speaker I pair. It would connect on demand via the alsa plugin when sound was sent to the outputs. I had to edit audio.conf for bluetooth to enable more than one SBC

Code: Select all

[General]
#Disable=socket
AutoConnect=true
Enable=Socket,Source,Sink,Media
#Disable=Socket
[A2DP]
SBCSources=50
The problem is with Bluez 5 this option doesn't exist anywhere. Audio.conf has been removed, and I can't use ALSA either since bluez 5 doesn't support it.

I'm looking into downgrading to bluez 4 at the moment, I believe I can accomplish more than one speaker connection since I was able to get it to work before. It was on OpenWRT but I still think it's worth a shot. Anyway, if anyone else has more info on configuring the bluez 5 settings, specifically in increasing the SBCSources it would be much better than downgrading the to bluez 4.

jivex5k
Posts: 20
Joined: Thu May 12, 2016 5:06 pm

Re: RPi 3 can't connect more than 1 speaker with bluetooth.

Fri May 13, 2016 2:02 pm

Still no luck with this. Going to update to the latest version of Jessie to see if that helps.
If it doesn't I'm going to try to downgrade to bluez 4 and use ALSA instead of pulseaudio.

EDIT - Updated to the 5/10/16 release, no luck. Still can only connect one speaker, looks like it's designed to function that way based on the gui integration that was added.

SantoshMullick
Posts: 2
Joined: Sat May 07, 2016 4:34 am

Re: RPi 3 can't connect more than 1 speaker with bluetooth.

Sat May 14, 2016 1:24 pm

As per the given instruction I am able to connect the Bluetooth speaker but no sound from speaker If I play the music on my raspberry Pi.

User avatar
Douglas6
Posts: 4783
Joined: Sat Mar 16, 2013 5:34 am
Location: Chicago, IL

Re: RPi 3 can't connect more than 1 speaker with bluetooth.

Sat May 14, 2016 3:22 pm

What are you using to play music? What happens when you

Code: Select all

aplay /usr/share/sounds/alsa/Front_Center.wav 

jivex5k
Posts: 20
Joined: Thu May 12, 2016 5:06 pm

Re: RPi 3 can't connect more than 1 speaker with bluetooth.

Sat May 14, 2016 5:11 pm

Douglas6 wrote:What are you using to play music? What happens when you

Code: Select all

aplay /usr/share/sounds/alsa/Front_Center.wav 
Aplay probably won't work. I don't have the hardware right now to test it but I would assume it does nothing to the bluetooth speaker since bluez 5 doesn't support the old alsa bluetooth plugin. I can test it Monday to make sure.

I'm using MPD to play the sound, sending it to my local pulseaudio server on the loopback address.
I had to modify

Code: Select all

etc/MPD.conf 
like so:

Code: Select all

audio_output {
    type            "pulse"
    name            "My Pulse Output"
    server          "127.0.0.1"             # optional
    sink            "bluez_sink.00_02_3C_44_C9_43"  # optional
}
And

Code: Select all

etc/pulse/default.pa
like so:

Code: Select all

load-module module-native-protocol-tcp auth-ip-acl=127.0.0.1
You have to change the sink name to your specific bluetooth speaker address.
Actually explaining this just gave me an idea to simply add the other speaker to the mpd configuration and see if it works without connecting it first. I don't think it will but it's worth a shot, won't be able to test it until Monday though.

Then I can use MPD to play audio. I have to connect to the speaker using bluetoothctl first though.
Also it works through the GUI if you disable the analog output in the sound preferences. This changed a bit with the latest update, now you can simply right click the audio icon and select the bluetooth speaker, but this will disconnect any other bluetooth speaker that was currently selected. It enables the web browser to play the audio through the speaker.

Anyway, thanks for the response, I was feeling alone on this issue.
Last edited by jivex5k on Sat May 14, 2016 5:14 pm, edited 1 time in total.

jivex5k
Posts: 20
Joined: Thu May 12, 2016 5:06 pm

Re: RPi 3 can't connect more than 1 speaker with bluetooth.

Sat May 14, 2016 5:12 pm

SantoshMullick wrote:As per the given instruction I am able to connect the Bluetooth speaker but no sound from speaker If I play the music on my raspberry Pi.
You have to configure MPD, or some other audio player to do it. See my above post for how I set up MPD to play through the speaker.

Also, paplay would probably work to test it, but not aplay since pulse handles the bluetooth and not ALSA.

User avatar
Douglas6
Posts: 4783
Joined: Sat Mar 16, 2013 5:34 am
Location: Chicago, IL

Re: RPi 3 can't connect more than 1 speaker with bluetooth.

Sat May 14, 2016 5:27 pm

@jivex5k, sorry, I was responding to SantoshMullick. I should have just asked him to start a new thread. By the way, aplay over Bluetooth DOES work; it surprised me too.

So you're trying to play to two Bluetooth speakers at the same time? Maybe I'll try that this weekend.

jivex5k
Posts: 20
Joined: Thu May 12, 2016 5:06 pm

Re: RPi 3 can't connect more than 1 speaker with bluetooth.

Sat May 14, 2016 5:34 pm

Douglas6 wrote:@jivex5k, sorry, I was responding to SantoshMullick. I should have just asked him to start a new thread. By the way, aplay over Bluetooth DOES work; it surprised me too.

So you're trying to play to two Bluetooth speakers at the same time? Maybe I'll try that this weekend.
No worries!
That's crazy aplay works, maybe I can get it working like I did before with asound.conf settings.
When ALSA was working with multiple speaker it would connect to them on demand when MPD started sending audio. Pulse seems to require a connection before hand, but I don't recall if I ever tried to send MPD to a pulse sink that wasn't connected. I don't think it would work since the sink disappears when the connection does.

Either way, more avenues to explore after the weekend! Thanks for the aplay test!

SantoshMullick
Posts: 2
Joined: Sat May 07, 2016 4:34 am

Re: RPi 3 can't connect more than 1 speaker with bluetooth.

Sat May 14, 2016 6:33 pm

Status of the connected BT Speaker is
[bluetooth]# info 08:EF:3B:11:6C:17
Device 08:EF:3B:11:6C:17
Name: LG SOUND BAR(6C:17)
Alias: LG SOUND BAR(6C:17)
Class: 0x240428
Icon: audio-card
Paired: yes
Trusted: yes
Blocked: no
Connected: yes
LegacyPairing: no
UUID: Audio Sink (0000110b-0000-1000-8000-00805f9b34fb)
UUID: A/V Remote Control Target (0000110c-0000-1000-8000-00805f9b34fb)
[CHG] Device 1C:3E:84:E5:3F:84 RSSI: -79
[CHG] Device 1C:3E:84:E5:3F:84 RSSI: -70
[bluetooth]# r
There is no other speaker connected to this Pi board, I Just Initiated on the new pi board.& playing video on Youtube.

Do I have to configure Audio driver's too for this?

jivex5k
Posts: 20
Joined: Thu May 12, 2016 5:06 pm

Re: RPi 3 can't connect more than 1 speaker with bluetooth.

Sat May 14, 2016 6:43 pm

SantoshMullick wrote:Status of the connected BT Speaker is
[bluetooth]# info 08:EF:3B:11:6C:17
Device 08:EF:3B:11:6C:17
Name: LG SOUND BAR(6C:17)
Alias: LG SOUND BAR(6C:17)
Class: 0x240428
Icon: audio-card
Paired: yes
Trusted: yes
Blocked: no
Connected: yes
LegacyPairing: no
UUID: Audio Sink (0000110b-0000-1000-8000-00805f9b34fb)
UUID: A/V Remote Control Target (0000110c-0000-1000-8000-00805f9b34fb)
[CHG] Device 1C:3E:84:E5:3F:84 RSSI: -79
[CHG] Device 1C:3E:84:E5:3F:84 RSSI: -70
[bluetooth]# r
There is no other speaker connected to this Pi board, I Just Initiated on the new pi board.& playing video on Youtube.

Do I have to configure Audio driver's too for this?
If you are using the gui I'd recommend upgrading to the latest raspbian jessie build since they integrated the bluetooth and pulse into it automatically. You just right click the speaker icon in the upper right and select the bluetooth speaker, the browser will automatically route to this new speaker.

If you are on Rasbian Jessie, just not the 5/10/16 release, you can update it like so:

Code: Select all

sudo apt-get update
sudo apt-get dist-upgrade
sudo apt-get install piclone geany usb-modeswitch
sudo apt-get install python-pigpio python3-pigpio
Then reboot and right click the speaker icon in the upper right, select your bluetooth speaker. It should already be listed there since you paired it via bluetoothctl.

The method I was using is for MPD specifically, but would work with any other console player that allows you to send audio to a pulseaudio sink.

spl23
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 378
Joined: Fri Dec 26, 2014 11:02 am

Re: RPi 3 can't connect more than 1 speaker with bluetooth.

Sat May 14, 2016 8:24 pm

You can pair multiple audio devices simultaneously, but you can only connect to one at a time - trying to connect to a second device will disconnect the first one. This seems to be a limitation of the way BlueZ works with PulseAudio; there is no obvious fix for it.

jivex5k
Posts: 20
Joined: Thu May 12, 2016 5:06 pm

Re: RPi 3 can't connect more than 1 speaker with bluetooth.

Wed May 18, 2016 9:47 pm

spl23 wrote:You can pair multiple audio devices simultaneously, but you can only connect to one at a time - trying to connect to a second device will disconnect the first one. This seems to be a limitation of the way BlueZ works with PulseAudio; there is no obvious fix for it.
Hmmm....
Well downgrading to 4.0 doesn't seem like it will be easy as the old Rasbian images weren't designed for the RPi 3.
I think I'm going to have to create a cross compilation environment to dig into the source files for pulse/bluez to get this to work. I've got some experience doing that for OpenWRT so it's not completely unreasonable.

If anyone could point me in the right direction to either downgrading bluez without using apt-get or compiling software for rasbian from the sources it would help me quite a bit. I'll be searching google in the meantime.

User avatar
Douglas6
Posts: 4783
Joined: Sat Mar 16, 2013 5:34 am
Location: Chicago, IL

Re: RPi 3 can't connect more than 1 speaker with bluetooth.

Wed May 18, 2016 10:09 pm

You can compile and build BlueZ 4 under Jessie (takes less than an hour on the Pi; I wouldn't bother cross-compiling). I personally doubt it will help. I just tested on my Android phone, and it also allows just one A2DP connection at a time.

jivex5k
Posts: 20
Joined: Thu May 12, 2016 5:06 pm

Re: RPi 3 can't connect more than 1 speaker with bluetooth.

Wed May 18, 2016 10:48 pm

Douglas6 wrote:You can compile and build BlueZ 4 under Jessie (takes less than an hour on the Pi; I wouldn't bother cross-compiling). I personally doubt it will help. I just tested on my Android phone, and it also allows just one A2DP connection at a time.
Oh duh... I was so used to cross compiling I hadn't considered that.
Bluez 4 with the ALSA plugin does allow multiple connections simultaneously, I did it on OpenWRT with some mips hardware. I'll continue to post my progress in this thread if I get it to work.

jivex5k
Posts: 20
Joined: Thu May 12, 2016 5:06 pm

Re: RPi 3 can't connect more than 1 speaker with bluetooth.

Fri May 20, 2016 9:45 pm

Compiled bluez 4.101 using this guide:
https://learn.adafruit.com/install-blue ... stallation

It's a start at least. hcitool is not showing the bluetooth adapter though, might not have the driver for the onboard bluetooth or maybe just not fully configured yet. Going to do a fresh install of the latest rasbian-lite. It might still have bluez 5 installed by default though, I removed it from my current setup using apt-get remove.

I remember editing the source files to add a specific adapter back when I was working on OpenWRT, going to dig through the files and see what I find. Previously I was able to use MPD and ALSA together, pairing the speakers with hciconfig would allow MPD to auto-connect to the speakers when it played music.

EDIT-
I remember now, I had to add a vendor/device code for an existing supported USB bluetooth dongle that was in the linux kernel. Well my linux kernel hasn't been downgraded, assuming the onboard bluetooth driver is in there then it should just be a configuration issue causing the adapter to not be listed with

Code: Select all

hcitool dev
Last edited by jivex5k on Fri May 20, 2016 9:55 pm, edited 1 time in total.

User avatar
Douglas6
Posts: 4783
Joined: Sat Mar 16, 2013 5:34 am
Location: Chicago, IL

Re: RPi 3 can't connect more than 1 speaker with bluetooth.

Fri May 20, 2016 9:48 pm

You could try just installing bluez-firmware to get the onboard adapter recognized?

jivex5k
Posts: 20
Joined: Thu May 12, 2016 5:06 pm

Re: RPi 3 can't connect more than 1 speaker with bluetooth.

Fri May 20, 2016 10:04 pm

Douglas6 wrote:You could try just installing bluez-firmware to get the onboard adapter recognized?
Says it's already installed. Even removed and reinstalled it, no luck. Also looked at pi-bluetooth and bluetooth, they would install bluez 5 though.

Can't enable the service to auto start, it's because my init script is for bluez 5, going to find the old one and use it.

EDIT - found one here:
https://github.com/igloocommunity/bluez ... tooth.init
Didn't work to get systemctl enable to work, and running the script itself says it's not executable.
I deleted it and enabled in turn worked with no errors, but isn't starting the service when I reboot. Not sure this is related to the adapter not being listed with hcitool or not.
Last edited by jivex5k on Fri May 20, 2016 10:16 pm, edited 1 time in total.

User avatar
Douglas6
Posts: 4783
Joined: Sat Mar 16, 2013 5:34 am
Location: Chicago, IL

Re: RPi 3 can't connect more than 1 speaker with bluetooth.

Fri May 20, 2016 10:16 pm

If you can't recognize the adapter, running the bluetoothd will have no effect. Do you have a USB adapter? You could install pi-bluetooth, and then adjust /etc/systemd /system/dbus-org.bluez.service to load the BlueZ 4 bluetoothd.
Last edited by Douglas6 on Fri May 20, 2016 10:19 pm, edited 2 times in total.

jivex5k
Posts: 20
Joined: Thu May 12, 2016 5:06 pm

Re: RPi 3 can't connect more than 1 speaker with bluetooth.

Fri May 20, 2016 10:18 pm

Douglas6 wrote:If you can't recognize the adapter, running the bluetoothd will have no effect. Do you have USB adapter?
Yep, USB adapter is seen. Would like to utilize the onboard one though.

EDIT-
Seems to be working, just scanned and it found the speakers. I'm going to see if I can get this working like I did with mips hardware running OpenWRT, if I can then it's just a matter of getting the onboard adapter recognized.
Last edited by jivex5k on Fri May 20, 2016 10:22 pm, edited 1 time in total.

User avatar
Douglas6
Posts: 4783
Joined: Sat Mar 16, 2013 5:34 am
Location: Chicago, IL

Re: RPi 3 can't connect more than 1 speaker with bluetooth.

Fri May 20, 2016 10:20 pm

See edit.


jivex5k
Posts: 20
Joined: Thu May 12, 2016 5:06 pm

Re: RPi 3 can't connect more than 1 speaker with bluetooth.

Wed Sep 07, 2016 10:02 pm

lugo wrote:Have you tried something along this line?
http://askubuntu.com/questions/661545/h ... th-dongles
No, haven't even managed to get the first dongle working with alsa.
Looks like I'm missing a shared object:

Code: Select all

Cannot open shared library /usr/lib/arm-linux-gnueabihf/alsa-lib/libasound_module_pcm_bluetooth.so
I thought this object was compiled with bluez 4 but apparently it's not. The information I've found about it refers to install bluez-alsa with apt-get which doesn't work on this build.

I've kind of hit a wall with this, I know if I can get the alsa plugin for bluetooth working correctly I'll be able to connect to multiple speakers. I've got the simple-agent python script able to connect to more than one with a single dongle, now it's a matter of getting the alsa bluetooth plugin working and after that getting to onboard bluetooth recognized.

I've found the plugins here:
ftp://ftp.alsa-project.org/pub/plugins/ ... .1.tar.bz2

I'm going to try and compile alsa from source to see if I can get the plugins working, it's complaining about not finding ALSA when I try to compile just the plugins.
Last edited by jivex5k on Wed Sep 07, 2016 10:11 pm, edited 1 time in total.

User avatar
Douglas6
Posts: 4783
Joined: Sat Mar 16, 2013 5:34 am
Location: Chicago, IL

Re: RPi 3 can't connect more than 1 speaker with bluetooth.

Wed Sep 07, 2016 10:05 pm

Have you done

Code: Select all

sudo apt-get install pulseaudio-module-bluetooth

jivex5k
Posts: 20
Joined: Thu May 12, 2016 5:06 pm

Re: RPi 3 can't connect more than 1 speaker with bluetooth.

Wed Sep 07, 2016 10:26 pm

Douglas6 wrote:Have you done

Code: Select all

sudo apt-get install pulseaudio-module-bluetooth
Just tried it, same missing shared object.

I was hopeful the plugin would be in the ALSA project tar file that is called plugins, it doesn't appear to be there though. I compiled both the base library and the plugins:

ftp://ftp.alsa-project.org/pub/lib/alsa ... .2.tar.bz2
ftp://ftp.alsa-project.org/pub/plugins/ ... .1.tar.bz2

They compiled and installed fine, but still missing this shared object. Maybe I can install the old alsa-bluez package by editing the package sources to an old version if there is one somewhere. I just need to figure out what to compile to get libasound_module_pcm_bluetooth.so

EDIT-
It's in the bluez source files, I found this a source file called pcm_bluetooth.c that contains references to ALSA.
Searching my entire system from root for the shared object shows nothing, so it didn't compile for some reason. There's probably just a configure flag I'm missing here.

EDIT2-
Bluez is compiling the plugin now. I think it wasn't detecting ALSA originally until I manually compiled it but it's there now. Put it in a different folder than Mplayer expected though, but that's fixable.

Now I'm running into connection refused errors:

Code: Select all

bt_audio_service_open: connect() failed: Connection refused (111)
I think I've run into this before, have to edit the dbus permissions I believe. Progress though, I've got ALSA and Bluez 4 compiled and installed at least with the python pairing script working.

EDIT3 -
Removed pulseaudio-bluetooth-module along with all the extra shit it installed and it's working now! I believe it was conflicting with bluez 4 and DBUS.

I should be able to set up mpd to connect to multiple speakers now. Going to dig through my old config files and see if I can get it all working like it was on OpenWRT. So close now, the last step may be another wall though in getting bluez 4 to recognize the onboard bluetooth module instead of resorting to a USB one.

Return to “Troubleshooting”