This tutorial will allow you to retrofit your old speakers into Bluetooth controlled speakers. The main goal of this project is to expose the Onion community to the Bluetooth capabilities on OpenWRT.
Tutorial Difficulty: Intermediate
Time Required: 25 minutes
Required Materials:
- The Omega
- The Expansion Dock
- Onion BLE
- USB Hub
- USB Audio Soundcard
- Speakers or Headphones (Something to test the audio with)
Useful Experience:
- Using BlueZ
- Using PulseAudio
Since the Omega only has one USB port, we need a USB Hub to connect the BLE Dongle and USB soundcard. The sound card is where you will provide the auxillary output to the speakers.
After you are done this, make sure you are running the latest version of the Omega's firmware:
oupgrade
Installing PackagesHere is the list of packages we will be using:
- obluez-libs
- obluez-utils
- opulseaudio-daemon
- pulseaudio-profiles
- pulseaudio-tools
- alsa-lib
- alsa-utils
Before we start installing any packages, we need to run the following command.
opkg update
Then run the following command to install the packages:
opkg install obluez-libs obluez-utils opulseaudio-daemon pulseaudio-profiles pulseaudio-tools alsa-lib alsa-utils
We have to setup the PulseAudio Daemon so that it runs in the background. To do this enter the following commands:
udevd --daemon
chmod 0777 /dev/snd/*
mkdir -p /var/lib/pulse
pulseaudio --system --disallow-exit --no-cpu-limit &
PulseAudio is somewhat unpredictable in this regard. If you have trouble, we recommend rebooting and restarting the process. To check if PulseAudio successfully daemonized, run the ps command:
ps
As you can see, PulseAudio is running for us.
The bluetooth device setup is relatively simple. To make sure your dongle is connected properly run the command.
hciconfig -a
And to turn on the dongle run the following commands.
hciconfig hci0 up
hciconfig hci0 sspmode enable
hciconfig hci0 piscan
At this point your donlge should be blinking a blue light.
Now to actually connect to a device we have to use bluetoothctl. Enter the command:
bluetoothctl
You will enter into the bluetoothctl menu and your dongle will be listed as a controller. Run the following commands to make the dongle discoverable/pairable and allow it to discover other devices.
agent on
discoverable on
pairable on
scan on
Once you target device is located your can pair with it using the command:
pair XX:XX:XX:XX:XX:XX
At this point you will be prompted to enter a PIN on the command line which you will then have to re-enter on you remote device for verification. We need to trust the remote device so that the remote device can initiate the connection. To do this, enter the command:
trust XX:XX:XX:XX:XX:XX
Try initiating the connection from your device and it should work. You should see a screen like so. The remote device should be registered as an input device.
You can now quit the bluetooth menu with the command:
quit
Also, your phone should recognize the OnionBLE as a media audio device.
Now you can check to make sure your device is still connected by running this command.
hcitool con
Your device should be listed, if you see nothing. Try initiating the connection again from the remote device. If that doesn't work go back to the previous step. To get the audio to play, we will be using the pactl
utility.
To see our audio sources run the command:
pactl list sources
Your device should show up as a source. For me it is source # 2. We should do the same for the audio sinks, to confirm that our USB sound card is listed as a sink.
pactl list sinks
You should see a similar screenshot. In our case, the USB sound card is recognized as C-Media USB Headphone Set. Connect your speakers or headphones (make sure the volume is low). Run the command below, replacing the source/sink names as listed in the previous two commands.
pactl load-module module-loopback source=bluez_source.XX_XX_XX_XX_XX_XX sink=<Sink Name> rate=44100 adjust_time=0
You should be hearing music right now. We should mention that when testing with the iPhone, we established connection however only heard noise.
You can control the volume using pactl.
pactl set-sink-volume 1 -25%
Original Wiki PageThe original guide page is available at: https://wiki.onion.io/Tutorials/Bluetooth-Streaming-Audio
Comments