Samstag, 9. Februar 2013

9. The DeviceCard sends a message

Today we take a look at the code snippet, which is responsible for the message shown in the blog yesterday. I had already mentioned that before a CDCard   or RadioCard can be processed, it must be ensured that the detcted RFID-card is no DeviceCard. The result of the check is stored in the variable boolean device card = 0 . The variable we had yesterday in the Squeezebox settings. The following code can be find in the void loop (void)

// ****** This block checks whether the card is a card devices.

i = 0;

while (i <7) {
   if (memcmp (Squeezebox [i], SerNum , 5) == 0) // check if device card for SB3 01

Here is a classic comparison of two memory locations (memory compare). Squeezebox [i] is read from the 2-dimensional array in which all UID / CS, are included. SerNum has been defined with 5 bytes. The result of the comparison must be zero. If the result is zero, the beginning preparations for displaying the message start.

For Squeezebox fans: I can recommend at this point the information about the Command Line Interpreter (CLI). To find: Help> Technical Information> command line interface of the LMS. The Help button is on the bottom left on the entrance side of the Logitech Media Server. 

We require the following character string:

"GET / status display & p0 = p1 = p2 = & <Nachricht1.Zeile> <Nachricht second line> & p3 = <duration in seconds> & player? = <player's MAC address> HTTP/1.0 "

Let#s start building the message
memcpy (namTmp, namSbox [i], 18); the name of the SB is stored in a temporary variable. So after the next iteration of the loop the name of the squeeze-device is known as well
memcpy (macAdrTmp, macAdrSbox [i], 6), 

same to the Mac address.

Now we have all the things we need for displaying.all there is, what do I need to vernünftgen ads. So I call the subroutine

dsplMsgSB() .

Thus it is clear that we will find ourselves in a subroutine, the code is written in blue letters.

dsplMsgSB void () {

Now we need to urgently deal with the parameters p1, p2 and player.
p1 = RFID-Steuerung%%20wurde%% 20erfolgreich%% 20nach  (the%%20are the spaces between between two words. We use double%% because the single %-character is used otherwise)
english version: 
p1 = The%%20RFID-controlling%%20has%%20been%%29rerouted 

p2 =%s%% 20umgeleitet (%s is the variable namTmp)
english version:
p2 = to%%20%s%%20sucessfully
player = 02x%:% 02x:% 02x:% 02x :% 02x:.% 02x (02x in place of the% number is entered after a variable So macAdrTmp [0] , macAdrTmp [1], macAdrTmp [2], ... etc to macAdrTmp [5]

We write now in an orderly manner in a designated memory area.
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]);

Everything in "" is being followed in the 150 bytes variable named SBox saved The rest is easy. Connect to the server and send the message placed in SBox

client.connect (server, 9002);  
if (client.connected ())  
  while (client.available())
    char c = ();
  client.println (SBox);
  client.println ();
  Serial.println (F ("connection failed"));
client.stop ();

... and now returning to the main-program! !

device card = 1;

Serial.println ("Device Card is 1") // for testing


The variable deviceCard will be set to true (1) and ready. With deviceCard =1 the subsequent rest of this programpart will not be executed.

What if the card remains lying on the reader? SBox is sent again and again - if not checked at each iteration if a new (other) UID/CS exists. If this is not the case, everthing what is decribed above will not be executed.
if (memcmp (data, SerNum, 5) = 0!)    {
   memcpy (SerNum, data, 5),

The first loop pass is SerNum is empty and the comparison will be  != 0. After that the received data (data)  will be copied to serNum. The next loop cycle you find data == serNum , that means everything is skipped. This applies to the Device Card as well as for the RadioCard or CDCard .  

Finally, a little exercise: On the  display the message   "Best regards from Duckburg, Dagobert" should appear for 30 seconds.
The MacAddress is  00:15:AF: AC:B8:25 . Since we "only" have a constant message the line  

snprintf(SBox, 150, "GET /status?p0=display&p1=Best%%20regards%%20from&p2=Duckburg,%%20Dagobert&p3=30&player=00:15:af:b8:ac:25 HTTP/1.0");

  ... and that looks on a Squeezebox Touch in german language like this:

Unimagined possibilities are opening up now. With an Arduino and an Ethernet shield you can display any system messages on on your Squeeze-device. Who likes listening to loud music and gets a visitor at the door the display says  "There is the bell ringing!". The possibilities are unlimited, thanks to the disclosure of the interface. This can also be seen in the many add-ons that are available for the LMS. Next time, we turn to the radio card. This is really simple.

Keine Kommentare:

Kommentar veröffentlichen