Random Access Science

Geophysics, Glaciology, Computer Science and everything inbetween

XBMC Kitchen Radio

A while back I decided to turn a old Dell Inspiron Mini 10 netbook into a XBMC radio for the kitchen. My requirements where,

  • Stream music from my server
  • Stream online radio
  • Remote control from my other devices
  • Push media to device
  • Low power consumption

Installing XBMC from ppa

First add the XBMC ppa repository to your apt-get list and then install XBMC

1
2
 sudo add-apt-repository ppa:team-xbmc
 sudo apt-get install xbmc xbmc-eventclients-xbmc-send

Configure for low power consumption

I am a big fan of turning off my devices when I do not use them. I am going to use the laptop for less than a hour on average each day so I do not want it running 24/7. In Linux there are two powersaving modes: Suspension and Hibernation. During suspension the machine is still running and uses a bit of power. In hibernation the RAM is dumped to the harddrive and no power is used.

When you use a normal kitchen radio you just flick the power switch when you leave. I really wanted that feature in this device. Since I am using a laptop it can survive on battery power for a couple of hours. So I wrote a small script that detects if there is a active external power connection to the netbook and shutdown if the user turns of the power (on the wall socket).

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#!/bin/bash
PowerStatus=yes # Is the power on?
LinePower_Path=/org/freedesktop/UPower/devices/line_power_ACAD # Found using upower -e

while [ 1 ]
do
# Check current power status
PowerStatus=$(upower -i $LinePower_Path | grep online | awk '{ print $2}')

if [ "$PowerStatus" == "no" ]; then

# Test by sending a message?
#    notify-send "Power status: $PowerStatus"

# Mute sound to smooth things
xbmc-send --host=127.0.0.1 --port=9777 --action="PlayerControl(Stop)"

# Put into hibernation
sleep 2
sudo pm-hibernate

fi

# Sleep for 10 seconds and check status again
sleep 10

done

Here i use the upower tool in Ubuntu to check current power status. The path (/org/freedesktop/UPower/devices/line_power_ACAD) may vary between systems. You can determine it by running the UPower command,

1
   upower -e

When the power is cut it will stop whatever is playing using the xbmc-send command (Full command list) and put the system into hibernation. The script is run in a while loop so the status is checked every 10 seconds. To run the script on boot save it to disk and edit /etc/rc.local (works on Ubuntu). The file should look something like this,

1
2
3
4
5
   #!/bin/sh -e

   ./home/christian/detect_linepower.sh &
   sudo killall NetworkManager
   exit 0

Setting up streaming and media push functions

Music streaming works out out-of-the-box in XBMC. Just hook-up your server via a NFS or SMB connection to the client. To get streaming Danish TV/radio I normally install the addons developed by Tommy Winther.

If you have several devices you can push content using the UPnP features build into XBMC settings (UPnP/Client). With this I can push music from my laptop/server to the radio with zero setup. I do however need XBMC installed on the device that sends contents.

If you want complete control of the radio without having a monitor attached I suggest using the web interface build into XBMC. There are some nice addons available to improve on the web experience (Chorus).