Monday, July 19, 2021

Airplay (Shairport-sync) on the Raspberry Pi and Disabling Wifi Power Save

As of this writing on Jul 19th 2021 I am having trouble with the packaged version of shairport-sync. This page outlines how to fairly simply compile it from a different repository and also to disable the problematic wifi power save mode which can cause skipping.


I am now running 4 different raspberry pi’s with the Shairport-sync software to receive airplay streams from our phones and computers and they work great. The ones connected via WiFi tend to have dropouts while the ones with physical connections seem to work perfectly all the time and almost never skip. This seems to be in spite of the power or memory of the machines in question which range from pi zero’s through Pi3 B+ and a couple of Pi4’s now.

I recently upgraded the one we use the most to a Pi4 trying to see if that would solve the problem, and I wanted it to run some other software at the same time and thought it would be worth doing a reload on that older Pi3. 

I initially tried the standard distribution of the shairport-sync installed via:

sudo apt install shairport-sync

That worked great except that I could not seem to make any changes to the configuration file. If you just want to use your hostname as the share name and do not need to change any other configuration options then this will work just fine and you don’t really need to do anything else other than enable it via the systemctl enable shairport-sync and then reboot. I didn’t want my hostname to be the share name and whenever I made any changes to the configuration file, which the standard package installs in /etc/shairport-sync.conf instead of the other standard location where it has been as long as I can remember in /usr/local/etc/shairport-sync.conf, it would just crash upon starting up.

I uninstalled it and decided to scrape around and do an actual build of the software from the same repository that I used originally for the others. There are several forks available the one I used successfully is this one by github user Mike Brady

First install some necessary packages to be able to build it, this should be done after you’ve updated the software on your pi via the normal methods.

sudo apt install autoconf libtool libdaemon-dev libasound2-dev libpopt-dev libconfig-dev
sudo apt install avahi-daemon libavahi-client-dev
sudo apt install libssl-dev
sudo apt install git

Now we need to clone the git repository and to the configure and make steps:

cd ~
git clone
cd shairport-sync
autoreconf -i -f
./configure --with-alsa --with-avahi --with-ssl=openssl --with-systemd --with-metadata

If there are other options you wish to compile in like the mqtt server or others that configure line is the place to add them.

Once those are done you can do the make and install:

sudo make install

And enable the app to run at startup like this:

sudo systemctl enable shairport-sync

If you wish to change the name of the share as it appears to iOS devices or increase the timeouts for resyncs which I also did for a little more leeway with a bad wifi connection you can edit the configuration file which should be placed in /usr/local/etc/shairport-sync.conf via the command:

sudo nano /usr/local/etc/shairport-sync.conf

You’ll find the name entry at the top of the first section, you can uncomment theirs and change it or just add a line like:

name="Living Room";

you can also scroll down a bit to find the drift and resync tolerances. If you really want to have several servers all receiving the stream at the same time and playing the same music in sync then you should not alter these, but if you are mostly using one at a time as I do for whatever room I’m in and not the entire system you can increase their default times by altering the default lines which look like:

// drift_tolerance_in_seconds = 0.002; // allow a timing error of this number of seconds of drift away from exact synchronis$
// resync_threshold_in_seconds = 0.050; // a synchronisation error greater than this number of seconds will cause resynchron$

uncomment those and experiment with larger values. For myself I increase the drift tolerance to 0.05 and the resync threshold to 0.1

There are SO many suggestions out there on how to force the wifi power save mode to stay off after a restart but only this one worked for me. You can check to see if the wifi power save is on by running the command:

iw dev wlan0 get power_save
and change it via the command:
sudo iw dev wlan0 set power_save off

It seems that despite all protestations by many people that this is now off by default on their pi’s it is most definitely on when mine reboot. We need to create a systemctl command to run at startup that will execute the command above. If you have more than one wifi interface or are using the descriptive names option in the newer Pi OS’s you may have to use a different name than wlan0 but that is the default if you haven’t changed anything as of this writing.

Create the file with the nano editor like this:

sudo nano /etc/systemd/system/wifi_power_save_off.service

Paste the following into the file and save with ctrl-o and then ctrl-x to exit the editor.

Description=Set WiFipower save off so no skipping of audio

ExecStart=/sbin/iw dev wlan0 set power_save off


In order for the systemctl system to see this additional file you have to run the reload daemon command and finally enable it with these 2 commands:

sudo systemctl daemon-reload
sudo systemctl enable wifi_power_save_off

Now reboot your pi and check to see that your shairport-sync share shows up in your iOS devices properly and then run the "iw dev wlan0 get power_save" command again to make sure that it has run properly.

.code { background:#f5f8fa; background-repeat:no-repeat; border: solid #5C7B90; border-width: 1px 1px 1px 20px; color: #000000; font: 13px 'Courier New', Courier, monospace; line-height: 16px; margin: 10px 0 10px 10px; max-height: 200px; min-height: 16px; overflow: auto; padding: 28px 10px 10px; width: 90%; } .code:hover { background-repeat:no-repeat; }