drgeoff
Posts: 7220
Joined: Wed Jan 25, 2012 6:39 pm

Re: [TUTORIAL] RPi as Bluetooth A2DP Reciever

Thu Jan 10, 2013 11:51 am

fredoll wrote:There is one little error in the udev bluetooth script proposed by
MachineShedFred (Mon Jan 07, 2013 1:31 pm)

Code: Select all

if [ ! -z $CONFIRM ]
Should be

Code: Select all

if [ ! -z "$CONFIRM" ]
Fred
But I don't get that far because the earlier 'find' command finds nothing in /sys/devices/virtual/input/.

blackhole
Posts: 3
Joined: Mon Jan 07, 2013 4:56 pm

Re: [TUTORIAL] RPi as Bluetooth A2DP Reciever

Sat Jan 12, 2013 6:47 pm

MachineShedFred solution worked for me finally when I changed PULSEAUDIO_SYSTEM_START=1 to PULSEAUDIO_SYSTEM_START=0 in /etc/default/pulseaudio. Don't forget to run sudo service pulseaudio restart after that.
The solution is not perfect, the first time I try to stablish an A2DP connection from my phone I get the following D-BUS errors in /var/log/messages: Unable to autolaunch a dbus-daemon without a $DISPLAY for X11
The second time it works but sound is not very good. Good luck

alxeder
Posts: 1
Joined: Wed Jan 23, 2013 9:41 am

Re: [TUTORIAL] RPi as Bluetooth A2DP Reciever

Wed Jan 23, 2013 9:44 am

hi there,
I made a complete structured writeup about this topic:
http://www.blackv.tk/general/raspberry- ... udio-sink/

rocket
Posts: 7
Joined: Thu Mar 07, 2013 10:46 pm

Re: [TUTORIAL] RPi as Bluetooth A2DP Reciever

Thu Mar 07, 2013 11:02 pm

Great tutorial!! I use linux rarely and got caught out for a while on the pulseaudio connection of source to sink (turns out you can't use lower case in the source mac address - doh).

I do have a question as I can't get the udev script to work at all (again due to my lack of linux skills). I understand what the script file "bluetooth" is meant to do but for some reason I can't get the input rule file to run it at all. I believe I have all permissions set correctly .

Just nothing happens when my ipad connects to the pi (it is already pre-paired). In udev monitor I can see the kernel message "...../input[x]" come up when the ipad connects but the bluetooth script (which has -rwxrwxr-- privilege) just won't run. The 99-input.rules file has -rw-r--r-- privilege.

I tried a simple script file to simply echo a message when bt connects but no go as well. The rule just doesn't get triggered.

UPDATE: Not sure what I did but the rule trigger now works! However, still not there yet as I can't get past the first echo command in the bluetooth script file. The only thing that gets written to the log file is "Executing bluetooth script..". Any help would be much appreciated!

UPDATE 2: Gave up on this script - used the one from here instead http://blog.mrverrall.co.uk/2013/01/ras ... audio.html. Also the pi needs to be logged in otherwise the stream would cut off after a few seconds of play. Use the instructions from here: http://raspberrypi.stackexchange.com/qu ... n-raspbian

alien_
Posts: 1
Joined: Sat Aug 04, 2012 10:45 pm

Re: [TUTORIAL] RPi as Bluetooth A2DP Reciever

Wed Mar 20, 2013 8:50 pm

Did anyone try to get this done with Alsa alone, without PulseAudio? Would it even be possible?

toxaris
Posts: 1
Joined: Fri Nov 15, 2013 7:51 pm

Re: [TUTORIAL] RPi as Bluetooth A2DP Reciever

Fri Nov 15, 2013 7:54 pm

Hello.

I have managed to pair my phone with my Pi.
But i get this error when I try to load the modules:

Code: Select all

pactl load-module module-loopback source=bluez_source.20_54_76_B3_94_9E sink=alsa_output.platform-bcm2835_AUD0.0.analog-stereo rate=44100 adjust_time=0
Failure: Module initialization failed
What is wrong?
The BT-ship is this BCM20702A0.

lkhan01123
Posts: 1
Joined: Sun Nov 17, 2013 8:07 am

Re: [TUTORIAL] RPi as Bluetooth A2DP Reciever

Sun Nov 17, 2013 8:09 am

I am having issue with my bluetooth stream.

My streaming stops after every few minutes and when i go to my phone and disconnect and connect again, it works fine.

Any ideas?
Wheezy

http://www.instructables.com/id/Turn-yo ... /?ALLSTEPS
http://kmonkey711.blogspot.com/2012/12/ ... ry-pi.html

Linux raspberrypi 3.6.11+ #538 PREEMPT Fri Aug 30 20:42:08 BST 2013 armv6l GNU/Linux

fdboer
Posts: 3
Joined: Fri Oct 05, 2012 7:14 am

Re: [TUTORIAL] RPi as Bluetooth A2DP Reciever

Fri Nov 22, 2013 8:08 am

Needed some dbus action to get the original script working ... the sound dropped after a few seconds even though the connection was still there. The following appears to work on my headless setup.

#!/bin/sh

echo "Executing bluetooth script...|$ACTION|" >> /var/log/bluetooth_dev

ACTION=$(expr "$ACTION" : "\([a-zA-Z]\+\).*")
if [ "$ACTION" = "add" ]
then
for dev in $(find /sys/devices/virtual/input/ -name input*)
do
if [ -f "$dev/name" ]
then
mac=$(cat "$dev/name" | sed 's/:/_/g')
bluez_dev=bluez_source.$mac

sleep 1

DBUS_DAEMON_PID=$(ps -u pi | grep dbus-daemon | cut -f1 -d" ")
if [ -z "${DBUS_DAEMON_PID}" ]
then
# start dbus-deamon for this user
eval $(sudo -u pi dbus-launch --sh-syntax)
(set | grep DBUS_SESSION_BUS_) > ~/.dbus/dbus-env; chown pi:pi ~/.dbus/dbus-env
echo "Started dbus session : $DBUS_SESSION_BUS_ADDRESS" >> /var/log/bluetooth_dev
else
# reuse existing dbus-daemon
. ~pi/.dbus/dbus-env
echo "Reusing dbus session : $DBUS_SESSION_BUS_ADDRESS" >> /var/log/bluetooth_dev
fi

CONFIRM=`sudo -u pi pactl list short | grep $bluez_dev`
if [ ! -z "${CONFIRM}" ]
then
echo "Setting bluez_source to: $bluez_dev" >> /var/log/bluetooth_dev
echo pactl load-module module-loopback source=$bluez_dev sink=alsa_output.platform-bcm2835_AUD0.0.analog-stereo rate=44100 adjust_time=0 >> /var/log/bluetooth_dev
sudo -u pi DBUS_SESSION_BUS_ADDRESS=${DBUS_SESSION_BUS_ADDRESS} pactl load-module module-loopback source=$bluez_dev sink=alsa_output.platform-bcm2835_AUD0.0.analog-stereo rate=44100 adjust_time=0 >> /var/log/bluetooth_dev
fi
fi
done
fi

e90jimmy
Posts: 8
Joined: Thu Jan 12, 2012 4:39 pm
Contact: Website

Re: [TUTORIAL] RPi as Bluetooth A2DP Reciever

Mon Jan 13, 2014 3:47 pm

castalla wrote:One issue I'm having is that after some time, the whole PI locks up! Could be a deal breaker .... any ideas where I could look for a cause?

I'm having a similar problem with mine. I can pair to the phone just fine, music plays, then after 30s or so, the whole thing freeze, and I can no longer SSH into the Pi.

I have to reboot/unplug it to get back in.


Has anyone solved this issue? I have V1 Model B, with 256mb RAM.

Bouma
Posts: 1
Joined: Sun Jan 26, 2014 9:34 pm

Re: [TUTORIAL] RPi as Bluetooth A2DP Reciever

Mon Jan 27, 2014 1:07 am

I've been trying to get this working for a couple of days using this thread and the instructions here as a basis: http://kmonkey711.blogspot.co.uk/2012/1 ... ry-pi.html

After pairing and running the command below, I can play music from my android phone through the pi but only for about 5 seconds before it stops. To get it working again I have to unpair, pair and then run the command again.

Code: Select all

pactl load-module module-loopback source=bluez_source.**_**_**_**_**_** sink=alsa_output.platform-bcm2835_AUD0.0.analog-stereo rate=44100 adjust_time=0

Any ideas what might be causing the drop out?

ebw
Posts: 1
Joined: Sun Apr 13, 2014 9:38 pm

Re: [TUTORIAL] RPi as Bluetooth A2DP Reciever

Sun Apr 13, 2014 9:44 pm

I had the same issue. And retyping the

Code: Select all

pactl load-module module-loopback source=xxxx sink=yyyy
was working.

Code: Select all

watch -n 5 pactl scan
seems to keep the pulse audio loopback running on my setup. But I have done just a quick test.
Bouma wrote:I've been trying to get this working for a couple of days using this thread and the instructions here as a basis: http://kmonkey711.blogspot.co.uk/2012/1 ... ry-pi.html

After pairing and running the command below, I can play music from my android phone through the pi but only for about 5 seconds before it stops. To get it working again I have to unpair, pair and then run the command again.

Code: Select all

pactl load-module module-loopback source=bluez_source.**_**_**_**_**_** sink=alsa_output.platform-bcm2835_AUD0.0.analog-stereo rate=44100 adjust_time=0

Any ideas what might be causing the drop out?

mgoetzke
Posts: 4
Joined: Tue Jan 08, 2013 3:55 pm

Re: [TUTORIAL] RPi as Bluetooth A2DP Reciever

Sun Apr 27, 2014 9:04 am

for the 20 second drop outs dont forget to edit

Code: Select all

/etc/pulse/client.conf
just add this line

Code: Select all

extra-arguments = --exit-idle-time=-1 --log-target=syslog
after the line

Code: Select all

; extra-arguments = --log-target=syslog

sideeffekt
Posts: 1
Joined: Thu May 01, 2014 4:20 pm

Re: [TUTORIAL] RPi as Bluetooth A2DP Reciever

Thu May 01, 2014 5:19 pm

The issue I have is that my device is not being connected as an input device through udev.

Instead of
SUBSYSTEM=="input", GROUP="input", MODE="0660"
KERNEL=="input[0-9]*", RUN+="/usr/lib/udev/bluetooth"

I use
KERNEL=="hci0:11, SUBSYTEM=="Bluetooth", RUN+="/usr/lib/udev/Bluetooth"
KERNEL=="hci0:12, SUBSYTEM=="Bluetooth", RUN+="/usr/lib/udev/Bluetooth"

as these are how my device will show up rather than an input also.This gets my script to launch, but I have create a custom script and manually add a completed pactl command for each device I want to connect.

This doesn't work in the script for me

for dev in $(find /sys/devices/virtual/input/ -name input*)

because my device is not showing as an input

I created a script that just reads

amixer set Master 100%
pactl load-module module-loopbacksource=bluez_source.C8_3D_97_E9_39_2F sink=alsa_output.platform-bcm2835_AUD0.0.analog-stereo

and I have to add this line for each device I connect one time since the mac address is always different.So if I add another bluetooth device that I want to work upon pairing I would modify my script to look like this:

amixer set Master 100%
pactl load-module module-loopbacksource=bluez_source.C8_3D_97_E9_39_2F sink=alsa_output.platform-bcm2835_AUD0.0.analog-stereo
pactl load-module module-loopbacksource=bluez_source.D4_AB_7D_23_12_6F sink=alsa_output.platform-bcm2835_AUD0.0.analog-stereo

For me this is acceptable, as it works and I can pair my devices and they will play music upon connection. But I know this is not the cleanest way to do this and I would love to be able to run the script from this website and auto populate my bluez_source.mac_address for each device automatically. Can anyone help with a proper way to do this when the device is not showing as an input device? Or how do I get my device to show as an input device. I get either

UDEV [2499.845822] add /devices/platform/bcm2708_usb/usb1/1-1/1-1.2/1-1.2:1.0/bluetooth/hci0/hci0:11 (Bluetooth)
or
UDEV [2499.845822] add /devices/platform/bcm2708_usb/usb1/1-1/1-1.2/1-1.2:1.0/bluetooth/hci0/hci0:12 (Bluetooth)
and never
UDEV [2501.546449] add /devices/virtual/input/input1 (input)
from udev monitor (I have tried using bluez-simple-agent to pair and trust the device and it also does not make a difference with getting these as an input)

comanderxv
Posts: 1
Joined: Tue Dec 09, 2014 7:21 pm

Re: [TUTORIAL] RPi as Bluetooth A2DP Reciever

Tue Dec 09, 2014 7:54 pm

pactl load-module module-loopbacksource=bluez_source.C8_3D_97_E9_39_2F sink=alsa_output.platform-bcm2835_AUD0.0.analog-stereo
pactl load-module module-loopbacksource=bluez_source.D4_AB_7D_23_12_6F sink=alsa_output.platform-bcm2835_AUD0.0.analog-stereo
I had the same problem with the input devices. But type the mac address is not my style so here is my solution for that

Code: Select all

bluez_dev='bluez_source.'$(hcitool con | grep -o -E '([[:xdigit:]]{1,2}:){5}[[:xdigit:]]{1,2}' | sed 's/:/_/g' )

Code: Select all

sudo -u pi pactl load-module module-loopback source=$bluez_dev sink=$AUDIOSINK rate=44100 adjust_time=0
i have these lines in /usr/lib/udev/bluetooth and have deleted all the code with inputs.

my /etc/udev/rules.d/99.... have this entry to start the script:

Code: Select all

KERNEL=="hci0:*",SUBSYSTEM=="bluetooth",RUN+="/usr/lib/udev/bluetooth"
System is:

Code: Select all

Linux raspberrypi 3.12.28+ #709 PREEMPT Mon Sep 8 15:28:00 BST 2014 armv6l GNU/Linux

Saran
Posts: 11
Joined: Wed Oct 23, 2013 8:31 pm

Re: [TUTORIAL] RPi as Bluetooth A2DP Reciever

Thu Jan 22, 2015 11:30 pm

I can connect and my device is playing to Pi, but I have no sound.

When I check this I get:

Code: Select all

$ pactl list sources short
Assertion 'l' failed at pulsecore/flist.c:168, function pa_flist_pop(). Aborting.
Aborted
Ideas?

coolig
Posts: 1
Joined: Mon Jan 26, 2015 8:46 pm

Re: [TUTORIAL] RPi as Bluetooth A2DP Reciever

Mon Jan 26, 2015 9:05 pm

Hi, I successfully connected my android-phone to RPI but only for the first time.
After setting a pair between this two devices I can't trigger the /udev script because udev doesn't plug my phone to /devices/input...
for the first time udev monitor gives me this:
UDEV - the event which udev sends out after rule processing
KERNEL - the kernel uevent

KERNEL[1621.651314] add /devices/platform/bcm2708_usb/usb1/1-1/1-1.4/1-1.4:1.0/bluetooth/hci0/hci0:11 (bluetooth)
UDEV [1621.670120] add /devices/platform/bcm2708_usb/usb1/1-1/1-1.4/1-1.4:1.0/bluetooth/hci0/hci0:11 (bluetooth)
KERNEL[1627.444657] add /devices/virtual/input/input1 (input)
KERNEL[1627.450908] add /devices/virtual/input/input1/event0 (input)
UDEV [1629.446089] add /devices/virtual/input/input1 (input)
UDEV [1629.463483] add /devices/virtual/input/input1/event0 (input)
----
After the ADD the /udev/bluetooth script recognize the event start the sound - it works.
But when I disconnect the bluetooth in my phone and then reconnect to RPI I get this in in udev monitor:
KERNEL[1862.931180] remove /devices/virtual/input/input1/event0 (input)
UDEV [1862.936481] remove /devices/virtual/input/input1/event0 (input)
KERNEL[1862.971340] remove /devices/virtual/input/input1 (input)
UDEV [1863.112739] remove /devices/virtual/input/input1 (input)
KERNEL[1867.040543] remove /devices/platform/bcm2708_usb/usb1/1-1/1-1.4/1-1.4:1.0/bluetooth/hci0/hci0:11 (bluetooth)
UDEV [1867.043015] remove /devices/platform/bcm2708_usb/usb1/1-1/1-1.4/1-1.4:1.0/bluetooth/hci0/hci0:11 (bluetooth)
KERNEL[1877.536549] add /devices/platform/bcm2708_usb/usb1/1-1/1-1.4/1-1.4:1.0/bluetooth/hci0/hci0:12 (bluetooth)
UDEV [1877.555403] add /devices/platform/bcm2708_usb/usb1/1-1/1-1.4/1-1.4:1.0/bluetooth/hci0/hci0:12 (bluetooth)
---
and nothing more happens. no /devices/virtual/input... so the /udev/bluetooth script doesn't get fired -> no sound...
I think this is the bluetooth pairing connection problem, but if someone could point me the directions where to look for answers or what causes the problem ?

Return to “Media centres”

Who is online

Users browsing this forum: No registered users and 5 guests