Freitag, 8. Februar 2013

8. Software Settings and the Device Card

The software is downloadable at Google.code. Here is the


The software is a functional version that need to be adjusted in some respects to your own needs. If you have problems, dicovered errors or improvements you should  drop me a line.

The general query of a RFID-card is very simple because of the downloadable Adafruit-Sketch (link already blogged).Now let's have a lokk to the controlling of Squeezedevices and the cooperation with the Logitech Media Server = LMS (formerly SqueezeCenter).

Fundamentals
All media devices of the Squeezegroup need for playing music content the support of a server. This is either the server on the internet (mysqueezbox.com) or as in my case, the LMS that runs on a device in the home network. individual devices have a server in the internal software (Squeezebox Touch).

I consider only the LMS variant in the local network . The most commonly used mode of operation is likely the individual control.


Individual Controlling of Squeeze-devices

Each player will be individually controlled by the LMS. To keep its individuality, is required for an RFID-control in the network, to tell the server to which device  the following command(s) are intended. This message to the LMS, which target device is desired, takes over the DeviceCard  .

If there is a single control system, there must be a group control system. Via the setup of the Squeeze-devices you can form individual groups or switch all devices logically together. The group formation can not be made ​​with this software!   Unfortunately there is not enough capacity in the memory of the Arduino.  



Group Controlling of Squeeze-devices

All actions on a device within a group affect every other out in the same way! I like calling the group-controlling as Party Mode. In all rooms the same music!

Once all devices run into control group, it is irrelevant which device is passed to the data stream. It affects all devices anyway. So you can save the DeviceCard.

The software:
I describe the SW in that substantial parts that are project-specific

// ***** Squeezebox-Settings *****
uchar serNum[5]; // Serial Number of the RFID-Card 
char namTmp[20]="SB%20Touch PC";  // device-name with default
char SBox[150]; // character arry for the message to the server
boolean deviceCard = 0; // Flag, if DeviceCard
 

In this part memory areas for specific content are reserved . I do not work with strings, because of the uncontrolled assignment of memoryspace. On my place that led me to the fact, that sometimes the sketch aborted. So I switched with the help of the German forum to the char-array. Now the locations shown above are "filled" targeted.


// + + + + + + + + + + + + + + + + + + + + + + + + + + + For information + + + + + + + + + + + + + + + + + + + + + + + + + + + +
/**** devices card IDs under which the devices are accessed ****
* const uchar Squeezebox01 [5] = {110,190,163,209,162} // = Squeezebox1 SBClassic livingroom

* const uchar Squeezebox02 [5] = {222,225,153,209,119} // = Squeezebox2 SBClassic kitchen
*
const uchar Squeezebox03 [5] = {30,211,170,209,182} // = Squeezebox3 SBTouch
*
const uchar SqueezeplayPC [5] = {94,111,152,209,120} // = Squeezebox4 SBTouch PC (Squeezeplay)
* const uchar SqueezeplayMAC [5] = {158,29,168,209,250
} // = Squeezebox5 SBTouchMAC (Squeezeplay)
* const uchar SoftsqueezePC [5] = {222,91,164,209,240} // = Squeezebox6 SBClassic PC (Softsqueeze)
* const uchar iPengIPOD [5] = {142,72,165,209,178} // = Squeezebox7 SBiPeng (iPOD) */



In this area, all the UID/CS for the Squeeze-devices are listed informative. You can delete, if you want.
 


//**2-dimensional array for alle Squeezeboxes (Devicecards)
const uchar Squeezebox[7][5]= {
  {110,190,163,209,162},
  {222,225,153,209,119},
  {30,211,170,209,182},
  {94,111,152,209,120},
  {158,29,168,209,250},
  {222,91,164,209,240},
  {142,72,165,209,178}   };


There is a request in the program, where is checked the if detected Card is a DeviceCard. For this purpose, all the UID of the DeviceCards has to be known.

//**2-dimensional  array for alle Mac-adresses
byte macAdrSbox[7][6]={
{0x00,0x04,0x20,0x12,0xde,0x14},
{0x00,0x04,0x20,0x12,0xdc,0x55},
{0x00,0x04,0x20,0x23,0x72,0x16},
{0x00,0x04,0x20,0xb8,0xac,0x25},
{0x00,0x04,0x20,0x0b,0x59,0x2d},
{0x00,0x04,0x20,0xd8,0xae,0xce},
{0x00,0x04,0x20,0x89,0xc4,0x87} };

 

The command to the Logitech Media Server contains the target address of the selected Squeezebox. This address must be set up in the software. Therefore there is always a default adress selected. That is the reason why I always choose a default-Squeezebox.

// +++++++++++++++++++++++++ Einstellen des aktuellen Default-Wertes ++++++++++++++++++++++++
//byte macAdrTmp[6]= {0x00,0x04,0x20,0x12,0xde,0x14}; //default SBClassic Wohnzimmer
//byte macAdrTmp[6]= {0x00,0x04,0x20,0x12,0xdc,0x55}; //default SBClassic Küche
byte macAdrTmp[6]= {0x00,0x04,0x20,0x23,0x72,0x16}; //default SBTouch
//byte macAdrTmp[6]= {0x00,0x15,0xaf,0xb8,0xac,0x25}; //default SBTouch PC (Squeezeplay)
//byte macAdrTmp[6]= {0x00,0x04,0x20,0x23,0x72,0x16}; //default SBTouch MAC (Squeezeplay)
//byte macAdrTmp[6]= {0x00,0x04,0x20,0x23,0x72,0x16}; //default SBClassic PC (Softsqueeze)
//byte macAdrTmp[6]= {0x00,0x04,0x20,0x23,0x72,0x16}; //default SBiPeng (iPod)

 

So is it easier, I've listed all possibilities in advance , from which I choose one. For my tests, the test was very helpful.
 

/ / ** 2-dimensional array of the names of Squeeezegeräte name
/ / this can not exceed 18 characters! Otherwise change!

char namSbox[7][18]={
  {"SB-Classic%20(WZ)"},
  {"SB-Classic%20(KU)"},
  {"SB-Touch"},
  {"SB-Touch%20PC"},
  {"SB-Touch%20Mac"},
  {"SB-Classic%20PC"},
  {"SB-iPeng%20iPOD"}   };



If the stream was diverted to another Squeezebox device, a message is generated for the new device, the data stream it f was diverted olgreich. How this is done I will show you later.


Message on SB-Touch PC :
"RFID Controlling has been rerouted to SB-Touch PC sucessfully"

Message on SB Classic PC:
"RFID Controlling has been rerouted to SB-Classic PC sucessfully"


The pictures show the software versions of the SB Touch and the SB Classic. Next time we have a look onto the code snippet, which is responsible for this message.

Donnerstag, 7. Februar 2013

7. Inside the RadioCard

Now I've wired my board. As you can see, it was really no big deal. Not pretty, but functional. For additional plug the hole grid is perfect to use.





Unfortunately, blurred















Now quickly connected to the Arduino and let's go for the first test. I have previously downloaded the files from github and put the files in the folder C: \ arduino \ arduino-1.0.3 \ libraries . I want to show me a hex dump of the 1K memory on the card. Therefore I loaded the sketch mifareclassic_memdump.pde to the Arduino. Our RadioCard placed near the RFID-board and already the Arduino starts working!

My RFID board lives!
The Serial Monitor shows the following result:


This looks very good! All HEX values ​​:-( . But I was longing for decimal numbers. But step by step. My Mifare S50 card has a 1K memory and is divided into 16 sectors (0-15) Each sector. has 4 blocks of 16 bytes (0-15). If we calculate:


16 sectors * 4 blocks * 16 bytes = 1024 bytes = 1KByte
In the picture above I only displayed the first four sectors, the remaining 12 blocks look the same - promised! The sector "0" is a special one. it containes the block "0", which belongs to the manufacturer. The first four bytes of the UID (here: FE 48 98 D1) followed by the checksum (here: FF). This is exactly the information that needs to be tinkered it to my playlist number. If I convert the hex values ​​FF FE 48 98 D1 to decimal values, I get:

 
254 72 152 209 255  ... and that is very familiar to me! The Radio Card !


Mittwoch, 6. Februar 2013

6. The PCB layout of ID: 789

The previous day, I left with a reference to the .brd file. The .brd file has nothing to do with the Bunderepublik Deutschland but shows the layout of the board. Here's an overview:


Copyright Adafruit

Along with the .sch file you can find all the relevant points on the board. The .brd file includes all components, names, even those that are not printed on the shield. I summarized all major components and platinum points in the following image.


In general I can say: There are enough ways available to connect the board to whatever. It is well recognized that many inputs and outputs are not used, but only because to make the board stackable. For those who use the board as a shield , it's really plug 'n play. But those who wants "outsource" the shield -like me- it would be necessary to deal with the pinout.

On the photo it looks like you have four solder points to connect ground (Gnd). Really four? Let's have a look at the layout. Wow! Only one single platinum point is possible to use. That's exactly what I said yesterday: A look at the layout is worth it!

Short explanation to the yellow boxes:
Q1 = level converter SDA
Q2 = level converter SCL
Q3 = level converter SCK
Q4 = level converter RSTP
FSR = Voltage regulator 5V/3.3V
IRQ = Connected to an LED, showing the status of the interrupt (IRQ)  

The green lines represent the two lines SDA and SCL They can be picked up at five different points:  
SDA: Top left 2x (SDA), MOSI (separate power strip), and the bottom right 2x (Analog In 4)
SCL: Top right 2x (SCL), SS (SPI socket) and the bottom right 2x (Analog In 5)  

The yellow lines are the points that I will connect to a 5-pin male header.

Next, it the blog goes on with the " Wiring" and the first test run.

<= one step back                                                                                             go ahead =>

Dienstag, 5. Februar 2013

5. Sound the RFID-card out

And so I have bought the following RFID-card : Adafruit ID:789. As it should be, I first checked out what is available for it at Adafruit. In this moment I'm only interested in hardware-informations.  In the data specifications you can find several tabs. Let's have a look one after another:

Tab "Description"
Here you can find descriptions and valuable information on the structure of the board. Those who intend to use the SPI interfacesghoul read those informations. In short: Reading required  

Tab "Technical Details"
Only showing the size specification is IMHO definitely a little poor. I had always expected data on power consumption in different states. What voltages are / can be used? Sorry, no answers.  

Tab "Tutorials"

  • Very good additional information about RFID. Here I was able to find more in-depth data of the RFID card, which I will use. I use Mifare S50 Classic - cards. In that document there is more to find. Really worth reading!
  • Since I will not use the function of NFC phones and I have not looked in there ', I can not judging this point.
  • The other information are data sheets and time charts. The data sheets can answer many questions, if you don't know how to go on.I come back again to the data sheets
"Download"
Here I have been led on a false trail. At this point you have to be extremely careful!

The links to the libraries guide us to the required I2C-sketches. I will try them at a later date.

The antenna design is based on the use of the RFID chip from NXP PN532. This one is used on my board. So far ok

It is said that the schematic diagram will follow later, but there is a link that works - and point on the diagram of the breakout boards (ID: 364) ! I have not noticed it right away, and asked me how it is with the power supply and the levels on the inputs and outputs. The data sheet tells me that the max. voltage is 3.6 V. Input and output levels are at 3.3V. The question Is: How can I adjust the voltage? The tutorail shows namely the breakout board with an additional level adjustment. Do I need it? Then I searched the forum at Adafruit and had been successful. In a post dated 11/13/2012 someone asks for a diagram of the NFC Shield. In response, there is a link to github, where there is among others a *.brd and a *.sch file. What the hell I have to/can do with the file? The program associated with this format is called eagle and is available in the Internet for download. During installation, you can choose a free version with limited options (eagle-light). And then I see in the diagram (*.sch file) what I need:



Copyright Adafruit
Both lines the SDA and the SCL have ever used a level shifter. The IRQ line, does not require a level converter, as it is an output of the RFID-board and the input of the Arduino will work properly with this voltage. The same question what to do with the 3.3V supply voltage is cleared by the diagram:


Copyright Adafruit
The Shield has a fixed voltage contrller "onboard". It converts the 5V into the necessary 3.3V.  

Therefore the board has everything my heart desires!

But where is what on the board? This time tomorrow I'll have look at the *. brd file.


Montag, 4. Februar 2013

4. The guts of the DuinoSqueeze

In the overview diagram of yesterday, I listed the required modules. In the following picture you can see them in all its glory.

From the left: The Ethernet Shield, the Arduino Uno and the RFID-card


The Arduino Uno
To this module it is to say the least because this is the best known on the net. I purchased my Uno from China and it works properly me until now. I'm still thinking about whether or not it should give way to a lack of space to a Nano. I would suggest that we decide this at a later date, when the DuinoSqueeze runs.

The Ethernet Shield
As well a board from China. The most famous two Ethernet Shields have either the ENC28J60 or WIZnet W5100 chip installed. I opted for the Wiznet-variant, because it is easier to handle. The Shield will be mounted piggyback on the Arduino. Arduino and the Ethernet-shield operates together via the SPI interface.

The RFID Shield 
I do not intend to use the RFID-reader piggyback, but slightly offset from the other electronics. The reasons are alone in optics. The electronics and the I will hide in the closet somewhere. So definitely an interface is to be used, which allows such a remote operation. There I decided to use the I2C interface. So I need a board / shield which uses this interface. The assortment of shilds with a I2C-Interface is not really abundant. If man / woman still needs a reading distance of at least 5 cm, the antenna size is already playing a major role.   So I ultimately decided on the RFID-board of Adafruit (ID: 789) . The board is delivered already prepared for the I2C interface using the Arduino ports . 

So as to avoid collisions on the ports between the the shields/boards, you should plan the using of the ports carefully.  
 
The SPI-interface is natively using the following pins:  
MOSI ( M aster O ut / S lave I n) pin D11 (fixed)  
MISO ( M aster I n / S lave O ut) pin D12 (not changeable)

SCK (Slave Clock) pin D13 (fixed)
SS / CS ( S lave S elect or C hip S elect) Pin Dx (changeable)

The I2C interface of the reader consists of:

 
SDA (serial data),
SCL (serial clock)  


In addition to the ports above we use  the IRQ (interrupt). It does not belong to the I2C interface.

The following table shows the proposed pinout:


Dx = Digital I / O, Ax = Analog I / O

Who is interested in more profound information of the  SPI and I2C interface, should have a look at the  this german seminar .

All devices on the I2C bus must have a unique address by which they can be identified and addressed on the bus. It would be important to know what address has the RFID reader. We'll do that later. There are so-called sniffer (sniffer).

Next time we look at the RFID board and have closer look to the inner life. Now you could say "unimportant", but it isn't as unimportant as you think .

Sonntag, 3. Februar 2013

3. The RadioCard plays the music

Today I would like to explain you the intended mode of operation by means of the following diagram:

Overview diagram of the home network for DuinoSqueeze

First I will explain you the sequence of operation which a RadioCard represents. The RadioCard has a UID incl check sum (CS), as we we met short time ago:

254 72 152 209 255

Behind this card hides the Internet Radio Channel  MemoryhitsFM . So here we go

  1. The RFID reader will detect the card and sends the UID as a string 25472152209255 to the Arduino.
  2. The Arduino stores the UID and CS internally as a variable.
  3. The Arduino converts the string 25472152209255 into 254-72-152-209-255 . This string is our desired playlist number (PL-No.)!
  4. The Arduino now has a PL-No, to send it via Ethernet Shield to the music server: Logitech Media Server (formerly SqueezeCenter) . Where is the graph of the Logitech Media Server ? The Logitech Media Server "lives" in my home network to the NAS Synology 409 +. If you google the term Logitech Media Server, surely you will find a free version for Windows or Linux.
  5. The Logitech Media Server (from now on LMS) manages the communication to the connected media players- in the graph, the Squeezebox Touch and Squeezebox Classic (SB3).
  6. LMS checks, whether there is a playlist called 254-72-152-209-255.m3u in the database. Finding the right LMS Playlist, it sends the data stream to one or more players.
This is the simple operation of a RadioCard . The function of a CDCard or PlaylistCard is dealt in principle identical. Only the contents of the playlists are different. That is, when it is used, explained in more details.

In the Playlist 254-72-152-209-255.m3u you see (only) the following text:

#EXTM3U
#EXTINF: -1, - Memory Hits FM, DE
http:// www.surfmusik.de/m3u/memoryhits-fm, 13851.m3u

This playlist is created by me "by hand". For any other internet radio channel, the RadioCard works on the same principle.

This is all, to play the internet music!

In addition, there is a DeviceCard, with, if necessary, you may route the above data stream to other Squeezeboxes.

Samstag, 2. Februar 2013

2. What the German Football Club ‘Dynamo Dresden’ has to do with the project

Dynamo Dresden? Yes! Dynamo Dresden is a German football club. This club ordered every year its annual entrance cards at a Distributer of its confidence. That was the same in the season 2011/2012. The Distributer had printed the RFID-based annual cards. But unfortunately, all the cards were printed incorrectly. Lots of RFID cards, which were waiting for a new assignment. By chance (you also have to get lucky in life) I now could purchase the required number of tickets for a good price. Although the cards were printed, they were technically in a perfect condition. Just as new!



Basically one word to the cards. These cards are no season tickets! The club Dynamo Dresden make them to what they should be. I have only the pure cards! They are personalized at Dynamo Dresden and there the cards get their datas. No unauthorized people can have access to the datas.

The cards do have a memory of 1KByte. Two different passwords are there to protect the contents. Without those keys you do not have any access to the contents. In a "virgin" card that's different. They are equipped with a so-called transport code, that is well known and is "FF FF FF FF FF FF". These transport codes can be overridden with new specific passwords, if required. My application does not need specific security requirements, so I will use the card exclusively with the transport code.

Additionally to the two possible passwords each card has its own "ID", the UID Number (UID = U nique ID entification). This consists of four bytes and a check sum. Since it is stored on a card in binary, it is in its present form not reasonable to use. So either I will use in the UID in HEX numbers or decimal values. I opted for the decimal version. So I have 4 numbers in between the number range of 0-255. Among the four numerical UID values the check value will still join, which also will be read out. Here is an example of an RFID card UID: 254 72 152 209 255 .

Such digits sequences will meet us again in the future.

Freitag, 1. Februar 2013

1. Off we go or the WAF



Today I decided to create a blog of my project. If it works I do not know. The first few days are a test object. They are also used to test the settings of the blog.



Every reader wonders rightly: Why the umpteen-millionth blog. The blog is not for me but for everyone out there who are doing it as well as me. I have (or had) to fight in my project with many uncertainties, of which I would like to preserve the interested reader.



What is this blog about?



Projects always arise when man / woman think anything could be simpler or more beautiful as today. As a music lover I have scattered around my home media player the variety squeezebox-euipment. These are: two classic Squeezebox 3 one Squeezebox Touch ,  two Squeezplay on PCs with the operating systems Windows and OSX. Concluding an iPhone and an iPod together with the controller / player iPeng .



This all is easy to handle for me, who set up the whole hardware to use. Only the wife of the home will not operate the squeezeboxes, but listen - and that as simple as possible. This is admittedly not the case, and so the wonderful devices are easily viewed from my wife very suspicious.



To make a long story short: The WAF is, on the open-topped popularity scale, on carpet level (ie at the bottom). The WAF is the W omens- A cceptance- F actor. Apparently the WAF seems to be inversely proportional to the male enthusiasm with technical innovations.



Back to the topic.



Based on this Youtube video https://www.youtube.com/watch?v=m-0Zj8fJz8U   where the documentation was not really to find. I'm aiming to develop my own non-contact control , not only to play all my CD's, but also forall the  internet radio stations,. The basis are small RFID transponders in card form, whose information is read and performs, depending on  the found information, specific activities.



Requirements for the RFID control:

Play all CDs by CDCards

Playing playlists by PlaylistCards

Target selection of streaming through the use of so-called DeviceCards

Direct selection of Internet radio stations by RadioCards



... and the next time the function is illustrated and explained what the German Football Club Dynamo Dresden has to do with my project.


Samstag, 12. Januar 2013

12. Eine neue DeviceCard wird hinzugefügt


Ich habe von einem lieben Menschen ein etwas älteres IPhone geschenkt bekommen. Mit iPeng wird es zum vollwertigen Squeezedevice. Das wollen wir dem Programm nun hinzufügen.

Achtung: ich habe lange daran gerätselt, warum die Gerätekarte nicht funktioniert. Bei der Fehlersuche hat mir das Squeezeforum (deutsch), inbesondere pippin sehr geholfen. Hier noch einmal meinen herzlichen Dank. 

Folgendes ist grundsätzlich zu beachten: Alles nachfolgend Beschriebenes funktioniert nur, wenn bei iPeng das ausgewählte Gerät der Master ist!!! Das bedeutet, dass der Name des Gerätes oben angezeigt werden muss. Siehe nachfolgendes Bild.



1. Schritt: Das IPhone bekommt einen Namen
Wir müssen dem iPhone einen Namen geben, da wir eine Bestätigung auf das Display schreiben werden, dass der Datenstrom erfolgreich umgeleitet wurde. Ich werde werde es SB-iPhone nennen.


2. Schritt: Das 2-dimensionale Array wird angepasst
Das 2-dimensionale Array im Programm muss angepasst weren und muss nachher wie folgt aussehen. Die blaue Schrift markiert die Änderungen:


//**2-dimensionales Array der Namen der Squeeezegeräte-Namen
char namSbox[8][18]={             // von 7 nach 8 verändert
{"SB-Classic%2001"},
{"SB-Classic%2002"},
{"SB-Touch"},
{"SB-Touch%20PC"},
{"SB-Touch%20Mac"},
{"SB-Classic%20PC"},
{"SB-iPod"},
{"SB-iPhone"} };                  // hinzugefügt


3. Schritt: Die Mac-Adresse des iPhones
Wir benötigen aus dem iPhone die Mac-Adresse. Die gibt es unter Einstellungen-Allgemein-Info-WLAN-Adresse. Meine lautet: 64:B9:E8:28:23:9A, und die tragen wir jetzt in das Programm ein:


//**2-dimensionales Array für alle Mac-Adressen
byte macAdrSbox[8][6]={
{0x00,0x04,0x20,0x12,0xde,0x14},
{0x00,0x04,0x20,0x12,0xdc,0x55},
{0x00,0x04,0x20,0x23,0x72,0x16},
{0x00,0x15,0xaf,0xb8,0xac,0x25},
{0x00,0x26,0xbb,0x0b,0x59,0x2d},
{0xe3,0xf8,0xd4,0xd8,0xae,0xce},
{0x00,0x24,0x36,0x89,0xc4,0x87},
{0x64,0xB9,0xE8,0x28,0x23,0x9A} };


4.Schritt: Die DeviceCard einbinden
Ich habe immer einige RFID-Karten vorrätig, bei denen die UID/PZ schon ausgelesen sind. Davon wähle ich nun die Karte 62-222-174-209-159 und die binden wir nun in dei Software ein.


//**2-dimensionales Array für alle Squeezeboxen (Gerätekarten)
const uchar Squeezebox[8][5]= {
  {110,190,163,209,162},
  {222,225,153,209,119},
  {30,211,170,209,182},
  {94,111,152,209,120},
  {158,29,168,209,250},
  {222,91,164,209,240},
  {142,72,165,209,178},
  {62,222,174,209,159}   };

War es das schon? Nein im Programm muss noch etwas geändert werden:


5. Schritt: Programmänderungen
Es gibt in der loop eine while Schleife, die alle UID/PZ der bekannten DeviceCards abfragt.Die Menge war bisher "7". Das muss in "8" geändert werden.

 while( i<8)            // es werden 8 DeviceCards überprüft
{
  if (memcmp(Squeezebox[i],serNum,5)==0) //Wenn eine DeviceCard gefunden wurde
  {
    memcpy(namTmp,namSbox[i],18);        // Der Name der SBox wird in eine temporäre Variable geschrieben


6.Schritt:  Software aktualisieren
Das sollte jeder können, deshalb: kein Kommentar :-)


7. Schritt: Der Test
Es ist zu beachten, dass die Software wiederholtes Auflegen der gleichen Karte nicht auswertet! Das bedeutet, wenn man die Funktion wiederholt testen möchte, muss man eine andere RFID-Karte zwischendurch auswerten lassen. Wenn alles richtig gemachte wurde, wird nach dem Auflegen der DeviceCard vom SB-iPhone folgende Meldung angezeigt:



Durch die Software iPeng mit der Playerfunktion wird das iPone in einer Dockinstation zu einem vollwertigen Squeezedevice.

soweit für heute ... an dem beabsichtigten Video arbeite ich noch.

Freitag, 11. Januar 2013

11. Die CDCard - und die Playlist für Squeezebox

Als ich die ersten Versuche in diesem Projekt begonnen hatte, bestand das eigentliche Ziel daraus, einen schnellen Zugriff auf die Musik meiner CD's zu haben. Dass es sich so entwickelt hat, war mir auch nicht bewusst. Also wollen wir uns kurz der CDCard zuwenden.

Eigentlich ist die theoretische Seite klar: Wir benötigen eine erweiterte Playlist im Format .m3u . Wie die grundsätzlich auszusehen hat, haben wir gestern gesehen. Also grundsätzlich gibt es keine Probleme. Keine Probleme?? Die meisten Playlists von anderen Programmen sind nicht erweitert - sie funktionieren nicht. Also habe ich dafür ein funktionierendes Verfahren für mich vorgesehen. Ich möchte es an dieser Stelle für all diejenigen vorstellen, die mit der Playlist genauso kämpfen wie ich.

Ich gehe davon aus, dass das Rippen einer CD sehr wohl fast jedem bekannt ist. Zur Info: ich rippe mit Audiograbber. Die Files liegen danach im mp3-Format in einem speziellen CD-Ordner vor.

Ich habe diese Woche von meinem Heizöllieferanten eine CD "Après Ski Classics" geschenkt bekommen, die soll mir jetzt als Beispiel dienen.

Beim Grabben kann Audiograbber auch eine Playlist m3u erzeugen. Die sieht dann so aus - einfach arm:

01 - Tim Toupet - Du hast die Haare schön-1.mp3
02 - K2 - Der Berg ruft (Remix 2000).mp3
03 - Olaf Henning - Cowboy & Indianer (komm hol das Lasso raus).mp3
04 - Jürgen Drews - König an der Schneebar.mp3
05 - The BossHoss - Hey Ya!.mp3
06 - Peter Wackel - Après Ski.mp3
07 - Helmut Aus Mallorca - Der alte Holzmichel.mp3
08 - A-Teens - Gimme! Gimme! Gimme!.mp3
09 - Scooter - The Question is what is the Question.mp3
10 - Didi Diesel - I bin der Champ.mp3
11 - Henning & Holm - Maddalena 2001 (Du Luder).mp3
12 - Bata Illic - Michaela.mp3
13 - Sonthofen Allstars - Alles Wunderbar.mp3
14 - Cascada - Everytime we touch.mp3
15 - Hermes House Band - I will Survive (Radio Edit).mp3


Das ist definitiv kein erweitertes Format!!  Da lacht sich der LMS schlapp!!! Das geht besser.  Dazu benötigen wir das für mich beste Editier-Programm für MP3's - MP3Tag. Zum Zeitpunkt dieses Blogs mit Version 2.54. Die RFID-Karte ist schon identifiziert und hat die UID/PZ 78-12-179-209-32. Ich habe nun in die ID3-Tags ein neues Feld hinzugefügt: RFID-Karte.

MP3Tag mit den neuen Feldern EAN-Nummer und RFID-Karte


Wir benötigen dieses Feld später beim Export noch.

In MP3Tag gibt es unter Datei - Export die Möglichkeit, eine Exportdatei zu beschreiben. Mein Export heißt natürlich Squeezebox-Playlist (wie denn sonst). Die Syntax dafür lautet:

$filename(U:\playlists\%RFID_CARD%.m3u,utf-8)
#CURTRACK 0
#EXTM3U$loop(%track%)
#EXTURL:file:///volume1/music/$cutLeft($replace(%_path%,\,/, ,'%20'),3)
#EXTINF:%_length_seconds%,%title%
/volume1/music/$cutLeft($replace(%_path%,\,/),3)$loopend()


Da wir hier als Schwerpunkt definitiv nicht MP3Tag haben, nehmt es an und legt euch euren eigenen Export an. beim Export öffnet sich dieses Fenster. Wichtig ist, dass der Dateiname wie im Bild eingetragen wird. Dann holt sich das Programm automatisch die RFID-Nr. aus dem ID3-Tag. Wenn wir jetzt OK drücken bekommen wir DIE Playliste die wir benötigen und das im richtigen Ordner gespeichert. Toll!!

Die Playliste hat jetzt folgenden Inhalt:











#CURTRACK 0
#EXTM3U
#EXTURL:file:///volume1/music/Pop/Sampler/Après%20Ski%20Classics/01%20-%20Tim%20Toupet%20-%20Du%20hast%20die%20Haare%20schön.mp3
#EXTINF:223,Du hast die Haare schön
/volume1/music/Pop/Sampler/Après Ski Classics/01 - Tim Toupet - Du hast die Haare schön.mp3
#EXTURL:file:///volume1/music/Pop/Sampler/Après%20Ski%20Classics/02%20-%20K2%20-%20Der%20Berg%20ruft%20(Remix%202000).mp3
#EXTINF:236,Der Berg ruft (Remix 2000)
/volume1/music/Pop/Sampler/Après Ski Classics/02 - K2 - Der Berg ruft (Remix 2000).mp3
... usw,

Das sieht doch definitiv eher nach erweiterter Playlist aus - und funktioniert auch.

Hier liegt sie im Verzeichnis playlist mit all den Anderen.



Funktioniert????  Nein! Eine Fehlermeldung macht sich breit. Die kann ich heute gar nicht gebrauchen!!


Das liegt mit Sicherheit in dem Playlist-Script. Da fällt mir direkt auf:

#EXTURL:file:///volume1/music/Pop/Sampler/Après%20Ski%20Classics/01%20-%20Tim%20Toupet%20-%20Du%20hast%20die%20Haare%20schön.mp3

Im ersten Track ist ein deutsches Sonderzeichen enthalten. Und Sonderzeichen mag der LMS überhaupt nicht. Das "ö" macht Ärger!!

Im Script wird in derZeile

#EXTURL:file:///volume1/music/$cutLeft($replace(%_path%,\,/, ,'%20'),3)

in der ein "\" durch "/" und ein " " durch %20 ersetzt ($replace) wird, wie folgt geändert:

#EXTURL:file:///volume1/music/$cutLeft($replace(%_path%,\,/, ,'%20',ä,%C3%A4,ö,%C3%B6,ü,%C3%BC),3)


Die Fehlermeldung bleibt nun aus! Sollte es doch noch mal zu solchen Fehlermeldungen kommen müsst ihr in diesem Umfeld suchen!

Die RFID-Karte wird nun im CD-Cover versteckt und ist von außen nicht zu sehen.



Das habe ich mit allen meinen CD's gemacht: Gerippt - in der Datenbank gespeichert - RID-Karte vorbereitet - Playlist erzeugt und gespeichert - CDCard in CD-Cover versteckt. FERTIG!  Bei über 300 CD's keine Arbeit für einen Tag - das ziiiiieeeeeht sich! :-)  Das Ergebnis ist aber immer wieder eine Freude.

Ich hatte am Anfang gedacht, dass es irre lange dauert eine bestimmte Playlist in dieser Menge zu finden. Das Gegenteil ist der Fall! Dadurch, dass die Inhalte in einem Verzeichnis sortiert werden ist alles schön "durchnummeriert", Macht euch die Mühe, die UID und PZ auf die Karte zu schreiben! Das vereinfacht eine eventuelle Fehlersuche erheblich.

Wir gehen langsam auf die Zielgerade. Wie nun eine PlaylistCard gebaut wird, sollte nach den Durchlesen der letzten Blogs keine Schwierigkeiten mehr bereiten. Das überlasse ich euch! WEr dabei trotzdem noch Probleme hat, kann sich ja bei mir melden.

Das nächste Mal wollen wir das Ding im Einsatz sehen. Video? Mal sehen. Es wird definitiv etwas dauern.



Donnerstag, 10. Januar 2013

10. Die RadioCard als "Stationstaste"

Manchmal ist es schon lästig sich seine Lieblingsstation auszuwählen. Zugegebenermaßen helfen die Favoriten da erheblich.

Damit sind wir wieder beim WAF (siehe blog vom 07.01.13). Das Navigieren, wohlmöglich noch durch einen Verzeichnisbaum (weil alles so schön geordnet sein soll) ist manchmal mehr als lästig.

Hier soll die RadioCard einspringen. RadioCard auflegen und schon gibt's was auf die Ohren.

Schauen wir uns mal den SW-Teil an. Nachdem die Gerätekennung durchlaufen wurde und feststeht, dass keine DeviceCard vorliegt, muss es eine von den Karten sein, für die eine Playlist hinterlegt wurde.

if (steuerkarte == 0)
          {
          Serial.println(steuerkarte);
          // dsplRFID(macAdrTmp);
          playPlaylist(macAdrTmp);
          }


Das war es schon und ab in das Unterprogramm (nun nehmen wir aber die temporäre Mac-Adresse mit).

Hier das Unterprogramm in seiner kompletten Pracht:

void playPlaylist(byte* macAdrSbox)
{
  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], macAdrSbox[0], macAdrSbox[1], macAdrSbox[2], macAdrSbox[3], macAdrSbox[4], macAdrSbox[5]);
  client.stop();
  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);
    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();
    }
}


Das, was hier an den Server gesendet wird, ist wohlvertraut. Lediglich die gesendeten Parameter sehen anders aus.

Nun wird gesendet (Beispiel);
GET /status?p0=playlist&p1=resume&p2=254-122-179-209-230&player=00:15:af:b8:ac:25 HTTP/1.1

Kurze Erläuterung:
p0 = es soll eine playlist gespielt werden
p1 = resume bedeutet, dass eine aktuelle Playlist abgebrochen wird und durch die unter p2 ersetzt wird. Auf die Dateierweiterung wird verzichtet, muss aber als .m3u vorhanden sein

Erst hier werden die Bindestriche zwischen den einzelnen UID-Werten erzeugt,

Der Befehl playlist kennt jede Menge weitere Parameter. Hier sei wieder auf das Command Line Interface (CLI) verwiesen. Siehe gestern (9.).

Auf dem Server gibt es ein Verzeichnis music/playlists. Dort "wohnt" die Playliste 254-122-179-209-230.m3u   mit dem Inhalt:

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


Wir haben es hier auf jeden Fall mit einer erweiterten Playliste zu tun. Hierzu ein Zitat aus Wiki (http://de.wikipedia.org/wiki/M3U):

Die erste Zeile #EXTM3U ist die Einleitung der Kopfdaten und legt das Format der M3U fest, bei erweiterten M3Us ist immer als erste Zeile #EXTM3U zu verwenden.
Nach der ersten Zeile folgt der eigentliche Inhalt der M3U. Pro Mediendatei werden 2 Zeilen benötigt:

  • Die 1. Zeile beginnt immer mit #EXTINF:, danach folgt die Länge der Mediendatei in ganzen Sekunden. Nach der Länge wird ein Komma als Trennzeichen verwendet, danach folgt der Name der Mediendatei, welcher zur Anzeige im Medienspieler dient. Wenn die angegebene Länge kleiner als die tatsächliche Länge ist, wird wie beim PLS-Format die angegebene Länge nicht beachtet. (Setzt man die Länge auf −1, wird sie ebenfalls nicht beachtet.)
  • Die 2. Zeile ist identisch mit der Spezifikation von einfachen M3Us, hier wird der volle Dateiname mit absolutem oder relativem Pfad oder eine URL zu einer Datei auf einem Webserver angegeben
Also beginnen wir uns ein Playliste für die Freunde des WDR4 (not my favorite) zu basteln. Eine neue RFID-Karte wird einfach mit geöffnetem Serial Monitor des Arduino gelesen. Dort ist dann der Befehl in seiner kompletten Form zu sehen:

GET /status?p0=playlist&p1=resume&p2=238-8-172-209-155&player=00:15:af:b8:ac:25 HTTP/1.1

Also muss die Playliste 238-8-172-209-155.m3u heißen-

Dazu benötigen wir ein leeres Dokument, welches wir über einen Editor erzeugen.

dahinein schreiben wir schon mal 
#EXTM3U
#EXTINF:-1,


Jetzt benötigen wir nur noch den Link auf den externen Stream. Es gibt Links mit und ohne Stationslogo. Die Besten sind immer noch die, die durch den LMS erzeugt werden. Dazu suchen wir die Radiostation WDR4 im Menüpunkt Radio und fügen sie den Favoriten hinzu. Wenn wir jetzt in den LMS gehen, Und dort Hauptmenü - Favoriten auswählen, finden wir  rechts in der Zeile von Favoriten das Symbol eines Stiftes. Anklicken und WDR4 auswählen. Auch dort finden wir den Stift erneut. Anklicken. Jetzt ist folgendes Bild zu sehen:


Wir sehen zwei Felder, in denen wir etwas ändern könnten. Auf der linken Seite können wir die Anzeige anpassen. Die Änderung hier würde sich nicht auf die RadioCard auswirken, sondern nur auf die Favoriten-Anzeige. In der Mitte sehen wir den Link:

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

Das ist unser gesuchter Link! Den wollen wir nicht ändern, sondern ihn nur ins Clipboard kopieren. Wir fügen den Link aus dem Clipboard in unser Dokument ein. Zum Schluss unter 238-8-172-209-155.m3u im Ordner music/playlists/  speichern und FERTIG!

Nach Auflegen der RadioCard zeigt der SqueezePlay-Player den nachfolgenden Bildschirm:


Als Gimmik gibt es noch die UID und PZ dazu. Alle anderen Links im Internet, die ich gefunden habe, zeigten kein Sender Logo! Leider gibt es auch Stationen, die im LMS kein Logo haben, z.B. BBC4.

Es gibt noch eine einfachere Möglichkeit. Unter Internetradio - Suchen im LMS den gewünschten Sender eingeben und danach auswählen. Dann ist der Link ebenfalls sichtbar.


Beim nächsten Mal geht es um die CDCard. Da schauen wir uns an, wie die Playlisten aus der Musik-Datenbank schnell erzeugt werden können.

Mittwoch, 9. Januar 2013

9. Die DeviceCard sendet eine Nachricht



Heute schauen wir uns mal den Codeschnipsel an, der für die gestern gezeigte Nachricht zuständig ist.

Ich hatte schon erwähnt, dass, bevor eine CDCard  oder RadioCard abgearbeitet werden kann, sichergestellt werden muss, dass es keine DeviceCard ist. Das Ergebnis der Überprüfung befindet sich in der Varablen boolean deviceCard=0;  // Erkennungsflag, ob DeviceCard.  Die Variable hatten wir gestern in den Squeezebox-Settings. Der folgende Code steht in der void loop(void)


// ****** Dieser Block überprüft ob die Karte eine Gerätekarte ist.
i=0;

while( i<7) {
   if (memcmp(Squeezebox[i],serNum,5)==0)   //Prüfung ob Gerätekarte für SB3 01 {

Hier ein klassischer Vergleich von zwei Speicherbereichen (memory compare). Squeezebox[i] wird aus dem 2-dimensionalen Array gelesen, in dem alle UID/PZ enthalten sind. serNum ist mit 5 Byte definiert worden. Das Ergebnis des Vergleichs muss Null sein. Wenn das Ergebnis Null ist beginnen die Vorbereitungen der Anzeige.

Für Squeezebox-Fans kann ich an dieser Stelle die Informationen zum Command Line Interpreter (CLI) empfehlen. Zu finden über: Hilfe > Technische Informationen > Command Line Interface des LMS. Der Hilfe-Button ist unten links auf der Eingangsseite zum Logitech Media Server. 

Wir benötigen folgende Zeichenfolge:
"GET /status?p0=display&p1=<Nachricht1.Zeile>&p2=<Nachricht 2. Zeile>&p3=<Dauer in Sekunden>&player=<Mac-Adresse des Zielplayers>HTTP/1.0"


memcpy(namTmp,namSbox[i],18);

Der Name der SB wird in einen temporäre Variable gespeichert. Damit steht beim nächsten Schleifendurchlauf auch der letzte aufgerufene Name

memcpy(macAdrTmp,macAdrSbox[i],6); 

bzw. Mac-Adresse zur Verfügung. Jetzt ist alles da, was ich zum vernünftgen Anzeigen benötige. Also rufe ich das Unterprogramm


dsplMsgSB();

auf. Damit klar ist, dass wir uns in einer Subroutine befinden wird der Code in blau geschrieben.

void dsplMsgSB() {

Jetzt müssen wir uns aber dringend um die Parameter p1, p2 und player kümmern.

p1 = RFID-Steuerung%%20wurde%%20erfolgreich%%20nach (die %%20 sind zwischenräume weil das %-Zeichen anderweitig belegt ist.)
p2 = %s%%20umgeleitet (%s steht für die variable namTmp.)
player = %02x:%02x:%02x:%02x:%02x:%02x (an die Stelle von %02x wird der Reihe nach eine Variable eingetragen. Also macAdrTmp[0], macAdrTmp[1], macAdrTmp[2],... u.s.w. bis macAdrTmp[5]

Das schreiben wir jetzt in geordneter Art und Weise in einen vorgesehenen Speicherbereich.

snprintf(SBox, 150, "GET /status?p0=display&p1=RFID-Steuerung%%20wurde%%20erfolgreich%%20nach&p2=%s%%20umgeleitet&p3=10&player=%02x:%02x:%02x:%02x:%02x:%02x HTTP/1.0",
namTmp, macAdrTmp[0], macAdrTmp[1], macAdrTmp[2], macAdrTmp[3], macAdrTmp[4], macAdrTmp[5]);

Alles was in "  " steht ist anschließend in der 150 Byte Variablen mit dem Namen SBox gespeichert

Der Rest ist einfach. Server verbinden und SBox senden.

client.connect(server,9002);
  if (client.connected())  

  {
    while (client.available())   

      {
      char c = client.read();
       }
  client.println(SBox);
  client.println();
  }
  else
  {
    Serial.println(F("connection failed"));
  }
  client.stop();

}

... und nun nichts wie zurück!!!!



devicecard = 1;
Serial.println("DeviceCard ist 1"); // zu Testzwecken
break;
}
i++;
}

Die Variable deviceCard wird auf true(1) gesetzt und fertig. Damit wird ein nachfolgender Teil nicht ausgeführt. Dort wird erst abgefragt, welchen Wert deviceCard hat.

Was ist, wenn die Karte auf dem Leser liegenbleibt? SBox wird immer wieder gesendet; wenn nicht beim jedem Durchlauf überprüft würde, ob eine neue (andere) UID/PZ vorliegt. Wenn das nicht der Fall ist, wird alles, was oben beschrieben ist, nicht ausgeführt!

if (memcmp(data,serNum,5)!=0)
   {
   memcpy(serNum,data,5);

Beim ersten loop-Durchlauf ist serNum ohnehin leer und der Vergleich wird  != 0 sein. Danach werden die empfangenen Daten (data) nach serNum kopiert. Beim nächsten Durchlauf wird data == serNum sein; das bedeutet: alles wird übersprungen. Das gilt für die DeviceCard genauso wie für die RadioCard oder CDCard.

Zum Schluss eine kleine Übung:
Auf dem Display soll folgende Nachricht erscheinen "Herzliche Grüße aus Entenhausen!". MacAdresse ist 00:15:af:b8:ac:25 und soll für 30 Sekunden angezeigt werden.

Da wir "nur" eine konstante Nachricht haben lautet die Zeile

snprintf(SBox, 150, "GET /status?p0=display&p1=Herzliche%%20Gruesse%%20aus&p2=Entenhausen%%20von%%20Dagobert&p3=30&player=00:15:af:b8:ac:25 HTTP/1.0");

 ... und das sieht nachher auf einer Squeezebox-Touch so aus:



Ungeahnte Möglichkeiten tun sich nun auf. Mit einem Arduino und einem Ethernet Shield kann ich mir beliebige Systemmeldungen auf dem Display anzeigen lassen. Wer laute Musik hört, bekommt bei einem Besucher vor der Tür die Anzeige "Es klingelt!!!". Die Möglichkeiten sind dank der Offenlegung der Schnittstelle beliebig. Das erkennt man auch an den vielen Add-Ons, die für den LMS verfügbar sind.


Das nächste Mal wenden wir uns der RadioCard zu. Das ist wirklich einfach.