Raspberry Pi with Sonos S1
The Raspberry Pi, the ultimate in-home audio solution?
My situation
The Sonos Play 5 Gen 1 doesn’t have AirPlay support. It does Spotify Connect, but no AirPlay. While Spotify Connect is pretty good at just playing background music, there’s times that someone wants to play a song from SoundCloud, or YouTube, or some other service.
The solution
A Raspberry Pi to the rescue! This Pi is actually doing a lot at once - I already have raspotify and shairport-sync to add AirPlay and Spotify Connect to a Bose SoundDock connected via a 3.5mm audio cable.
Because Sonos speakers can be managed over Wifi, I can actually have the physical jack be used for the Bose speaker, and a separate AirPlay target for the Sonos speaker.
The setup
-
SSH into your Raspberry Pi.
-
Set up an
airconnectdirectory withcd /var/lib/ sudo mkdir airconnect -
Get the files from philippe44’s AirConnect Github repo with
cd ~ wget https://github.com/philippe44/AirConnect/releases/download/1.7.0/AirConnect-1.7.0.zip sudo mv AirConnect-1.7.0.zip /var/lib/airconnect/ -
Unzip the files with
cd /var/lib/airconnect/ sudo unzip AirConnect-1.7.0.zip -
Give the binaries executable permissions with
chmod +x /var/lib/airconnect/* -
Create a service file with
sudo vi /etc/systemd/system/airupnp.serviceand paste in the following:
[Unit] Description=AirUPnP bridge After=network-online.target Wants=network-online.target [Service] ExecStart=/var/lib/airconnect/airupnp-linux-arm -l 1000:2000 -Z -x /var/lib/airconnect/airupnp.xml Restart=on-failure RestartSec=30 [Install] WantedBy=multi-user.targetSome things to note:
-
You might have to change the directory if your folder isn’t
/var/lib/airconnect/ -
There’s a
-l 1000:2000flag. This adds some latency to the audio, but it’s recommended from the Github page. -
You can use nano if you don’t like vi. However, you should be aware that vi is superior in every way. Make sure to
:wqwhen you’re done.
-
-
Register the service with
sudo systemctl enable airupnp.service
If you don’t need to change the name of the speakers, skip to 10.
-
(Optional) Create the config file from the binary with
/var/lib/airconnect/airupnp-linux-arm -i airupnp.xmlNote, run this command in a directory you’re allowed to write files to. Otherwise, it’ll give an error.
I moved my airupnp to the /var/lib/airconnect/ folder, and then edited it.
-
(Optional) Edit the config file with
sudo vi /var/lib/airconnect/airupnp.xmlIn here, you can change the names of speakers. I changed the speaker in the Kitchen from “Kitchen+” to “Kitchen Sonos”.
-
Start the service with
sudo service airupnp start
The result
The Sonos speaker now shows up as an AirPlay target, and can be used to play audio from any AirPlay device. There’s a second of latency between pressing play and the audio starting, but it plays music just fine.
This entire process shouldn’t take more than 15 minutes of tinkering, but I have had experience with sshing into my Raspberry Pi, and I have already had to deal with services and config files with raspotify and shairport-sync.
Update 01-30-2024
Running raspotify and airupnp at the same time seems to break raspotify’s audio out. (It’s silent).
Update 02-05-2024
It turns out the speaker’s volume was really low when I tried it. Raspotify, shairport-sync and airupnp work fine together.
Update 07-03-2026
Some tips on configuring AirConnect
Sometimes, you’ll have a device on your network that supports UPnP and Airplay all on its own, so AirConnect will add a ‘Speaker+’ entry to your airplay list, duplicating the existing ‘Speaker’ in the list. Other times, you’ll have a device that shows up on UPnP, but doesn’t accept HTTP streams.
For example, I have a TX-NR609 from Onkyo that supports playing content from UPnP servers on my network, but only if done via the Receiver’s controls. It will act as a UPnP receiver, but doesn’t actually switch to that as an input. Either way, AirConnect adds an entry for it, but it doesn’t work, so I want it gone.
For a simpler example, I picked up a Ikea Symfonisk speaker, which supports Sonos S1 and Airplay, so I don’t need AirConnect to add another AirPlay target for it.
To tell AirConnect to remove speakers, you nede to edit the config file. However, the config file can only disable speakers that it is told about.
You can auto-generate a config file by running airupnp with the -i
Here’s what I did.
cd /var/lib/airconnectAnd, because I’m running on the raspberry pi, I’ll run the arm version
./airupnp-linux-arm -i ~/demo.xmlWhich should produce something like this. You can read it by running
cat ~/demo.xml<?xml version="1.0"?>
<airupnp>
<common>
<enabled>1</enabled>
<max_volume>100</max_volume>
<http_length>-1</http_length>
<upnp_max>1</upnp_max>
<codec>flac</codec>
<metadata>1</metadata>
<flush>1</flush>
<artwork></artwork>
<latency></latency>
<drift>0</drift>
</common>
<main_log>info</main_log>
<upnp_log>info</upnp_log>
<util_log>warn</util_log>
<raop_log>info</raop_log>
<log_limit>-1</log_limit>
<max_players>32</max_players>
<binding>?</binding>
<ports>0:0</ports>
<device>
<udn>uuid:RINCON_xxxxxxxxxxxxxxxxx</udn>
<name>Speaker+</name>
<mac>bb:bb:bb:bb:bb:bb</mac>
<enabled>1</enabled>
</device>
</airupnp>Now copy every Device tag that you want to change some settings for. You need to add it to the actual config file that airupnp will use
(You can verify which config file you need to edit by peeking at the service config file)
cat /etc/systemd/system/airupnp.serviceIt’s the same as the one you should have made from the instructions above.
Now, edit /var/lib/airconnect/airupnp.xml and add those devices. If you don’t want it to show up, replace the enabled number from 1 to 0.
Lastly, to apply the new config file changes, restart the airupnp service with
sudo systemctl stop airupnp
sudo systemctl start airupnpAnd your duplicates and duds will be removed from the AirPlay list.