Han' mal den wichtigen Teil beigefügt. Die zwei Zeilen für das CS der SD-Karte habe ich eingefügt. Die Subs des dem RFID-shield mitgelieferten sketch habe ich weg gelassen.
Funktionsweise:
setup(): nix besonderes
loop(): Bereitstellen der RFID-Kartennummer und Übergabe an
playPlaylist(): aufrufen der Playliste im Logitech Media Center die aus der Kartennummer und Extension besteht.
#include <SPI.h>
#include <Ethernet.h>
#define uchar unsigned char
#define uint unsigned int
// Maximum length of an array
#define MAX_LEN 16
/////////////////////////////////////////////////////////////////////
//set the pin
/////////////////////////////////////////////////////////////////////
const int chipSelectPin = 9;
const int chipSelectEth = 10;
const int NRSTPD = 5;
// 4-byte card serial number, 5 byte checksum byte
uchar serNum[5];
uchar writeData[16]={0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 100}; //initialize the 100 yuan
uchar moneyConsume = 18 ; // consumption of 18 yuan
uchar moneyAdd = 10 ; // recharge 10 yuan
// Sector A password, 16 sectors, each sector password 6Byte
uchar sectorKeyA[16][16] = {{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
//{0x19, 0x84, 0x07, 0x15, 0x76, 0x14},
{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
};
uchar sectorNewKeyA[16][16] = {{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xff,0x07,0x80,0x69, 0x19,0x84,0x07,0x15,0x76,0x14},
//you can set another ket , such as " 0x19, 0x84, 0x07, 0x15, 0x76, 0x14 "
//{0x19, 0x84, 0x07, 0x15, 0x76, 0x14, 0xff,0x07,0x80,0x69, 0x19,0x84,0x07,0x15,0x76,0x14},
// but when loop, please set the sectorKeyA, the same key, so that RFID module can read the card
{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xff,0x07,0x80,0x69, 0x19,0x33,0x07,0x15,0x34,0x14},
};
byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
byte ip[]={192,168,2,177};
byte server[] = {192, 168, 2, 14 };
String card;
String cardNew;
EthernetClient client;
void setup() {
Serial.begin(9600); // RFID reader SOUT pin connected to Serial RX pin at 2400bps
Ethernet.begin(mac, ip);
SPI.begin();
pinMode(chipSelectPin,OUTPUT); // Set digital pin 10 as OUTPUT to connect it to the RFID /ENABLE pin
//pinMode(chipSelectEth,OUTPUT);
digitalWrite(chipSelectPin, LOW); // Activate the RFID reader
//digitalWrite(chipSelectEth,HIGH);
pinMode(NRSTPD,OUTPUT); // Set digital pin 10 , Not Reset and Power-down
digitalWrite(NRSTPD, HIGH);
pinMode(4, OUTPUT);
digitalWrite(4, HIGH);
MFRC522_Init();
}
void loop()
{
uchar i,tmp;
uchar status;
uchar str[MAX_LEN];
uchar RC_size;
uchar blockAddr; // select the operating block address 0 to 63
// Look for the card, return the card type
status = MFRC522_Request(PICC_REQIDL, str);
if (status == MI_OK)
{}
// Anti-collision, return the card serial number 4-byte
status = MFRC522_Anticoll(str);
memcpy(serNum, str, 16);
card = " ";
if (status == MI_OK)
{
for (i=0;i<5;i++)
{
card += serNum[i];
if (i<4){card += "-";}
}
if (cardNew!= card)
{
Serial.println(card);
Serial.println(cardNew);
digitalWrite(chipSelectPin,HIGH);
playPlaylist(card);
digitalWrite(chipSelectPin,LOW);
Serial.println("Back again");
}
cardNew = card;
// Election card, return the card capacity
RC_size = MFRC522_SelectTag(serNum);
if (RC_size != 0)
{}
//Serial.println(" ");
MFRC522_Halt(); // command card into hibernation
}
}
/*
* Function: playPlaylist
* Description: The Playlist is sent to the Logitech Media center
* Input parameters: Cardnumber of RFID-Card
* Return value:
*/
void playPlaylist(String playlist)
{
client.connect(server,9002);
Serial.println("connecting...");
if (client.connected()) {
Serial.println("connected");
Serial.println(client.connected() + playlist);
//client.println("GET /status?p0=playlist&p1=play&p2=" + playlist + "&player=e3:f8:d4:d8:ae:ce HTTP/1.1");
client.println("GET /status?p0=pause HTTP/1.1");
client.println();
}
else {
Serial.println("connection failed");
}
while (client.available()) {
char c = client.read();
Serial.print(c);
}
if (!client.connected()) {
Serial.println();
Serial.println("disconnecting.");
client.stop();
}
}
Probleme wahrscheinlich in der Sub. teilweise bleibt der Uno auch nach der Rückkehr aus der sub stehen. "Back again" noch da, dann Ruhe im Busch.
Danke für die Hilfe.
Eberhard