Tuesday, April 1, 2014

SoundPi - Initial Setup

These are my notes from setting up a headless Raspberry Pi to act as a Squeezebox Client and a Bluetooth audio endpoint.

I got the image to install from http://downloads.raspberrypi.org/raspbian_latest.

SD Card Setup (on OS X)
Instead of downloading a special tool, I just used what was built in to OS X. It worked fine.

diskutil list
diskutil unmountDisk /dev/disk3
sudo dd bs=1m if=2014-01-07-wheezy-raspbian.img  of=/dev/rdisk3
diskutil unmountDisk /dev/disk3

Base Raspberry Pi Setup
Airport Extreme (my main wifi access point) doesn't have a good way of finding the DHCP clients. Instead I just starting sshing to addresses at the start of the reservation range until I found my pi at  (A better way, arguably, would be to do an nmap scan, or use a wifi router that lets you see the client addresses).

Once logged in I ran:
sudo raspi-config
To configure basics like hostname, change the pi password and update the tool, etc...
To figure out what the mac address was so that I could set a DHCP reservation for that client so that the IP address wouldn't change again.

I then cribbed some commands from http://glynrob.com/hardware/raspberry-pi-headless/ to get the base OS update to date:
sudo aptitude update 
sudo aptitude dist-upgrade

WiFi Setup
I have a Panda Wireless wifi adapter (enumerates via lsusb as 'Ralink Technology, Corp. RT5370 Wireless Adapter').  I followed these instructions to hook it to my local wifi network (using DHCP): http://kerneldriver.wordpress.com/2012/10/21/configuring-wpa2-using-wpa_supplicant-on-the-raspberry-pi/

This worked, but I was getting extremely high ping times.

64 bytes from icmp_seq=445 ttl=64 time=434.857 ms
64 bytes from icmp_seq=446 ttl=64 time=138.993 ms
64 bytes from icmp_seq=447 ttl=64 time=59.932 ms
64 bytes from icmp_seq=448 ttl=64 time=184.787 ms
64 bytes from icmp_seq=449 ttl=64 time=105.108 ms
64 bytes from icmp_seq=450 ttl=64 time=26.188 ms
64 bytes from icmp_seq=451 ttl=64 time=150.148 ms

64 bytes from icmp_seq=452 ttl=64 time=172.865 ms

Numbers like this aren't really acceptable.  Some brief investigation led me to this post, which suggests seeing if 'sudo iwconfig wlan0 power off' would solve the problem.  It did. Immediately after running this command my ping times fell.

64 bytes from icmp_seq=775 ttl=64 time=103.008 ms
64 bytes from icmp_seq=776 ttl=64 time=2.566 ms
64 bytes from icmp_seq=777 ttl=64 time=6.522 ms
64 bytes from icmp_seq=778 ttl=64 time=3.317 ms
64 bytes from icmp_seq=779 ttl=64 time=2.228 ms
64 bytes from icmp_seq=780 ttl=64 time=5.511 ms

I then added the line 'wireless-power off' to /etc/network/interfaces. This turns off power management for the 802.11 interface.

Here's the final contents of /etc/network/interfaces:
auto lo

iface lo inet loopback

auto eth0
allow-hotplug eth0
iface eth0 inet dhcp

allow-hotplug wlan0
# have to use 'manual' with wpa-roam
iface wlan0 inet manual
wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
wireless-power off

iface default inet dhcp

To make sure wireless comes up at every boot I added the following to /etc/rc.local

# Make sure wireless comes up
sudo ifup wlan0

After all this I encountered the problem that if I plugged in ethernet, it would shutdown wifi.  This was because of ifplugd.  The simple solution is just to uninstall ifplugd (from http://www.raspberrypi.org/phpBB3/viewtopic.php?f=36&t=67761).

sudo apt-get purge ifplugd

This has the side-effect of leaving eth0 up even after it isn't connected.  This may or may not be a problem.  There's likely a better way to do this (some of which I tried with no immediate luck).

That's the basic setup.  Next time, configuring bluetooth audio.