Introduction: Wireless Raspberry Pi Radio: Pianobar

* This entire process should take about 20 minutes

Pianobar is a free/open-source, console-based client for the personalized online radio Pandora.

Feature:
play and manage (create, add more music, delete, rename, ...) stations
rate songs and explain why they have been selected
upcoming songs/song history
customize keybindings and text output
remote control and eventcmd interface (send tracks to last.fm, for example)
proxy support for listeners outside the USA

Use your Raspberry Pi as a wireless Pandora Radio jukebox! You can  choose to add a display and controls to your Pi to set and navigate stations, however, this tutorial will use an SSH client and mobile devices (tablet or phone) to utilize pianobar's features. 

Step 1: Required Materials

- Raspberry Pi

- SD memory card (4GB or larger)

- Power adapter compatible with the MicroB connector on the Raspberry pi 

- USB Wi-Fi adapter

- Speakers or headphones

- Free or paid Pandora Radio account


Temporary Items for Initial Setup:

- HDMI compatible monitor and cable

- USB Keyboard (no mouse required, all steps done in a terminal environment)

Step 2: Preparation

The Raspberry Pi always needs to boot off of an SD card loaded with an operating system (OS) disk image.

You may buy an SD card that has already been made bootable complete with the Raspberry Pi OS or you may buy a blank card and 

There are many OS versions offered for the Raspberry Pi, however, in this example, I have chosen to use Raspbian “Wheezy”

Download the OS disk image and write it to your memory card. To write the image I used Win32 Disk Imager. Once the image is written to the card, plug the card into the Raspberry Pi's SD card reader and power on the device. (Be sure you have all the proper I/O devices plugged in, i.e., keyboard, USB wifi adapter, HDMI monitor.) 

Step 3: Initial Configuration

Keep in mind, if you mess up anything along the way, just reformat your card, reload the disk image and start again. No harm no foul. 

Upon powering the Raspberry Pi with the SD card plugged in, you will see the system automatically listing information about the operating system and peripherals. You do not need to know what it all means for this project, but I absolutely wouldn't discourage you from reading it and learning a little bit about your Raspberry Pi for your own benefit!

After the boot information is complete, you will be prompted with the raspi-config window. Here you should make the following changes:

- Expand root partition so all space on the SD card is usable.
- Set timezone.
- Enable SSH server (so you can control pianobar with your mobile device as well as continuing this installation on your desktop or laptop via SSH).
- Disable boot to desktop, we want to configure this program using only the terminal environment. 
- Do not update your Raspberry Pi at this point (we need to configure the wireless USB module first) 
- Do not restart your Raspberry Pi at this time.
* I also do not recommend overclocking your Pi for this project, the default setting works perfectly and overclocking will reduce the overall lifetime of the hardware.

Step 4: Configure Wireless USB Module

Navigate to your network interfaces with the following command:

sudo nano /etc/network/interfaces

Erase all the text and copy and past the code you see below:

auto lo

iface lo inet loopback
iface eth0 inet dhcp

allow-hotplug wlan0
auto wlan0


iface wlan0 inet dhcp
    wpa-ssid "ssid"
    wpa-psk "password"


*it should appear as the image below. Change the wpa-ssid value in the quotes to your network's ssid (your wireless network name) and be sure it is still surrounded by quotes.  Do the same with the wpa-psk, change it to the password for your personal wireless network, again, make sure the text is surrounded by quotes. 

To save this edit, hit ctrl+x, you will be prompted if you would like top keep the change, type Y and hit enter for yes and hit enter again to confirm the path of the file. 

Reboot the system with the following command:

sudo shutdown -h now

unplug the Raspberry Pi, wait 30 seconds and then reconnect the power supply.

You should see the Raspberry Pi attempting to join the network during the initial boot process in a series of DHCPDISCOVER messages. If it cannot connect, use sudo nano /etc/network/interfaces to recheck your network settings and reboot the Pi one more time. 

Step 5: SSH Into and Update Your Pi

Now you can SSH into your Raspberry Pi to finish the installation on your desktop or laptop. 

first you need to get the IP address of your Pi. Do this with the following command:

ifconfig

once you run that command, look for the inet addr: value. This is your Raspberry Pi's IP address. You will use this when trying to connect to the device.

If you are on a windows machine, I would advise that you download putty as your ssh client. If you are on a mac or linuix system, use the following command:

ssh pi@10.10.10.10

where pi is the name of your Raspberry Pi (by default the name is pi) and 10.10.10.10 is the inet addr value that you got when you ran ifconfig

If prompted for a password and you have not changed it on your own, the default password for the Raspberry Pi is "raspberry" (without quotes)

Once logged on, update your device with the following command:

sudo apt-get update

*this may take some time




Step 6: Installing Pianobar

To install pianobar use the following command:

sudo apt-get install pianobar

the pianobar installer will ask if you would like to continue. Type "y" for yes and hit enter to continue.

The installer will run automatically after you confirm the install. 

Step 7: Configure Pianobar

Create the config directory for Pianobar:

mkdir -p .config/pianobar

Navigate to the new directory:

cd ~/.config/pianobar

Once in the newly created directory, create a configuration file called "config":

sudo nano config

copy and paste the following into the GNU nano editing window:


# This is an example configuration file for pianobar. You may remove the # from
# lines you need and copy/move this file to ~/.config/pianobar/config
# See manpage for a description of the config keys
#
# User
user = YOUR_EMAIL_ADDRESS
password = YOUR_PASSWORD
# or
#password_command = gpg --decrypt ~/password

# Proxy (for those who are not living in the USA)
#control_proxy = http://127.0.0.1:9090/

# Keybindings
act_help = ?
act_songlove = +
act_songban = -
act_stationaddmusic = a
act_stationcreate = c
act_stationdelete = d
act_songexplain = e
act_stationaddbygenre = g
act_songinfo = i
act_addshared = j
act_songmove = m
act_songnext = n
act_songpause = p
act_quit = q
act_stationrename = r
act_stationchange = s
act_songtired = t
act_upcoming = u
act_stationselectquickmix = x
act_voldown = (
act_volup = )

# Misc
#audio_quality = low
#autostart_station = 123456

#event_command = /home/pi/.config/pianobar/scripts/eventcmd.sh
#fifo = /home/pi/.config/pianobar/ctl
#sort = quickmix_10_name_az
#love_icon = [+]
#ban_icon = [-]
volume = -30

# Format strings
format_nowplaying_song = SONG: %t | %a | %l
format_nowplaying_station = STATION: %n | %i
format_msg_time = TIME: %s
# No special prefix on songs, stations or info
format_msg_nowplaying = %s
format_msg_info = %s

# high-quality audio (192k mp3, for Pandora One subscribers only!)
#audio_quality = high
#rpc_host = internal-tuner.pandora.com
#partner_user = pandora one
#partner_password = TVCKIBGS9AO9TSYLNNFUML0743LH82D
#device = D01
#encrypt_password = 2%3WCL*JU$MP]4
#decrypt_password = U#IO$RZPAB%VX2

tls_fingerprint = 2D0AFDAFA16F4B5C0A43F3CB1D4752F9535507C0



Look for the following lines in the text you just copied into the GNU nano editing window. Change the text to your respective email and password you use for your free Pandora Radio account. 

user = YOUR_EMAIL_ADDRESS
password = YOUR_PASSWORD.


hit ctrl-x to exit the editor, type "y" to save the changes and hit enter one more time to confirm the file name.

You may not launch the Pianobar application by simply typing the following in your terminal window (once you are out of the GNU nano editor):

pianobar


*if you cannot hear any music, use ) to turn up the volume and use ( to turn it down. Again, to turn up the volume shift+0 increases volume, shift+9 decreases it

Step 8: Download an SSH for Your Mobile Device and Control Pianobar Remotely

I use my iPhone to control my wireless Pandora Pi using a mobile SSH client called ServerAuditor. It allows you to set up multiple devices and pre-configure the settings for quick connections.

(If you are going to attempt to configure settings for your devices so you connect to them quickly, I would suggest giving the devices a static IP address so you do not have to change the IP setting in the app every time you want to connect to the device)  

Now you are all set to control your music from anywhere in your house!

Step 9: Keyboard Controls

act_help = ?
              Show keybindings.

       act_songlove = +
              Love currently played song.

       act_songban = -
              Ban  current  track.  It  will  not be played again and can only
              removed using the pandora.com web interface.

       act_stationaddmusic = a
              Add more music to current station.  You  will  be  asked  for  a
              search  string. Just follow the instructions. If you're clueless
              try '?' (without quotes).

       act_bookmark = b
              Bookmark current song or artist.

       act_stationcreate = c
              Create new station. You have to enter a search string and select
              the song or artist of your choice.

       act_stationdelete = d
              Delete current station.

       act_songexplain = e
              Explain why this song is played.

       act_stationaddbygenre = g
              Add genre station provided by pandora.

       act_history = h
              Show history.

       act_songinfo = i
              Print information about currently played song/station.

       act_addshared = j
              Add shared station by id. id is a very long integer without "sh"
              at the beginning.

       act_songmove = m
              Move current song to another station

       act_songnext = n
              Skip current song.

       act_songpause = p
              Pause/Continue

       act_quit = q
              Quit pianobar.

       act_stationrename = r
              Rename currently played station.

       act_stationchange = s
              Select another station.

       act_songtired = t
              Ban song for one month.

       act_upcoming = u
              Show next songs in playlist.

       act_stationselectquickmix = x
              Select quickmix stations.

       audio_format = {aacplus,mp3,mp3-hifi}
              Select audio format. aacplus is default if both libraries (faad,
              mad)  are  available.  mp3-hifi  is  available  for  Pandora One
              customers only.

       autostart_station = stationid
              Play this station when starting up. You can get the stationid by
              pressing i or the key you defined in act_songinfo.

       control_proxy = http://host:port/
              Non-american  users  need  a  proxy to use pandora.com. Only the
              xmlrpc interface will use this  proxy.  The  music  is  streamed
              directly.

       event_command = path
              File that is executed when event occurs. See section EVENTCMD

       history = 5
              Keep a history of the last n songs (5, by default). You can rate
              these songs.

       password = plaintext_password
              Your pandora.com password. Plain-text.

       proxy = http://host:port/
              Use  a  http  proxy.  Note  that  this  setting  overrides   the
              http_proxy environment variable.

       sort  =  {name_az,  name_za,  quickmix_01_name_az, quickmix_01_name_za,
       quickmix_10_name_az, quickmix_10_name_za}
              Sort station list by  name  or  type  (is  quickmix)  and  name.
              name_az   for   example   sorts   by   name   from   a   to   z,
              quickmix_01_name_za by type (quickmix at the  bottom)  and  name
              from z to a.

       user = your@user.name
              Your pandora.com username.

*taken from http://manpages.ubuntu.com/manpages/maverick/man1/pianobar.1.html