Pi Pandora over the Pond

26Aug13

A friend of mine recently returned from working in the US for 3 years, where he’d got to like listening to Internet radio using Pandora. He wanted to get things set up so that he could listen to Pandora on his kitchen stereo.

Challenge #1 – be in the US

Pandora uses IP geolocation to restrict service to US IPs, so we needed a point of presence in the US. After signing up to Amazon Web Services (AWS) a t1.micro machine running in their free tier provided the requisite local IP address with access over SSH and OpenVPN.

We then configured FoxyProxy to send *.pandora.*/* to a SOCKS proxy running on PuTTY that was in turn connected to the Amazon machine and music streamed.

Challenge #2 – make it elegant

Getting Pandora on a laptop was fine, but it wasn’t connected to the kitchen stereo, and hooking it up would be a inelegant mess.

We tried repurposing some old iPhones, but they were too old to run the Pandora or OpenVPN apps.

We then tried using an Android tablet, which was able to work fine with the Pandora and OpenVPN apps from the Play store, but it looked a bit precarious sat up by the stereo, and I was worried that it was only a matter of time before the tablet would be hurtling towards the kitchen floor.

A Raspberry Pi tucked behind the stereo seemed like a much more elegant approach, and luckily my friend had one sat in a box waiting for its first project.

Three steps to success

To make the Raspbeery Pi work we needed network connectivity, VPN connectivity and a Pandora client:

1. Network connectivity

The kitchen stereo was nowhere near my friend’s router, so a cabled connection to the Pi wasn’t an easy option. I did suggest using some Powerline adaptors, but WiFi using a USB adaptor was going to be cheaper. Sadly he didn’t have an (ever reliable) Edimax EW-7811Un WiFi on hand, and I hadn’t brought one with me. We picked up a TPLink TL-WN725N from a local store after confirming that it worked with the Raspberry Pi.

Sadly the TL-WN725N we got didn’t work out of the box with (Jul 2013) Raspbian, but luckily putting the right drivers in place was not too hard (thanks to the pi3g blog):

wget http://resources.pichimney.com/Drivers/WiFi/8188eu/8188eu-20130209.tar.gz
tar -xvf 8188eu-20130209.tar.gz
sudo install -p -m 644 8188eu.ko /lib/modules/3.6.11+/kernel/drivers/net/wireless
sudo depmod -a
sudo modprobe 8188eu
sudo ifdown wlan0
sudo ifup wlan0

With that down the Pi was then available over WiFi.

2. OpenVPN

The OpenVPN client is a standard Raspbian repository, so:

sudo apt-get install -y openvpn

Then copy the client.ovpn file from the OpenVPN server to /etc/openvpn/client.conf

I didn’t want the openvpn to start on boot (as it was prompting for username and password) so the service was set to manually start:

sudo update-rc.d -f openvpn remove

With that done the tunnel could be brought up with:

sudo service openvpn start

and I could confirm that it was working by:

wget http://ipecho.net/plain -O – -q ; echo

and observing the US IP address of the AWS EC2 virtual machine.

3. Pandora client

There’s a command line client for Pandora called pianobar, which is part of the standard Raspbian respository:

sudo apt-get install -y pianobar

It needs a small config file in place before it works:

mkdir -p ~/.config/pianobar
echo ‘user = YOUR_EMAIL_ADDRESS‘ >>  ~/.config/pianobar/config
echo ‘password = YOUR_PASSWORD‘ >> ~/.config/pianobar/config

Make sure to substitute your own email address and Pandora password in the lines above. The following needs to be entered on a single line:

fingerprint=`openssl s_client -connect tuner.pandora.com:443 < /dev/null 2> /dev/null | openssl x509 -noout -fingerprint | tr -d ‘:’ | cut -d’=’ -f2` && echo tls_fingerprint = $fingerprint >> ~/.config/pianobar/config

To make sure that audio comes out of the 3.5mm jack on the Pi:

sudo amixer cset numid=3 1

At this stage pianobar can be run (and if all is right a list of channels will appear):

pianobar

Success :)

With the Raspberry Pi plugged into the kitchen stereo we could now listen to my friend’s favourite stations.

Improvements

Adafruit make a Raspberry Pi WiFi radio kit that adds buttons for channel selection and a dot matrix screen to show track info. I should also investigate web and mobile clients, but a command line station selection seems good enough.

Conclusion

The Raspberry Pi makes a good receiver for Pandora Internet radio, wherever you might be.



2 Responses to “Pi Pandora over the Pond”

  1. 1 John Morton

    That’s a great project for our year 10/11 students in Darwin, NT. Thanks Chris.

    • Pandora is licensed in Australia, so you won’t need the OpenVPN bit (unless you want to teach them how to circumvent geolocking, which of course is a useful skill for any teen).


Leave a reply to John Morton Cancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.