Install Pianobar (Pandora) on Raspberry Pi

Posted by Max Power | Posted in Raspberry Pi | Posted on 04-11-2014-05-2008

0

In this post we will install Pianobar, an application for streaming Pandora on the Raspberry Pi.

Install the Prerequisites

sudo apt-get -y install git pkg-config libevent-pthreads-2.0-5 libao-dev libgnutls28-dev libmad0-dev libfaad-dev libjson0-dev libgcrypt11-dev

Compile Pianobar

Now lets download Pianobar from github. Apparently the one from apt-get is out of date (reference).
git clone git://github.com/prattmic/pianobar.git
cd pianobar
make
sudo make install

Note: You may get it from https://github.com/PromyLOPh/pianobar as well (this one may be more up to date).

Configure Pianobar

Now lets configure pianobar. First create the Pianobar config file (or copy it from /usr/share/doc/pianobar/contrib/config-example).
mkdir -p .config/pianobar
Navigate to the new directory and create the config file
cd ~/.config/pianobar
sudo nano config

Copy the following into the config file:
# 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

Replace the following lines with your username and password for Pandora
user = YOUR_EMAIL_ADDRESS
password = YOUR_PASSWORD

Note: If you get the error “Login… Network error: TLS handshake failed.”, Pandora may have changed the tls_fingerprint (it is correct as of 12/3/2014). Or your login credentials may be wrong. You can get the current tls_fingerprint following these steps…

First create a file (placement of the file is not important)
cd
sudo nano pandora_tls

Now copy in this code (refrence: https://gist.github.com/r35krag0th)
#!/bin/bash
##
## A simple little shell script that will return the current
## fingerprint on the SSL certificate. It's crude but works :D
##
## Author: Bob Saska (r35krag0th) <git@r35.net>
##
openssl s_client -connect tuner.pandora.com:443 < /dev/null 2> /dev/null | \
openssl x509 -noout -fingerprint | tr -d ':' | cut -d'=' -f2

Then run the script
sudo bash pandora_tls
It will then return to you the latest tls_fingerprint and you can replace the one in the config file with that one.

Run Pianobar

Now lets launch Pianobar
cd
pianobar

Note: The volume may be low. Use “)” to increase the volume and “(” to reduce the volume. Use “q” to quit. The other commands are shown below.  If you need to change the audio source to the 3.5mm jack, run the following command…
sudo amixer cset numid=3 1

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

Refrences

  • https://learn.adafruit.com/pi-wifi-radio/raspberry-pi-setup-2-of-3
  • http://www.instructables.com/id/Wireless-Raspberry-Pi-Radio-Pianobar/?ALLSTEPS

Install Shairport on Raspberry Pi

Posted by Max Power | Posted in Android, Raspberry Pi | Posted on 04-11-2014-05-2008

0

This post will walk the user through the process of installing Shairport on the Raspberry Pi.  The following instructions assume that you are using the standard Raspbian (Debian Wheezy) install, it is installed and running, and you are connected to the internet.

Once you have Shairport installed and running, you will be able to stream audio from your Apple or Android device to the Raspberry Pi.  AllStream Cast+AirPlay+DLNA and AirPlay DLNA SONOS Chrome Roku are two applications for Android that will allow you to stream audio from you device to an AirPlay device or multiple devices.  Sonos replacement????

Update Packages

First make sure that your packages are up to date
sudo apt-get update && sudo apt-get upgrade

Install Prerequisites

Install the prerequisite packages
sudo apt-get install build-essential libssl-dev libcrypt-openssl-rsa-perl libao-dev libio-socket-inet6-perl libwww-perl avahi-utils pkg-config git libssl-dev libavahi-client-dev libasound2-dev libpulse-dev libmodule-build-perl

Optional
sudo apt-get install chkconfig

Update Firmware

Make sure that your firmware is up to date, this will hopefully avoid the popping noise when the audio is selected
sudo git clone git://github.com/Hexxeh/rpi-update.git
sudo rpi-update/rpi-update

Reboot to activate the new firmware
sudo reboot

Install Perl Net-SDP

Apparently a change in IOS 6 requires this module to be installed or else shairport will crash.
sudo git clone https://github.com/njh/perl-net-sdp.git perl-net-sdp
cd perl-net-sdp
sudo perl Build.PL
sudo ./Build
sudo ./Build test
sudo ./Build install
cd ..

ALSA

To avoid the error “Unknown PCM cards.pcm.front”, modify the ALSA config (refrence: http://cagewebdev.com/index.php/raspberry-pi-getting-audio-working/)
sudo nano /usr/share/alsa/alsa.conf
Change the line “pcm.front cards.pcm.front” to “pcm.front cards.pcm.default”

avahi-daemon

Now we will modify the avahi-daemon init.d script to fix the issue with avahi-daemon that gives the “avahi-daemon disabled because there is a .local domain” on many networks.
sudo nano /etc/init.d/avahi-daemon
Modify the line DISABLE_TAG=”/var/run/avahi-daemon/disabled-for-unicast-local and change it to DISABLE_TAG=”/var/run/avahi-daemon/disabled-for-unicast-local-DISABLE
Restart the avahi-daemon
sudo service avahi-daemon restart

Shairport

Install Shairport
sudo git clone -b 1.0-dev git://github.com/abrasive/shairport.git
cd shairport
sudo ./configure
sudo make
sudo make install

Start Shairport and test it to see if it is working
./shairport -a 'AirPlay'
Now using one of the Andriod apps listed above or iTunes you should be able to see this device and stream music to it. If you have speakers connected to the 3.5mm jack you may have to make that the default output for audio (see the audio setup below).

We are done in this folder
cd ..

Audio Setup

The following command will set the output to the 3.5mm jack (by default it is set to the HDMI)
sudo amixer cset numid=3 1
Adjust the audio level with the following command
alsamixer
*Note: If you get one of these errors: ‘amixer: Control default open error: No such file or directory’ or ‘cannot open mixer: No such file or directory’, the following command should fix things (Ref)
sudo modprobe snd_bcm2835

Starting Shairport on boot

Next we will set Shairport to launch on boot, first we will copy the startup script
sudo cp scripts/debian/init.d/shairport /etc/init.d/shairport

I want the start up script to use the pi user and not the admin user as it is setup to by default, therefore I need to edit the start up script
sudo nano /etc/init.d/shairport
Edit the following lines to read (reference: https://gist.github.com/khromov/6398615)
DAEMON=/usr/local/bin/shairport
USER=root
GROUP=nogroup
Note: The name of the device is set by default to the name of the Raspberry Pi. If you don’t want that, you can change AP_NAME and give it the name you want.

cd /etc/init.d
sudo chmod a+x shairport
sudo update-rc.d shairport defaults

Shairport Watchdog

We want to make sure that avahi-daemon starts before shairport otherwise shairport will fail.  The script will use pgrep so we need to install those packges
sudo apt-get install pcregrep pgrep
Now we will write a script called shairport-watchdog.sh in /root
sudo nano /root/shairport-watchdog.sh
that contains the following code (reference: https://github.com/abrasive/shairport/issues/242)
# find service pids
pgrep shairport
#if we get no pids, service is not running
if [ $? -ne 0 ]
then
service shairport start
echo "shairport started or restarted."
fi

Now edit the /etc/crontab file
sudo nano /etc/crontab
and add the following line
* * * * * root /bin/sh /root/shairport-watchdog.sh > /dev/null
Final cleanup
sudo chown -R pi:pi /home/pi/

References

  • http://snippets.khromov.se/raspberry-pi-shairport-build-instructions/
  • http://www.raywenderlich.com/44918/raspberry-pi-airplay-tutorial
  • http://adrianmejia.com/blog/2014/02/15/cheap-airplay-receiver-with-raspberry-pi/

Raspberry Pi Error – Entering kdb (current=0xce82ac80, pid 1) due to Keyboard Entry kdb>

Posted by Max Power | Posted in Raspberry Pi | Posted on 25-09-2013-05-2008

1

Saw the following error when trying to boot my Raspberry Pi:

Entering kdb (current=0xce82ac80, pid 1) due to Keyboard Entry kdb>

I determined that it was an error with the SD card and this is how I fixed it.  I took the SD card and put it in a USB SD card reader and plugged it into my Windows 7 machine that has a Mythbuntu (64 bit) Virtual Machine running in Oracle VM Virtualbox.  I mounted the USB drive in the VM and used GParted to determine what the mount path was.  In this case it was “/dev/sdc2”.  I then launched the terminal application and used the following command:

sudo e2fsck -f -v /dev/sdc2

After quite a while and answering yes a million times the process was done.  I then unmounted the card, put it back in the RPi and it booted fine.

Hopefully this is helpful to someone else out there (and hopefully this will help me to remember what I did to fix the problem last time).