Saturday, December 21, 2013

60 minutes of music I've discovered in 2013

Friday, December 20, 2013

Linn DS Alarm Function

Update 2014 - An alternative to this is available on GitHub which uses Node.js and should be cross platform. Linn DS Playlist and Alarm Server

Switching the radio on in the kitchen in the morning is a low priority amongst setting table, pouring cereals, carrying children, etc. The Sonos has an alarm clock facility which allows you to switch on the radio at a set time avoiding hassle of starting a controller.

When I upgraded to my Linn Sneaky DS, I no longer had this function, though the remote control made it easy if I forgot to take my phone downstairs with me.

Last week I decided to figure it out. I have a Linux machine which runs Ubuntu and runs all the media servers, backups and network shares. I decided to investigate how to control my DS from the command line.

Conveniently, the DS can be controlled via a web api, so after reading the docs and a few examples I was able to switch off and on and change source via Postman (Chrome REST client).

I then set about writing a curl script to send the commands and package this up as a shell script.

One final problem was discovering the IP address of the DS which I solved by using gupnp-tools which has a scanner; this scans my network for UPNP devices and since I know the UUID of the DS I can extract the correct IP address.

By adding the script to my Linux box' crontab, the DS starts on the radio each weekday morning.

How it works

Need to install gupnp-tools which provides gssdp-discover.

I created a script called which takes a parameter of the UUID of a Upnp device and returns the IP address:

gssdp-discover -t ${1} -n 3 | grep Location | sed 's/.*http:\/\///' | sed 's/:.....\/.*//'

Next is a script called to set the source of the DS:

curl -X POST -d @${2} $1/Ds/Product/control --header "Content-Type:text/xml" --header "Accept:text/xml" --header ""

This takes in 2 parameters, the first is the IP address of the device you want to control and the second is a file containing an XML body containing details of which source to set on the device, in this case, it is the radio function (source Id 1):

<?xml version="1.0"?>
<s:Envelope xmlns:s="">
  <s:Body s:encodingStyle="">
    <u:SetSourceIndex xmlns:u="">

Finally it's all put together in the following script. Set the SCRIPTS property to where you've saved the files above. Set the UUID property to the UUID of your DS - you'll need to scan your network to find this. In Windows, my DSs appear in the network view of Windows Explorer and I can see the unique identifier (UUID) if I right click the DS and view properties.


Now just add it to your crontab:
45 6 * * 1-5 /home/barry/scripts/

Enjoy one less thing to do in the morning :)

Here's the api documentation for the DS: