Home PageSqueezebox

Squeezebox

You can use the arduino with a wifi shield to talk to a squeezebox. It is possible to set the display and also make the arduino operate the unit for instance changing station.

Trileet already demonstrated the principle using a wired ethernet shield which he operated using RFID. Really cool. I have done the same thing using a wireless wifi shield from asynclabs. I used a Violet Mirror and a USB shield from circuitsonline to get the RFID card number. Depending on this number an action could then be innitiated. Ok so lets describe how this was done in steps. The first step is to be able to control the squeezebox from the browser window. Later on this same instruction will be used by the get command in the arduino program. You have many commands available so please read the instructions found on the logitech media server help.

Squeezebox commands

http://192.168.0.107:9002/status.txt  This displays current status.
Now Playing
The Sunset Mix

http://192.168.0.107:9002/status.txt?command=playlist&subcommand=loadtracks&trackid=1833
This plays track 1833 from your music collection

http://192.168.0.107:9002/plugins/Favorites/index.html?action=play&index=0
Plays from your favourites the first entry

http://192.168.0.107:9002/status.txt?p0=playlist&p1=play&p2=http://192.168.0.107/tuner/Mousse%20T%20-%20Horny.mp3
Play track stored on server

http://192.168.0.107:9002/status.txt?p0=display&p1=(c)B.Kasteel&p2=super%20this%20works&p3=20
This displays the text on the two lines for 20 seconds then reverts back to the original display

http://192.168.0.107:9002/status.html?p0=button&p1=play
Play what was playing (other command= STOP)

http://192.168.0.107:9002/status.html?p0=mixer&p1=volume&p2=20
Change volume absolute or relative

So you see that there are many different types of commands that can be used. Each command can be linked to a particular RFID tag later on. The main ones might be play a certain radio station or song. Obviously the localhost needs to be found for your setup. Change the 192.168.0.107 accordingly.

The following is a summary of the supported commands. Additional information about the command set is available in the Logitech Media Server Command Line Interface documentation.

squeezebox-2

Now that we have control over the squeezebox we need to drive the commands through a PHP program. This PHP program later on interprets the codes that will be sent from the arduino program and translates it into the commandes required by the squeezebox. These commands can be twofold at this stage.  http://192.168.0.107/tuner/index3.php?key=1045236790 is one type which when typed into the browser executes an instruction as if a tag with number 1045236790 has been seen by the RFID reader. The other instruction is http://192.168.0.107/tuner/index3.php?stop=1 which stops the player. Once the PHP program is installed at the right location you can type in these two commands into your browser and the instructions will be carried out. Of course the PHP program needs to have the right name and be in the right directory. In my example its the tuner directory and the program is called index3.php. Below you can see what this looks like when executed.
First all the commands that can be found are printed out. Then some info what the program is doing. These are for debugging and can be removed from the final program. Finally there is a table which is how you program the keys. This is done by editing the text string in the textbox.  The text should be the same as an instruction that worked before when typing it directly into the browser window. When the correct command is ready you press the appropriate update button which updates the key. Whe you later on are using the program as intended, when you scan a new RFID code it will automatically generate a new row in the table. The keys are stored in special files which are are named RFID code dot key. In this case for example 1045236791.key. They contain only the string command as seen in the text box as a text file. so for instance:
http://192.168.0.107:9002/status.html?p0=playlist&p1=play&p2=http://192.168.0.107/tuner/Mousse%20T%20-%20Horny.mp3&player=00:04:20:1e:1d:52

squeezebox-1

There is one other file needed and this is called last. This file simply contains the last RFID code found. so for instance 1045236790.
The PHP program you can view below.

Show »

<?php
# read in all our unique keys
$keys = array();
print “</pre>n”;
$files = scandir(‘.’);
foreach($files as $file){
if (preg_match(‘/(.*).key$/’, $file, $groups)){
$contents = file_get_contents($file);
$key = $groups[1];
$keys[$key] = $contents;
print “$key $contents”;
echo”<br>”;
}
}
echo”<br>”;
print “<b>all files read….</b>”;
echo”<br>”;
# see if this is a request to stop
if (isset($_GET['stop'])){
file_get_contents(“http://192.168.0.107:9002/status.html?p0=stop&player=00%3A04%3A20%3A1e%3A1d%3A52″);
print”Come here to stop “;
echo”<br>”;
}
# see if we have a key parameter passed in
if (isset($_GET['key'])){
$key = $_GET['key'];
# output this as our last key
file_put_contents(“last”, $key);
print”<b>Found that the last key was </b>”;
print”<b>$key</b>”;
echo”<br>”;
# add the key file if it isn’t already present
if (!isset($keys[$key]) && strlen($key) > 0){
// add the file
touch($key . “.key”);
$keys[$key] = “”;
print “Come here to add key “;
echo”<br>”;
}
# set the url if one is passed in
if (isset($_GET['url'])){
print “<b>URL has been passed in </b>”;
echo”<br>”;
$url = $_GET['url'];
print “<b>URL= $url</b>”;
echo”<br>”;
file_put_contents($key . “.key”, $url);
$keys[$key] = $url;
$website = file_get_contents(“http://192.168.0.107:9002/status.html”);
print (“$website”);
}
# no url? then this is a request to go hit that url
else if (strlen($key) > 0){
$url = $keys[$key];
print “<b>HIT URL= $url</b>”;
echo”<br>”;
# this gets the url by hand
$content = file_get_contents($url);
print(“<b>Fetched url for key: $key</b><br>”);
}
}
# read our last key
$last = file_get_contents(“last”);
print (“<b>Reading last key $last</b>”);
echo”<br>”;
?>
<table>
<?
foreach($keys as $key => $value){
?>
<tr>
<form action=”index3.php”>
<input type=”hidden” name=”key” value=”<?= $key ?>” />
<td
<? if (strcmp($last, $key) == 0){
print(“bgcolor=’green’”);
}
?>
><code><?= $key ?></code></td>
<td><input name=”url” type=”text” size=”160″ value=”<?= $value ?>” /></td>
<td><input type=”submit” value=”update”/></td>
</form>
</tr>
<?
}
?>

Ok so now we can command the squeezebox by typing in a command like http://192.168.0.107/tuner/index3.php?key=1045236790 into the browser.
Now we must read the RFID code needed and send this to this page. This is where the arduino comes in. The arduino has a wifi shield which is used to do the transmission to the server which has the PHP program on it.
The  arduino should therefore be on the same network as this PHP program.
Reading the RFID code itself is done by the Violet Mir:ror but basically any RFID reader could be used. The Violet Mir:ror is a USB RFID reader so you also need the usb host shield from circuitsonline to read the data coming from it. There is an article  http://arduino-projects4u.com/violet-mirror/ exactly how this works.
The wifi shield is also described on the site as is some basic software on how it can work.
So now all the components have been tested separately and all we need to do is make the whole thing work together.

Still to come.

 

I read somewhere that you could embed commands in a HTML file using iframe. I have not tested this but this is what it said.
<iframe src=”http://localhost:9000/status.txt?p0=display&p1=%title%&p2=%text%&p3=20″ height=”0″ width=”0″ frameborder=”0″ scrolling=”no”/>

Leave a Reply