Blog

Raspberry Pi Whole Home Audio ā€“ The Conclusion?

Welcome to what is possibly the concluding post in my Raspberry Whole Home
Audio Project
series of postsā€¦ or possibly not.

At the start of this journey I had a plan to install mopidy on one of my Raspberry Pis and use pulse
audio
to stream the output to the others. Along the way I ran into some challenges
stemming from me buying the cheapest peripherals I could (and subsequently needing
to upgrade the WiFi adapters and power cables I first bought to better ones),
and my vision evolved as things progressed.

Instead of using mopidy, I switched to installing Kodi on each of the Pis thanks to the OpenElec linux distribution thatā€™s available for
several types of hardware, the Pi included.

image

Kodi, as a full-blown media centre system, might seem like a
bit of an odd choice for a headless device (i.e. something with no attached
display), but itā€™s the right choice for me for a couple of reasons.

  • I already have it installed on a couple of PCs
    in the house, attached to the TVs in the living room and the bedroom
  • I already have a remote
    control app
    for it on my phone
  • There are plugins for a bunch of stuff, such as this one for my favourite music streaming service. Well written
    plugins integrate perfectly with the system, and the remote control app.
  • It has built-in support for acting as an airplay
    receiver

For me, these things combine to provide me with the best of
both worlds. If I just want to play music from my library or from an internet
streaming service on one set of speakers, then I fire up the remote app and
target the particular device I want to output from.

If I want to play the same thing on several (or all) the
devices at the same time, then I fire up TuneBlade
on my laptop and any sounds that would usually come out of its speakers get
redirected to all the airplay receivers.

image

When it works, itā€™s glorious. Having the same music playing
in sync on all the speakers in the apartment is awesome.

The problem is that it doesnā€™t always work. TuneBlade
includes a setting that lets you set how much of a buffer you want. If you set
it too high the devices wonā€™t synchronize because it will take a slightly
different amount of time to fill the buffer on each of them. I have it set to
zero, which works amazingly well most of the time but leaves me especially
prone to blips in network connectivity and bandwidth. When these occur, things
get out of sync (which sounds terrible, because each set of speakers is not all
that far away from its neighbours), and it canā€™t seem to automatically recover ā€“
I have to manually disconnect and reconnect the affected player to get it back
in sync with its peers.

The bottom line then is that my setup is good, but not
perfect. Itā€™s no Sonos.

The search for a perfect system will likely continue, but
for the time being Iā€™m pretty content. I spent less than $100, and I have a
setup that would have cost me $5,000 from them.

Blog

Raspberry Pi Whole Home Audio Updates

Itā€™s been a long time since Iā€™ve written about my Raspberry Pi Whole Home Audio Project.

Simply, thatā€™s because Iā€™ve hit a bit of a wall and Iā€™m especially busy with work right now so I havenā€™t been able to find the time to work my way around it.

The problem is that the USB WiFi adapters that I bought (for about $5 each) donā€™t perform well. They have signal strength issues, and while they do work and maintain a network connection, the poor signal strength means the connection isnā€™t fast enough to stream audio. There are plenty of other people out there having the same problem. You get what you pay for, I guess, and I need to buy replacement adapters.

Iā€™m also considering a change in direction. My original plan was to install mopidy on one of the Pis and use pulse audio to stream the output to the others.

Iā€™m considering instead installing TuneBlade on one of my Windows PCs. TuneBlade takes all the audio output from that computer and streams it using Appleā€™s AirPlay protocol. Iā€™d then install ShairPort on all the Pis to turn them into AirPort receivers.

What do you guys think?

Blog

Raspberry Pi Whole Home Audio: Playing Music

Itā€™s very rare that I tweet teasers to my blog post, but
last weekend I was so excited to be making progress on my Raspberry Pi Whole
Home Audio
project that I told the world Iā€™d be publishing this one on
Thursday.

Here we are on Friday morning. Thereā€™s doubtless a lesson in
here for me about making promises I canā€™t keep, but Iā€™m hoping youā€™ll forgive
me when you read about what Iā€™ve done.

If youā€™ve been following my #RPiWHA Project
hashtag on this blog then youā€™ll know that when we left off last time I had
three Raspberry Pis networked together with synchronized clocks, and one of
them had access to the internet and the music library I keep on my home server.
Thatā€™s important, but not especially exciting. Today weā€™re going to move in a
more exciting direction, though.

Today weā€™re going to put Pis #2 and #3 aside, but weā€™re
going to get Pi #1 playing music!

Specifying and Testing the Piā€™s Audio Output

The Raspberry Pi has two options for audio output. It has a
3.5mm analog output, and digital output through its HDMI port. It decides which
output to use automatically ā€“ if you have a HDMI monitor plugged in then the Pi
will detect this and assume you want to use HDMI for audio too.

Thatā€™s not the situation for me (my Pi is ā€œheadlessā€ and
doesnā€™t have a display connected at all), and audio comes out of the 3.5mm
output automatically ā€“ which is what I want. If you need to specify, you can
run:

sudo amixer cset numid=3 1

The digit 1 at the
end means the Pi should use the analog audio output. Putting 0 there instead would mean auto-detect
(the default) and putting 2 would
mean digital output over HDMI.

Plug in some headphones or speakers and run:

aplay /usr/share/sounds/alsa/Front_Center.wav

You should hear a voice saying ā€œfront centre.ā€

Install Mopidy

Weā€™re going to install music playing software called mopidy.
It provides a web-based interface so you can control your music, or there are
controller apps available in your app-marketplace of choice. Mopidyā€™s website
takes you through the
install process in detail
, but Iā€™m going to summarize the commands here:

wget -q -O - https://apt.mopidy.com/mopidy.gpg | sudo apt-key add -
sudo wget -q -O /etc/apt/sources.list.d/mopidy.list https://apt.mopidy.com/mopidy.list
sudo apt-get update
sudo apt-get install mopidy python-setuptools

Done! We now have a basic install of mopidy, and the especially
astute amongst you will have noticed that weā€™ve also installed a package called
python-setuptools. Mopidy is written
in the python programming language, and the latter package is going to help us
with installing and setting up some mopidy extensions in an automated way. The
first thing weā€™re going to do is install something called pip, which is a tool for installing python packages:

sudo easy_install pip

Now that we have that, weā€™re going to in turn use pip to
install some mopidy extensions:

sudo pip install Mopidy-MusicBox-Webclient
sudo pip install Mopidy-WebSettings

With those commands weā€™ve added a web-based interface to our
player so we can control it from a browser on another computer or mobile
device.

Setting Up Mopidy

Weā€™re almost ready to start mopidy and try things out, but
there is a little bit of initial setup to be done first. Edit the file ~/.config/mopidy/mopidy.conf. In the http section, change the following line
so that the web interface becomes accessible to any device on your network:

hostname = ::

In the local
section, tell mopidy where it should find your music library. In my case:

media_dir = /mnt/music

Save the file and exit. The next step is to tell mopidy to
scan your music folder:

mopidy local scan

If, like me, you have a large music collection stored on a
network share, be prepared for this to take a very long time. I started it
running before I went to bed, and it eventually completed the process about 45
minutes after I got up the following morning.

When itā€™s done though, weā€™re ready! Run mopidy:

mopidy

Itā€™ll take a little while to fully start up, but when you
see the line

INFO     HTTP server running at [::]:6680

that means weā€™re good to go. Open the browser on your
computer or mobile device and point it to
http://192.168.1.71:6680/musicbox_webclient (replace 192.168.1.71 with the IP
address of your Pi as appropriate). Go to Browse, Local Media, and select a
song!

If all is well the music will be playing through the
headphones or speakers attached to the Pi, and weā€™re all done until the next
installment ā€“ rerouting the audio from Pi #1 and streaming it, synchronized, to
Pis #2 and #3 instead.

Enjoy!

Blog

Browse Anonymously with a DIY Raspberry Pi VPN/TOR Router

So, after last week’s post about preparing my Raspberry Pis for my whole home audio project, I had three Pis that should have been set up properly, but weren’t working very well – and the culprit was the USB WiFi dongles I was using.

Happily a stumbled upon the article linked above, and it solved the issues I was having!

Surf the Internet securely with your very own portable WiFi VPN/TOR router. You can configure a Raspberry Pi with Linux and some extra software to connect to a VPN server of your choice.

I didn’t follow all the steps because they’re doing something different to me, but there is some commonality and, crucially, the article folks are using WiFi adapters with the same chipset that mine have. Step four shows you how to download and compile a version of hostapd that’s built especially for them and works well. I’ve updated my previous post with these steps.

Now that I have networking all set up I’ve taken a couple of extra steps:

  • I set up passwordless ssh between the three Pis. This isn’t required for my solution per se, it just makes things easier.
  • I used sshfs on pi #1 to connect it to my existing home server, and mount the folder that holds all my music.

I’m excited to move on to next steps! The prep work was necessary, but it didn’t make for an especially interesting blog post because it’s all a bit dry.

Keep following my #RPiWHA Hashtag! The next installment will be more interesting, I promise. We’re going to get some actual music playing!

Browse Anonymously with a DIY Raspberry Pi VPN/TOR Router

Blog

Raspberry Pi Whole Home Audio: Preparation and Networking

At the start of the month I announced my plan to try and build my own whole home audio system using a handful of Raspberry Pis to act as the player and audio
receivers. Iā€™ve received
all the stuff I need
now, and Iā€™m ready to get to building!

The first thing Iā€™m doing is preparing the Pis and setting
up networking. Next Iā€™m going to install audio playing software with a
web-interface on Pi number one, and thirdly Iā€™ll adjust the setup so that this
player sends itā€™s audio to the other two Pis (the receivers) instead of
outputting it directly to its own speakers. You can follow the whole journey by
following the #RPiWHA
Project
hashtag right here.

Installing Raspbian

Raspbian is the Raspberry Piā€™s recommended operating system.
Thereā€™s plenty of guidance online on how
to install it
, so I wonā€™t reiterate the whole process here. When I ran
through Raspbianā€™s initial setup options on first boot I set my location,
timezone and keyboard layout (in Internationalisation Options), set the memory
split to 16mb for graphics (in Advanced Options ā€“ we can set this low because
we wonā€™t even be connecting a display) and finally expanded the filesystem
(right from the main menu).

Minimizing SD Card Access

The Pi has no power button. If itā€™s plugged in then itā€™s on,
and you turn it off by pulling the plug. Iā€™ve read online that if the power is
pulled while the system is in the process of writing to the Piā€™s SD card (which
is the only storage the system has) this can cause problems and possible
corruption.

Linux systems do a lot of logging, most commonly to the
folder /var/log. They also write stuff about running process to the folder
/var/run. To minimize writes to the SD card, weā€™re going to mount these two
folders in memory instead of on the card. Another cause of frequent writes is
that linux systems store the time that a file was last accessed, so even if weā€™re
just reading a file the system is actually writing back to the disk to update
the time that the file was accessed. Weā€™re going to change that behaviour too.

To make these changes, weā€™re going to edit the file
/etc/fstab so that it looks like this:

proc            /proc           proc    defaults          0       0
/dev/mmcblk0p1  /boot           vfat    defaults,noatime  0      2
/dev/mmcblk0p2  /               ext4    defaults,noatime  0      1
none            /var/run        tmpfs  size=1M,noatime   0       0
none            /var/log        tmpfs  size=1M,noatime   0       0

The first two lines havenā€™t changed, but on the third line
weā€™ve added the flag ā€œnoatimeā€ to indicate that we donā€™t want to store the
timestamp that the file was last accessed. The fourth and fifth lines are
entirely new, and these create 1mb partitions in RAM to house the /var/run and /var/log folders respectively.

Setting Up Networking on Pi #1

The next step was to connect one of the Pis (and only one)
to my existing home WiFi network. To do this I plugged in one of my USB WiFi
adapters and modified the /etc/network/interfaces file to include the
following:

auto wlan0
allow-hotplug wlan0
iface wlan0 inet static
wpa-ssid MyHomeWiFiName
wpa-key-mgmt WPA-PSK
wpa-group CCMP TKIP
wpa-pairwise CCMP TKIP
wpa-psk MyHomeWiFiPassword
address 192.168.1.71
netmask 255.255.255.0
gateway 192.168.1.254
dns-nameservers 192.168.1.53 192.168.1.254

Your setup will probably be slightly different, but
essentially this connects to my home network, gives the pi a static IP address
(192.168.1.71 in my case) and defines my two DNS servers.

You may be wondering why Iā€™m only doing this on one of the
Pis, given that they all need to be connected together. The reason is that this
first pi (the player) is ultimately going to be sending audio out over the
network as multicast packets. In other words, this data goes to every device on
the network whether they want it or not.

The problem is that this is a lot of data flowing around, and
a typical home WiFi network struggles under the load of it all. My solution is
to have two WiFi networks. The one weā€™ve set up above will connect us to the
internet (for streaming audio services) and other stuff on my network (like the
fileserver where my music collection lives), but weā€™ll use a second, separate
WiFi network to send the multicast audio to other Pis.

Letā€™s plug in a second USB WiFi adapter to the first Pi, and
make some more additions to the /etc/network/interfaces file:

auto wlan1
allow-hotplug wlan1
iface wlan1 inet static
address 192.168.5.1
netmask 255.255.255.0

This section is pretty minimal as you can see, but itā€™s
setting a static IP address on the second wireless interface. The important
part is that this uses a different subnet to the other WiFi network (in my
case, 192.168.1.x is my existing network, 192.168.5.x is the dedicated network
for the Pis).

This section of the /etc/network/interfaces file is so short
because this Pi is going to act as a wireless access point that the others will
connect to. To set this up we need an additional bit of software, called
hostapd. Because I’m using WiFi adapters based on a Realtek 8188 chipset, I had to download and compile this myself – the version found in the debian software repositories wouldn’t work for me:

wget https://github.com/jenssegers/RTL8188-hostapd/archive/v1.1.tar.gz
tar -zxvf v1.1.tar.gz
cd RTL8188-hostapd-1.1/hostapd
make
sudo make install

Then edit the file /etc/hostapd/hostapd.conf to change the following three lines:

interface=wlan1
ssid=PiWHA
wpa_passphrase=mySecurePassword

Finally, start the service and add it to the boot autostart services for future:

sudo /etc/init.d/hostapd start
sudo update-rc.d hostapd enable

Setting Up Networking on the Other Pis

We want the other Pis to connect to the wireless network
hosted by Pi #1. To do so, plug one USB WiFi adapter into each and modify the
/etc/network/interfaces file on each to reflect the following:

auto wlan0
allow-hotplug wlan0
iface wlan0 inet static
wpa-ssid PiWHA
wpa-key-mgmt WPA-PSK
wpa-group CCMP TKIP
wpa-pairwise CCMP TKIP
wpa-psk mySecurePassword
address 192.168.5.2
netmask 255.255.255.0

The important point here is that the IP address for each
must be unique, and must be on the same subnet (192.168.5.x) that we set on the
first Pi.

Setting Up Time Synchronization

The Raspberry Pi has no real-time clock, and instead it gets
the time from internet time servers at boot. Having the time synchronized on
each of our Pis is going to be important to make sure that they play music in
sync. Only the first Pi has a connection to the wider internet though, so we
need to take some additional steps. On Pi #1, edit the file /etc/ntp.conf and
uncomment (or add) the following line:

broadcast 224.0.0.1

This tells the pi to broadcast a time signal out onto the
network using a special multicast IP address that the other Pis will listen
for.

On the other Pis edit the same file, but uncomment (or add)
the following lines:

disable auth
broadcastclient

We donā€™t need to tell the other Pis which multicast IP
address to listen for ā€“ they already know as part of the NTP protocol.

And Weā€™re Done! Or Are We?

That was a lot of setup work, but we should now have our Pis
setup and networked together, with our player device having an additional
connection to the wider internet.

The thing isā€¦ I donā€™t. The setup is all correct, but the
cheap USB WiFi adapters I bought from China donā€™t properly support access point
mode. Sometimes things work, sometimes they donā€™t.

Iā€™ve read that I can download driver source-code from the
adapterā€™s manufacturer and compile the driver myself, so Iā€™m going to try this
before I go further.

Blog

A little while ago I wrote about the Whole Home Audio project I’m planning, which will be a DIY effort based on several Raspberry Pis.

Well, good news! All the stuff I’d ordered has arrived, and I’m nearly ready to get started. Here’s what you see in the picture:

  1. 3x Raspberry Pi Model B+
  2. 3x Raspberry Pi Enclosure (Black)
  3. 3x Dual USB Power Supply
  4. 5x MicroUSB Cable
  5. 5x USB WiFi Adapter (I need four, but I accidentally ordered too many)
  6. 5x Samsung Class 10 8GB MicroSD Cards
  7. 2x Powered HDMI to VGA Adapter, with Audio Out
  8. 1x USB Wireless Mini Keyboard & Touchpad

Not all of this stuff will make it into the project, but I bought it so that I can use the Pis as media playing devices (running Kodi) that I’ll attach to the bedroom TV and the projector if things don’t work as planned.

I bought the keyboard because it would be useful in that regard, and I got the HDMI to VGA adapters because my projector doesn’t have an HDMI input at all, and the bedroom TV doesn’t have one spare. I’d read online that these things draw quite a bit of power – possibly too much for the Raspberry Pi’s HDMI output to reliably supply – which is why I went for a powered model, and why I picked power adapters with two ports each.

I’ve also read that fast MicroSD cards will greatly contribute to the Pi’s performance and that Class 10 is highly recommended. I also read that some Samsung Class 4 or 6 cards have better real-world performance than some of the Class 10 cards out there. I pushed the boat out and got some Class 10 cards from Samsung.

Follow the #RPiWHA Project hashtag on this blog to keep track of my progress. Next week I’m away travelling from work, but I’m excited to get started and start building, so it won’t be too long until the next update.

Blog

A little while ago I wrote about the Whole Home Audio project I’m planning, which will be a DIY effort based on several Raspberry Pis.

Well, good news! All the stuff I’d ordered has arrived, and I’m nearly ready to get started. Here’s what you see in the picture:

  1. 3x Raspberry Pi Model B+
  2. 3x Raspberry Pi Enclosure (Black)
  3. 3x Dual USB Power Supply
  4. 5x MicroUSB Cable
  5. 5x USB WiFi Adapter (I need four, but I accidentally ordered too many)
  6. 5x Samsung Class 10 8GB MicroSD Cards
  7. 2x Powered HDMI to VGA Adapter, with Audio Out
  8. 1x USB Wireless Mini Keyboard & Touchpad

Not all of this stuff will make it into the project, but I bought it so that I can use the Pis as media playing devices (running Kodi) that I’ll attach to the bedroom TV and the projector if things don’t work as planned.

I bought the keyboard because it would be useful in that regard, and I got the HDMI to VGA adapters because my projector doesn’t have an HDMI input at all, and the bedroom TV doesn’t have one spare. I’d read online that these things draw quite a bit of power – possibly too much for the Raspberry Pi’s HDMI output to reliably supply – which is why I went for a powered model, and why I picked power adapters with two ports each.

I’ve also read that fast MicroSD cards will greatly contribute to the Pi’s performance and that Class 10 is highly recommended. I also read that some Samsung Class 4 or 6 cards have better real-world performance than some of the Class 10 cards out there. I pushed the boat out and got some Class 10 cards from Samsung.

Follow the #RPiWHA Project hashtag on this blog to keep track of my progress. Next week I’m away travelling from work, but I’m excited to get started and start building, so it won’t be too long until the next update.

Blog

Whole Home Audio

Recently, I have become enamoured by the idea of whole home audio. And when I say enamoured, letā€™s be clear what Iā€™m actually talking about: I mean I’ve become obsessed by it.

Hereā€™s the thing though: Iā€™m not obsessed with the functionality. It would be nice to be able to play some music and have it come out of all the speakers in the house (without running cables all over the place), but what Iā€™m actually obsessed with is the price of systems that can do this.

image

The most popular system for whole home audio (or at least the one against which others are apparently measured) is Sonos. In my ideal setup I would want to be able to play music in the living room, kitchen, office and bedroom. To get the Sonos hardware necessary to build the system Iā€™d want (including surround-sound capable hardware in the living room for when we watch TV) Iā€™d have to spend about $3,000, and Iā€™d have to throw out all our existing audio equipment for not being compatible.

Itā€™s simply not worth it, in my opinion.

There are alternatives to the Sonos system available, of course, but this kind of system seems to be primarily the domain of high-end audio manufactures whose wares are priced beyond what I would consider sensible given my needs.

So, Iā€™ve decided not to buy a whole home audio system at all. Iā€™ve decided to try and build my own.

Enter the Raspberry Pi.

image

If youā€™re not familiar, the Raspberry Pi is a credit-card sized computer that costs about $40. It has a 700MHz ARM processor and 512mb RAM. Itā€™s not powerful, then, but it runs a Linux distribution and is designed to be a platform for electronics projects.

To start off with Iā€™m going to buy three of them ā€“ one for sending audio and two to receive it. Iā€™ve read about people who have managed to get a setup similar to the one I want working, and Iā€™ve read about many, many more people who came across challenges they found insurmountable and gave up. The nice thing about the Pi is that I can think of a million uses for it, so if I end up falling into the latter category at least I wonā€™t feel like I wasted my money.

Thereā€™s some Linux software available called Pulse Audio, which will be the basis of my project. Iā€™ve heard of Pulse Audio before because itā€™s the audio subsystem you find in many Linux distributions. What I didnā€™t know until recently though is that itā€™s capable of taking the audio that would normally be output to the computerā€™s speakers and sending it instead to another computer (or several other computers) on the network to be output there.

From what Iā€™ve read online the people that have managed to get this working have done so on a wired network, and theyā€™ve found that if they try and switch to a wireless setup then their router is flooded with audio traffic and canā€™t cope. This is a problem for me because wireless is one of my requirements, so my plan is to use a dedicated WiFi network for the audio: the sender will have two USB WiFi dongles attached, one to connect to the existing wireless network in my home for access to my music library and the internet, and a second to connect to an ad-hoc network used to communicate with the two receivers.

If Iā€™m able to get this setup working then I have some plans for extending the system and building additional functionality. Watch this space!