Mon 15th Oct 2012 at 13:00

Cooking up a Raspberry Pi Music Player (MK-II)

I have finally managed to complete my 2nd attempt at the jukebox / music player using a Raspberry Pi, Music Player Daemon (MPD) and Client175. This time using ArchLinux instead of Raspbian.This was also prompted by firstly having my initial USB hub start to smoke (be careful of leaving cheap hubs permanently powered) and secondly, the fact I managed to destroy the installation by attempting to uninstall all things X from the system. Apparently my face was a picture when I saw the packages "mpd" and "als-utils" being automatically removed!

 

IMAG0894.jpg

 

While Rasbian is okay and based on an OS I know intimately (Debian), the appeal of ArchLinux was how streamlined it is out of the box. However, unlike the Raspbian version, I endured a lot of irritation and frustration as I struggle to find information about the simplest of task (e.g. Static IP addresses). Rather than detail all the painful circles I went round to get this project to this stage, I will simply highlight the initial problem and solution.

 

Getting Started

The ArchLinux image is available from the Raspberry Pi's Download page. Once downloaded I simply inserted my SD card into my laptop and executed the following commands: (Sorry, I'm a Linux user, so if you use windows you should check out this page)

    1. unzip archlinux-hf-2012-09-18.zip
    2. sudo dd bs=1M if=archlinux-hf-2012-09-18.img of=/dev/mmcblk0
    3. sudo sync

You should be aware that above device path (/dev/mmcblk0) could be different from machine to machine.

Once this has been done, simply pop the SD card out of you computer and slot it into the Raspberry Pi.

    1. Plug the RJ45 network socket (While WiFi works, it will require some further configuration)
    2. Plug the power source in and wait

For this version, I decided to add the added challenge of do this build completely headless., so the following information was quite usuaful. 

      • Default Username: root
      • Default Passowrd: root
      • Default Hostname: alarmpi

So using this information I was simply about to ssh onto the Raspberry Pi. However, if you have no way of finding this out and want the similar challenge, you could try a ping sweep (I use nmap -sP 192.168.1-254 and see what IP addresses are ping-able.

Once I logged in, I then proceeded to also:

    1. update the OS using pacman: pacman -Syu
    2. change the hostname from raspberrypi to raspmusicplayer: sudo echo raspmusicplayer > /etc/hostname
    3. chnage the default password
    4. reboot



Installing and Configuring the Software

Like Raspbian, installing the software was extremely simple. I had the basic software all installed pretty much by this command:

pacman -S alsa-utils mpd mpc

However, there was a bit of configuration that needed completing.

 

Load the kernel module

While you think it would be abvious, it was to me and caused a bit of head scratching.

    1. echo snd-bcm2835 > /etc/modules-load.d/sound.conf
    2. modprobe snd-bcm2835

 

Music Player Daemon

    1. systemd-tmpfiles --create
    2. mkdir -p /var/lib/mpd/playlists
    3. touch /var/lib/mpd/{mpd.db,mpdstate}
    4. chown -R mpd.audio /var/lib/mpd
    5. vi /etc/mpd.conf and change the following entries
      music_directory        "/var/lib/mpd/music"
      
      #bind_to_address        "localhost"
      
      auto_update    "yes"
      
      zeroconf_enabled        "yes"
      
      zeroconf_name            "Raspberry Pi Music Player"
      

Also, as I use a static IP address (see WiFi section), I have also added to the following lines to the mpd.conf file:

BindAddress 127.0.0.1

BindAddress 192.168.1.3

 Note: First pain occured with starting the player on boot. While it was starting, none of the clients were able to communicate and running systemctl status mpd returned an error and failed to start:

mpd.service - Music Player Daemon
	  Loaded: loaded (/usr/lib/systemd/system/mpd.service; enabled)
	  Active: active (running) since Mon, 15 Oct 2012 12:26:21 +0100; 1s ago
	Main PID: 248 (mpd)
	  CGroup: name=systemd:/system/mpd.service
		  â”” 248 /usr/bin/mpd --no-daemon

Jan  1 01:00:08 raspmusicplayer mpd[96]: Failed to bind to '192.168.1.3:6600': Cannot assign requested address
Jan  1 01:00:08 raspmusicplayer systemd[1]: mpd.service: main process exited, code=exited, status=1
Jan  1 01:00:08 raspmusicplayer systemd[1]: Unit mpd.service entered failed state.

The issue was that mpd was trying to start prior to the wireless connection being established. The solution was to edit the /usr/lib/systemd/system/mpd.service and add change the After= line to:

After=sound.target network.target

 

Client175

I really like this client as you can even edit the mp3 tags. However, I'm on the look out for a mobile friendly web UI, but may well try writing my own. Due to ArchLinux being such a thin install, you will need to install python, this is achieved by the following command:

pacman -S mutagen python-beautifulsoup python2 python2-cherrypy

You will need to download the tarball.

wget http://client175.googlecode.com/files/client175_0.7.tar.gz

Once downloaded:

    1. cd /var/lib/mpd
    2. sudo -u mpd tar -zxvf /home/pi/client175_0.7.tar.gz
    3. vi client175/site.conf and change the following entries
      music_directory: "/var/lib/mpd/music/"

      run_as: "mpd"
    4. vi  /etc/rc.local and add the following line before the exit(0), this will ensure that Client175 is fired up automatically
      /usr/bin/python /var/lib/mpd/client175/server.py &> /var/log/mpd/Client175.log &

Now let me introduce the second pain. Getting Client175 to start on boot.

I started off trying to replicate the SysVInit rc.local method, but no matter what I did I could not get Client175 to start on boot. This caused me enormous amounts of frustration, as I found that the documentation seemed to be sparse on this subject and use forums seemed to be full of people informing me "don't use rc.local. It's an ugly hack and there's always a better way." but never offering me information as to what the "better way" was. Eventually I worked it out that I should create my out systemd config file:

/usr/lib/systemd/system/client175.service:

[Unit]
Description=A Web Server Frontend for Music Player Daemon
After=mpd.service

[Service]
ExecStart=/usr/bin/python2 /var/lib/mpd/client175/server.py 

[Install]
WantedBy=multi-user.target

 

WiFi

This was in some ways very easy and in some way a pain in the arse and it seems that there is very little documentation on

    1. Setting up a wireless connection
    2. Configuring the connection to be static

So, to keep things simple, I have only documented what I did to get it working, not everything I tried to do.

Install the software:

pacman -S wireless_tools netcfg wpa_supplicant

Edit /etc/wpa_supplicant/wpa_supplicant.conf:

ctrl_interface=/var/run/wpa_supplicant
eapol_version=1
ap_scan=1
fast_reauth=1
network={
    ssid="ACCESSPOINT_NAME"
    proto=RSN
    key_mgmt=WPA-PSK
    pairwise=CCMP TKIP
    group=CCMP TKIP
    psk="PASSPHRASE"
}

Edit /etc/network.d/home.static:

CONNECTION='wireless'
DESCRIPTION='A simple WPA encrypted wireless connection using a static IP'
INTERFACE='wlan0'
SECURITY='wpa-config'
WPA_CONF='/etc/wpa_supplicant/wpa_supplicant.conf'
IP='static' 
# Any other CONNECTION='ethernet' options may be used.
ADDR='192.168.1.3'
GATEWAY='192.168.1.254'
DNS=('192.168.1.254')
# Uncomment this if your ssid is hidden
#HIDDEN=yes

Finally, you should be able to execute the following:

    1. systemctl disable dhcp@something.service
    2. systemctl enable netcfg@home.static.service
    3. reboot

Note: As soon as you have issued the reboot command, you need to whip the wired network out of it's socket.

 

This site uses cookies, please read my cookie policy.