Starlight5
Posts: 24
Joined: Wed Apr 22, 2015 12:54 pm

[SOLVED] RPi Bluetooth audio receiver

Wed Oct 26, 2016 4:23 pm

I have a RPi2 which I would like to use as a Wi-Fi router and, at the same time, Bluetooth audio receiver.

My additional hardware includes 5V 2.5A PSU, RTL8188 with High-gain antenna (awaiting 802.11ac adapter delivery to replace it), generic Bluetooth 4.0 dongle, and simplest USB audio card (awaiting fancier version with media keys on case).

The machine currently runs Dietpi, hotspot is working just fine. I'd like to run OpenWRT to make setting up router part easy, but it doesn't work with my current Wi-Fi adapter and there's no guarantee it will with the new one. Now, the questions.
1. What additional software do I need to install to make my Pi-router completely secure as a standalone router? I assume it's UFW at the very least, how do I need to set it up? What else? How do I need to configure it all?

2. Please advise a good modern guide for Bluetooth audio receiver (A2DP) setup. Surprisingly, finding one that works is a problem.
Last edited by Starlight5 on Mon Nov 14, 2016 2:48 am, edited 1 time in total.

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

Re: RPi Wi-Fi router + Bluetooth audio receiver combo?

Wed Oct 26, 2016 5:02 pm

2. This is a good guide for setting up an A2DP receiver under Raspbian. https://github.com/davidedg/NAS-mod-con ... Audio5.txt
I would recommend adding the PulseAudio module module-bluetooth-policy as well to the system.pa file.

Starlight5
Posts: 24
Joined: Wed Apr 22, 2015 12:54 pm

Re: RPi Wi-Fi router + Bluetooth audio receiver combo?

Wed Oct 26, 2016 5:57 pm

Douglas6 wrote:2. This is a good guide for setting up an A2DP receiver under Raspbian. https://github.com/davidedg/NAS-mod-con ... Audio5.txt
I would recommend adding the PulseAudio module module-bluetooth-policy as well to the system.pa file.
Thank you. Was going to ask about this guide in the other thread. It is for making a Bluetooth transmitter, while I need a receiver. What changes should be implemented to make it work as a receiver? Frankly, my knowledge about the subject is nowhere near enough to figure it by myself.

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

Re: RPi Wi-Fi router + Bluetooth audio receiver combo?

Wed Oct 26, 2016 6:03 pm

Just as I said: load the module-bluetooth-policy as well as module-bluetooth-discover. That will take care of looping the Bluetooth source to the default ALSA sink.

Starlight5
Posts: 24
Joined: Wed Apr 22, 2015 12:54 pm

Re: RPi Wi-Fi router + Bluetooth audio receiver combo?

Wed Nov 09, 2016 12:29 am

Douglas6 wrote:Just as I said: load the module-bluetooth-policy as well as module-bluetooth-discover. That will take care of looping the Bluetooth source to the default ALSA sink.
I tried following the guide, without success. First of all, which users exactly should I add in "authorize users" section, besides root?
Also, it seems my Bluetooth device is operating under wrong profile, because of the error I get in bluetooth service status:

Code: Select all

 a2dp-source profile connect failed for A0:A8:CD:69:50:0E: Protocol not available

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

Re: RPi Wi-Fi router + Bluetooth audio receiver combo?

Wed Nov 09, 2016 12:39 am

Root is the only user you need to add to the pulse-access group. You can give it to pi if you want to have access to pactl commands without sudo.
Have you got the PulseAudio daemon running? What does this say?

Code: Select all

systemctl status pulseaudio 
Do both Bluetooth modules show with this?

Code: Select all

sudo pactl list modules 

Starlight5
Posts: 24
Joined: Wed Apr 22, 2015 12:54 pm

Re: RPi Wi-Fi router + Bluetooth audio receiver combo?

Sat Nov 12, 2016 5:14 am

First of all, thank you for helping!
Douglas6 wrote: Have you got the PulseAudio daemon running? What does this say?

Code: Select all

systemctl status pulseaudio 

Code: Select all

● pulseaudio.service - Pulse Audio
   Loaded: loaded (/etc/systemd/system/pulseaudio.service; enabled)
   Active: active (running) since Sat 2016-11-12 05:05:36 UTC; 4min 27s ago
 Main PID: 1747 (pulseaudio)
   CGroup: /system.slice/pulseaudio.service
           └─1747 /usr/bin/pulseaudio --system --disallow-exit --disable-shm --exit-idle-time=-1

Nov 12 05:05:36 DietPi systemd[1]: Started Pulse Audio.
Nov 12 05:05:36 DietPi pulseaudio[1747]: W: [pulseaudio] main.c: Running in system mode, but --disallow-module-loading not set!
Nov 12 05:05:36 DietPi pulseaudio[1747]: W: [pulseaudio] main.c: OK, so you are running PA in system mode. Please note that you most likely shouldn't be doing that.
Nov 12 05:05:36 DietPi pulseaudio[1747]: W: [pulseaudio] main.c: If you do it nonetheless then it's your own fault if things don't work as expected.
Nov 12 05:05:36 DietPi pulseaudio[1747]: W: [pulseaudio] main.c: Please read http://pulseaudio.org/wiki/WhatIsWrongWithSystemMode for an explanation why sy... bad idea.
Nov 12 05:05:37 DietPi pulseaudio[1747]: W: [pulseaudio] authkey.c: Failed to open cookie file '/var/run/pulse/.config/pulse/cookie': No such file or directory
Nov 12 05:05:37 DietPi pulseaudio[1747]: W: [pulseaudio] authkey.c: Failed to load authorization key '/var/run/pulse/.config/pulse/cookie': No such file or directory
Nov 12 05:05:37 DietPi pulseaudio[1747]: W: [pulseaudio] authkey.c: Failed to open cookie file '/var/run/pulse/.pulse-cookie': No such file or directory
Nov 12 05:05:37 DietPi pulseaudio[1747]: W: [pulseaudio] authkey.c: Failed to load authorization key '/var/run/pulse/.pulse-cookie': No such file or directory
Nov 12 05:05:37 DietPi pulseaudio[1747]: E: [pulseaudio] bluez4-util.c: org.bluez.Manager.GetProperties() failed: org.freedesktop.DBus.Error.UnknownMethod:...sn't exist
Hint: Some lines were ellipsized, use -l to show in full.
Douglas6 wrote:Do both Bluetooth modules show with this?

Code: Select all

sudo pactl list modules 
I have single bluetooth 4.0 adapter by CSR, just in case.

Code: Select all

[email protected]:~# sudo pactl list modules
Module #0
        Name: module-udev-detect
        Argument:
        Usage counter: n/a
        Properties:
                module.author = "Lennart Poettering"
                module.description = "Detect available audio hardware and load matching drivers"
                module.version = "5.0"

Module #1
        Name: module-alsa-card
        Argument: device_id="0" name="0" card_name="alsa_card.0" namereg_fail=false tsched=yes fixed_latency_range=no ignore_dB=no deferred_volume=yes use_ucm=yes card_properties="module-udev-detect.discovered=1"
        Usage counter: 0
        Properties:
                module.author = "Lennart Poettering"
                module.description = "ALSA Card"
                module.version = "5.0"

Module #2
        Name: module-native-protocol-unix
        Argument:
        Usage counter: n/a
        Properties:
                module.author = "Lennart Poettering"
                module.description = "Native protocol (UNIX sockets)"
                module.version = "5.0"

Module #3
        Name: module-stream-restore
        Argument:
        Usage counter: n/a
        Properties:
                module.author = "Lennart Poettering"
                module.description = "Automatically restore the volume/mute/device state of streams"
                module.version = "5.0"

Module #4
        Name: module-device-restore
        Argument:
        Usage counter: n/a
        Properties:
                module.author = "Lennart Poettering"
                module.description = "Automatically restore the volume/mute state of devices"
                module.version = "5.0"

Module #5
        Name: module-default-device-restore
        Argument:
        Usage counter: n/a
        Properties:
                module.author = "Lennart Poettering"
                module.description = "Automatically restore the default sink and source"
                module.version = "5.0"

Module #6
        Name: module-rescue-streams
        Argument:
        Usage counter: n/a
        Properties:
                module.author = "Lennart Poettering"
                module.description = "When a sink/source is removed, try to move its streams to the default sink/source"
                module.version = "5.0"

Module #7
        Name: module-always-sink
        Argument:
        Usage counter: n/a
        Properties:
                module.author = "Colin Guthrie"
                module.description = "Always keeps at least one sink loaded even if it's a null one"
                module.version = "5.0"

Module #8
        Name: module-suspend-on-idle
        Argument:
        Usage counter: n/a
        Properties:
                module.author = "Lennart Poettering"
                module.description = "When a sink/source is idle for too long, suspend it"
                module.version = "5.0"

Module #9
        Name: module-position-event-sounds
        Argument:
        Usage counter: n/a
        Properties:
                module.author = "Lennart Poettering"
                module.description = "Position event sounds between L and R depending on the position on screen of the widget triggering them."
                module.version = "5.0"

Module #10
        Name: module-bluetooth-discover
        Argument:
        Usage counter: n/a
        Properties:
                module.author = "João Paulo Rechi Vita"
                module.description = "Detect available Bluetooth daemon and load the corresponding discovery module"
                module.version = "5.0"

Module #11
        Name: module-bluez5-discover
        Argument:
        Usage counter: n/a
        Properties:
                module.author = "João Paulo Rechi Vita"
                module.description = "Detect available BlueZ 5 Bluetooth audio devices and load BlueZ 5 Bluetooth audio drivers"
                module.version = "5.0"

Module #12
        Name: module-bluez4-discover
        Argument:
        Usage counter: n/a
        Properties:
                module.author = "João Paulo Rechi Vita"
                module.description = "Detect available BlueZ 4 Bluetooth audio devices and load BlueZ 4 Bluetooth audio drivers"
                module.version = "5.0"
I do not understand how do I make RPi act as a Bluetooth Audio Receiver from here. It is paired with my laptop, but sound goes through laptop's speakers anyway, not through rpi's.

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

Re: RPi Wi-Fi router + Bluetooth audio receiver combo?

Sat Nov 12, 2016 2:29 pm

The module-bluetooth-policy is not loaded. Edit /etc/pulse/system.pa, and add this line at the bottom:

Code: Select all

load-module module-bluetooth-policy
as suggested above (twice). Reboot.

Starlight5
Posts: 24
Joined: Wed Apr 22, 2015 12:54 pm

Re: RPi Wi-Fi router + Bluetooth audio receiver combo?

Sat Nov 12, 2016 11:39 pm

Douglas6 wrote:The module-bluetooth-policy is not loaded. Edit /etc/pulse/system.pa, and add this line at the bottom:

Code: Select all

load-module module-bluetooth-policy
as suggested above (twice). Reboot.
Don't know how I managed to miss that... twice. Everything worked, thank you very much!

However, I am not satisfied with the end result. Comparing to ready-made Bluetooth receivers, it doesn't produce annoying noises on connecting, disconnecting and pairing - however, the range of my Bluetooth 4.0 dongle is definitely lacking, even when I put it 1m away from pi with wi-fi adapter and towards the source using USB extender; also, sound control reacts much slower. I found a neat hardware hack to increase the range, though not sure whether I am adventurous enough to go further with it.

Now, to the router part. It is working (hotspot by dietpi), but I'm not sure about protection. What I lack is understanding how I should configure firewall (preferably, ufw) to protect RPi router which will be exposed to the Internet, and its clients, from all potential threats - and maybe add some additional security software. I do not need any fancy stuff like ssh from Internet, or any sort of web-server running; it just needs to be secure and simple. Please help me.
Last edited by Starlight5 on Mon Nov 14, 2016 2:48 am, edited 1 time in total.

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

Re: RPi Wi-Fi router + Bluetooth audio receiver combo?

Sat Nov 12, 2016 11:49 pm

Glad you got the Bluetooth working! I'm really not an expert on networking; I'd post your question in a new thread.

Starlight5
Posts: 24
Joined: Wed Apr 22, 2015 12:54 pm

Re: RPi Wi-Fi router + Bluetooth audio receiver combo?

Mon Nov 14, 2016 2:45 am

FWIW today the sound and range are perfect. No idea what was wrong, but now everything is great. Thank you once again, Douglas6!

Return to “Networking and servers”