Friday Fun: Wireless Music Streaming over AirPlay on a Raspberry Pi A+

This Friday, we will be looking at setting an Raspberry Pi A+ up as a AirPlay receiver, so you can stream music wireless from your iPhone or iPad.

Ever wanted to make your speakers wireless? Maybe you're constantly fighting over the auxiliary cable at the office? Or maybe you want to use your phone whilst listening to music in the livingroom? I just hate having to use the auxiliary cable constantly and changing if someone wants to listen to something differently.

In the beginning of 2015, I stumbled upon the Shairplay Airplay Server on github, which I’ve tried to install a few times, however I’ve always run into trouble using it since the original author of the plugin abandoned it because of no time for maintenance (who can blame him?) Not so long after I discovered Volumio – Audiophile Music Player (it was called RaspyFi before), which has some really great features! It’s an open source linux distribution that turns embedded systems, such as the Raspberry Pi, BeagleBone and even your old Laptop, into a music streaming device! It even has Spotify support! It runs as a headless client, but it comes with a responsive web-ui that you can control from either phone, tablet or computer. The new version of Volumio has just been released and their website has received a major makeover. The Volumio OS is now faster than ever using a Nodejs as backend and Angularjs on the frontend.

Installation

For this project, we will be using:

  1. Raspberry Pi A+ (doh! We got one from ThePiHut, but any Pi, except Zero, should work)
  2. Class 10 MicroSD-card with SD adapter and at least 4GB space (We will be using the SanDisk Ultra 32GB Class 10)
  3. DAC/Audio add-on board for the Raspberry Pi, such as the HiFiBerry DAC+ (Recommended)
  4. Power-supply with 2A
  5. USB-wifi dongle (Depending on the manufacturer, the network setup might differ)
  6. Patience, Candy and Beer
Download Volumio

First off, you need to download the Volumio distribution from Volumio - Get started, which is version 0.979 at the time of this post. After the download has been completed, you follow the directions for copying the image onto the MicroSD card, these instructions can also be found at the above link, otherwise look at the copy below:

Windows
  1. Extract the downloaded zip file and you’ll have a .img image file
  2. Download and extract Win32DiskImager
  3. Open Win32DiskImager, right-clicking on the file, and select “Run as Administrator”
  4. Insert the MicroSD Card on your computer, you could use an external card reader, the SD-card adapter or the SD slot, if your computer has one built-in
  5. Check that the device name correspond to the microSD card, then browse the files and select choose the image file you want to write (IMPORTANT! To be safe, unplug every External USB Drive you may have connected to your PC)
  6. When ready click on Write and wait for the process to complete
  7. Exit from Win32DiskImageWriter and eject the SD card
  8. Done! Volumio is now on your SD Card!
MacOS

On Mac OS X, you have multiple software that helps you copy the image file. Here’s some of them:

Using ApplePi-Baker:

  1. Once the download has finished, you can open it and it will ask for your admin password (the one that you use for MacOS).
  2. Now select the right SD card in the Pi Crust box (Tip: If you have multiple devices in the list, remove the SD card, refresh and check which one disappeared from the list)
  3. Go to the Pi Ingredient box IMG recipe and navigate to the downloaded volumio image file, select it and press "Restore Backup"

Now plug the sd-card into your Raspberry Pi and let's get ready for configuration!

Configuration

Now depending on your setup, the configuration might be a breeze or turn out a bit more difficult. If you are using the Edimax dongle, it should be plug and play, but if you are using the Realtek, it might take some tinkering.

Wireless Setup using the Realtek WiFi Dongle

Now we arrive at the most difficult step, as the Raspberry Pi A+ doesn’t have support for wired ethernet (If you're using a Raspberry Pi 2/3, you can use onboard ethernet or WiFi). Depending on which USB wifi dongle you have purchased the configuration might differ. Using the Edimax EW-7811Un, Volumio can setup a hotspot named "Volumio" and the UI will automatically appear in your browser. However, with the Realtek WiFi dongles, we need to setup the initial WiFi configuration. Plug-in your prepared Volumio SD card into the Raspberry Pi A+ and attach it to a monitor by HDMI cable and plug a keyboard into the USB. We just need to do a few changes before your Pi will appear as a AirPlay receiver.

We will have to add the wireless router settings in order for it to connect to your WiFi, afterwards these settings are editable/configurable from Volumios web-interface. Depending on your WiFi, the setting can be different – I encourage you to google for an alternative WiFi setup guide, if this one differs from yours. Otherwise, add a comment and I’ll see if I can help!

Start the Raspberry Pi with the SD-card inserted and log in with the following information

User: volumio 
Pass: volumio

Lucky for me (and you), Volumio comes with my (our) favourite editor nano, so let’s edit the network interface configuration! Type following in console:

sudo nano /etc/network/interfaces

and make sure your wlan0 has these settings (note the two last lines):

allow-hotplug wlan0 
iface wlan0 inet dhcp 
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
iface default inet dhcp

Now press CTRL+O to write and quit Nano. Next, we add the WPA supplicant configuration:

sudo nano /etc/wpa_supplicant/wpa_supplicant.conf

and add the following:

network={
ssid="YOUR_NETWORK_NAME"
psk="YOUR_NETWORK_PASSWORD"
proto=RSN
key_mgmt=WPA-PSK
pairwise=CCMP
auth_alg=OPEN
}

Depending on your wireless setup, some of these might differ from our setup

  • proto could be either RSN (WPA2) or WPA (WPA1).
  • key_mgmt could be either WPA-PSK (most probably) or WPA-EAP (enterprise networks)
  • pairwise could be either CCMP (WPA2) or TKIP (WPA1)
  • auth_alg is most probably OPEN, other options are LEAP and SHARED

In the new version, Volumio disables power-saving functions/management by default. You can check whether it is disabled by writing:

cat /sys/module/8192cu/parameters/rtw_power_mgnt

If it returns 0, everything is good and power management is disabled. But if it should return 1, then edit the following file:

sudo nano /etc/modprobe.d/8192cu.conf

and make sure the file contains the following:

options 8192cu rtw_power_mgnt=0 rtw_enusbss=0

Save the file and reboot.

Now, let's check the wireless setup, after logging in write:

sudo ifconfig wlan0

If it returns 192.168.211.1, even though your router is setup up as DHCP server, then we need to disable the hotspot feature by executing the following commands, which disables the hostapd and isc-dhcp-server services:

systemctl disable hostapd.service
systemctl disable isc-dhcp-server.service

and stop them:

systemctl stop hostapd.service
systemctl stop isc-dhcp-server.service

Now reboot the Raspberry Pi using sudo reboot

Log on your Local Network and input http://volumio.local, you should see the Volumio dashboard - see Connect and Listen section.

Wireless Setup using the Edimax WiFi Dongle

Connect the USB dongle, HiFiBerry DAC+ and power-supply to your Raspberry Pi - after booting up, you will see a Volumio Hotspot using your Laptop - connect to it. You will be redirected to the Volumio dashboard on connect, otherwise use the Raspberry Pi's local ip or http://volumio.local and proceed to section below.

Connect and Listen!

First off, lets check if the HiFiBerry DAC+ is setup correctly on the Raspberry Pi, press the menu in the top right corner and go to Settings - it should set the DAC as standard I2C device. Now lets add the Raspberry Pi to your normal wireless network. Press the menu icon in the top right corner and go to Network, now scroll to the bottom and you will see a list of nearby access-points, choose the correct one and input the password, you might be disconnected at this point otherwise reboot the Raspberry Pi by using the top right menu again.

Connect to your own local network and open iTunes on your Macbook or Apple Music on your iPhone (If connected to the local network). You will see the AirPlay icon show up, press it and you should see Volumio as an option. You can change the name of the Raspberry Pi in Settings on the Volumio dashboard.

Enjoy your new music streaming device using AirPlay on a Raspberry Pi!