Sonntag, 10. Februar 2013

10. The RadioCard as a "Station button"

Sometimes it's annoying to select his favorite station. Admittedly favorites help a lot. So we're back to the WAF (see blog dated 01/01/13). Navigating, probably  through a large directory tree (because everything is sorted so beautiful :-) ), is sometimes more than a nuisance. Here comes the RadioCard into the breach. Put a RadioCard on the desk and and your favourite radiostation starts playing.

Let's have a look at the SW part. Upon testing the RFID-Card that no DeviceCard is present, it must be one of those cards, for which playlist has been deposited in a special directory.

if (deviceCard == 0)                 // If it is not a DeviceCard, the playliste can be called
{

  Serial.println("DeviceCard ist 0");
  // dsplRFID(macAdrTmp);            // may be activated by using an Arduino Mega
  playPlaylist(macAdrTmp);


That's it and and we can go to the subroutine (now we take the temporary MAC address with us). Here the subroutine in its full splendor:

void playPlaylist(byte* macAdrTmp)
{
snprintf(SBox, 150, "GET /status?p0=playlist&p1=resume&p2=%d-%d-%d-%d-%d&player=%02x:%02x:%02x:%02x:%02x:%02x HTTP/1.1", serNum[0], serNum[1], serNum[2], serNum[3], serNum[4], macAdrTmp[0], macAdrTmp[1], macAdrTmp[2], macAdrTmp[3], macAdrTmp[4], macAdrTmp[5]);
  Serial.println(SBox);
  client.stop();
  Serial.println();
  Serial.println("client stopped");
  client.connect(server,9002);
  delay(1000);
  Serial.println(F("connecting..."));
  if (client.connected())
    {
      Serial.println(F("connected"));
      while (client.available())
      {
        char c = client.read();
      }
    Serial.println(SBox);
    client.println(SBox); //Squeezeplay
    client.println();
    Serial.println(F("abgesetzt"));
    }
   
  else
    {
    Serial.println(F("connection failed"));
    }
    Serial.println(F("Serverdaten lesen"));

  if (!client.connected())
    {
    Serial.println();
    Serial.println(F("disconnecting."));
    client.stop();
    }

}


That which here is sent to the server, is probably familiar only the transmitted parameters are different.

Now the following string will be sent (for example)
? GET / status p0=playlist & p1=resume & p2=254-122-179-209-230 & player=00:15:af:b8:ac:25 HTTP/1.1


Short explanation:
p0=playlist means, that a playlist should be played
p1=resume means that a current playlist will be canceled and will be replaced by the playlist decribed under
p2= filename of the playlist without extension

The playlist with the filname under p2 has to exist with the extension  .m3u in a dirctory that is defindes in the LMS. On this place the hyphens between the UID values ​​are generated. The command playlist knows a lot more parameters. Here again we refer to the Command Line Interface (CLI). See yesterday (9.). On the server there is a directory music / playlists  where the playlist 254-122-179-209-230.m3u   "lives" with the content:

#EXTM3U
http://opml.radiotime.com/Tune.ashx?id=s96815&formats=aac,ogg,mp3,wmpro&partnerId=16&serial=158f087abcf88503358ccf826d66a5b0

Here we deal with an extended M3U-playlist. This is a quote from German-Wiki translated into english language (http://de.wikipedia.org/wiki/M3U).

The first line # EXTM3U is the introduction of the head data and specifies the format of M3U's. In extended M3U''s you always find the first line # EXTM3U is  in use. The first line is followed by the actual content of the M3U . Each media  listed in the M3U-file consits two lines:
  • The 1st Line always begins with # EXTINF: , followed by the length of the media file in whole seconds. After the length of a comma is used as a separator, followed by the name of the media file, which is used for display in the media player. If the length specified is less than the actual length, as in PLS format the specified length is not observed. (Putting the length to -1, it is also not considered.)
  • The 2nd Line is identical to the specification of simple M3U's. Here is the full file name listed with absolute or relative path or URL to a specified file on a Webserver.
So we start to tinker a play list for the friends of WDR4 (german radio, not my favourite) . A new RFID card will simply read with the Arduino Serial Monitor that is open. There the command in its complete form shown:
GET / status p0 = playlist & p1 = p2 = & resume?
238-8-172-209-155 & player = 00:15: af: b8: ac: 25 HTTP/1.1
So must the name of the playlist must be: 238-8-172-209-155.m3u . Therefore we need a blank document, which we generate an editor. Into this document we write we write the both first lines:

  #EXTM3U
  #EXTINF: -1,


Now we need the link to the external stream. There are links with and without station logo. The best link is still generated by the LMS. For this purpose we are looking for the radio station WDR4 at the Squeezedevice Radio and add the station to the Favorites. If we now go into the LMS and there select the Home - Favorites. Click and select WDR4.  Click. Now you can see the following picture:




We paste the link from the clipboard into our document. Finally, at 238-8-172-209-155.m3u folder music / playlists /  save and READY! After placing the RadioCard on the Duinosqueeze it shows the SqueezePlay player with the following screen:



Next time it comes to the CDCard . We look at how the playlists can be generated quickly from the music-database.