AirPi: DIY Airplay Speakers using Shairport and a Raspberry Pi Updated

My last AirPi post has been popular – and still is – but part of why of like Arch linux is that it is constantly updating so you must be hands on, learning a new part of the OS the hard way!

Since my post a year ago, Shairport has some new features and dependencies, and Arch has moved to the systemd service manager, changing the tutorial process somewhat. In order to update it, I have run through the process with the current build (2013-02-11).

The initial steps are the same:

Install Pacman Packages

Next you’ll need to install the tools required to compile in Arch.

Then git to clone the Shairport repo.

Shairport has a number of dependencies so we’ll install them and there dependencies too.

A new dependency for Shairport is perl-net-sdp. This isn’t a package yet in the pacman repos so must be installed from the AUR.

READ THE UPDATES BELOW IF YOU HAVE PROBLEMS AT THIS STEP

Finally, alsa is required to get sound output in Arch on the RPi.

Change the default output to the 3.5mm jack

After all the installs, best to reboot

Make Shairport

Create a directory to do the build

Now clone the repo, cd into it and make.

All being well, Shairport should have built and you can now run it with the name ‘AirPi’.

If all is well, install

Systemd

The biggest change is dropping rc.conf in favour of systemd. The sound module snd-bcm2835 now autoloads but Avahi must be enabled as a service.

A .service file needs creating for systemd to start Shairport as a service at boot. Create this using vi in /etc/systemd/system/

Copy this code

Or you get use wget again and download mine:

Now enable the new service

UPDATE MARCH 2014

I recently created another ‘AirPi’ for my sister so went through these steps. As before, ArchPi has changed a few things. The main problem I came across was ivp6 being disabled, preventing Shairport binding to the socket. To enable it, change ipv6.disable=1 in /boot/cmdline.txt to false (0).

UPDATE FEBRUARY 2015

More updates a year on. As a commenter has said, this tutorial is done as root (because that’s the default for the Arch ARM image). You can’t makepkg as root anymore. The solution is to create a build folder and sudo as a lower user:

pacman -S sudo
mkdir /home/build
chgrp nobody /home/build
chmod g+ws /home/build
setfacl -m u::rwx,g::rwx /home/build
setfacl -d --set u::rwx,g::rwx,o::- /home/build
cd /home/build

Copy extract the perl package from the AUR here then sudo -u nobody makepkg to make the package.

I also had issues with my file system becoming read only. To fix this edit ‘/boot/cmdline.txt’ and add ‘rw’ at the end of the line before ‘rootwait’, reboot.

Finally, James picked up that the audio quality is off now by default. To fix it:

echo “use_mmap=no” >> /etc/libao.conf

cropped-JBRLogo.png

17 thoughts on “AirPi: DIY Airplay Speakers using Shairport and a Raspberry Pi Updated”

  1. Fantastic guide.

    I have one problem though. The setup works when I issue the command

    ./shairport.pl -a AirPi

    But I’m unable to connect to it when it has been started automatically as a service (it is visible but I can’t connect to it).

    Any ideas?

  2. nice guide, im looking to set a few up around the house into differnt speakers and have like a “sonos” wireless music setup around the house setup but if i name them all the same will it play through them all or will they be listed as different speakers on the idevice? and only be able to play through one speaker?

    1. No, they will be listed as different AirPlay devices and you can only connect to one at a time so only one speaker at a time.

      The only way to achieve that would be to have a central amp with speaker wire laid into each room; not completely wireless but it’s what I have done.

      1. Hi, If you name each AirPi differently then using TuneBlade you can stream to all of them at once and in Sync and free for non apple AirPlay like the Pi. I am using cheap computer speakers which are fine for the kitchen, bathroom etc and have their own amp and volume control. All I need to do now is find out how to switch off the Pi simply without destroying the SD card and without having to log in with Putty and issue the sudo halt command.
        Any ideas?
        Good Tutorial.
        Steve

        1. Sounds like you want a ‘power’ button to issue the halt command. I imagine it’s something you could design with GPIO – a shutdown script that runs when a button is pressed.

          I haven’t looked into it much but here are a couple of links that get across what I am thinking:

          http://openmicros.org/index.php/articles/94-ciseco-product-documentation/raspberry-pi/217-getting-started-with-raspberry-pi-gpio-and-python

          http://raspi.tv/2012/making-a-reset-switch-for-your-rev-2-raspberry-pi (starts from halt state)

          Let me know if you create a solution.

  3. Great tutorial! Got my system up and running in 10 min.

    By any chance do you know if shairport passes (or logs) any information about users connected or the music being passed?

    1. Thanks, glad you got up and running quickly.

      The first method that came to my head for seeing users connected was to use lsof. You can see just connections using lsof -i and just shairport using lsof -c shairport -i. The only problem with this is that lsof isn’t included in ArchPi. You could install it using pacman -Syu lsof but an inbuilt (but rougher) solution is to use netstat -at. You will see the ip of the connected user, bound to the default shairport port (63242) (it will only show the connection when music is playing). Hope this helps.

  4. Great tutorial and finally it works for me.

    But using ExecStart=/usr/local/bin/shairport -a AirPi -b 256 -d in shairport.service for startup didn’ t work for me. The stream was always breaking down after a minute or so.
    But if I start the Pearl file it works: ExecStart=/usr/local/bin/shairport.pl -a AirPi -b 256 -d. Any idea what’ s the reason for this?

    Greetings
    Stefan

    1. Thanks and glad you got it working. Not sure about the problem though. Do you get any errors if you run shairport manually in the foreground or does it only cut out using the start up?

      What build of shairport did you use? I did this recently and had a problem where it would connect then drop after a few seconds. I had to use the ’1.0 dev’ branch but I think they’ve moved to 1.0 now anyway.

      Anyway, if it works using calling the pearl file I guess just leave it like that!

  5. Shairport works as expected when I start it manually from the install folder (excpet for a missing frame error, but no sound issues), but when I start it as a daemon, when I try to connect to it the selection jumps back to the default, and the RPi prints out:

    systemd[187]: Failed to open private bus connection: Failed to connect to socket /run/user/1000/dbus/user_bus_socket: No such file or directory.

    I am connecting over ssh, so I use journalctl to get the error.

    I don’t know why I a getting this error, any ideas for fixes?

    Thanks

    1. Fixed the problem. I’m not sure what was happening, but following the instructions to enable dbus on the Arch Wiki Systemd page seemed to fix the error, and AirPlay works at boot now.

    1. Ah thanks for posting this. When I created the latest update, I didn’t check the audio playback but got complaints from my sister after delivering it a couple of days ago regarding poor sound! Nice to have a quick solution now.

  6. Just wanted to say thanks for the excellent step-by-step tutorial. One suggestion: for non-root users, shairport does not run properly (lack of privileges). This isn’t a problem for you, as I think you’re running all these commands as root. Took me a few minutes to figure out where I was going wrong. Thanks again!

Leave a Reply