RFID test
This commit is contained in:
parent
6684be01eb
commit
a3be4cbb3c
46
src/main.cpp
46
src/main.cpp
|
|
@ -276,6 +276,52 @@ void readRFID()
|
||||||
Serial.print("Tag UID: ");
|
Serial.print("Tag UID: ");
|
||||||
String uidString = getRFIDString(rfid.uid.uidByte);
|
String uidString = getRFIDString(rfid.uid.uidByte);
|
||||||
Serial.println(uidString);
|
Serial.println(uidString);
|
||||||
|
|
||||||
|
|
||||||
|
// Prepare key - all keys are set to FFFFFFFFFFFFh at chip delivery from the factory.
|
||||||
|
MFRC522::MIFARE_Key key;
|
||||||
|
for (byte i = 0; i < 6; i++) key.keyByte[i] = 0xFF;
|
||||||
|
|
||||||
|
//some variables we need
|
||||||
|
byte buffer[42]; //data transfer buffer (16+2 bytes data+CRC)
|
||||||
|
byte size = sizeof(buffer);
|
||||||
|
|
||||||
|
uint8_t pageAddr = 0x05; //In this example we will write/read 16 bytes (page 6,7,8 and 9).
|
||||||
|
//Ultraligth mem = 16 pages. 4 bytes per page.
|
||||||
|
//Pages 0 to 4 are for special functions.
|
||||||
|
|
||||||
|
MFRC522::StatusCode status;
|
||||||
|
|
||||||
|
rfid.PICC_DumpDetailsToSerial(&(rfid.uid));
|
||||||
|
|
||||||
|
//------------------------------------------- GET FIRST NAME
|
||||||
|
/*
|
||||||
|
status = rfid.PCD_Authenticate(MFRC522::PICC_CMD_MF_AUTH_KEY_A, 4, &key, &(rfid.uid)); //line 834 of MFRC522.cpp file
|
||||||
|
if (status != MFRC522::STATUS_OK) {
|
||||||
|
Serial.print(F("Authentication failed: "));
|
||||||
|
Serial.println(rfid.GetStatusCodeName(status));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Serial.println("Auth");
|
||||||
|
*/
|
||||||
|
|
||||||
|
// works only with mifare ultralight:
|
||||||
|
status = rfid.MIFARE_Read(pageAddr, buffer, &size);
|
||||||
|
if (status != MFRC522::STATUS_OK) {
|
||||||
|
Serial.print(F("Reading failed: "));
|
||||||
|
Serial.println(rfid.GetStatusCodeName(status));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Dump a byte array to Serial
|
||||||
|
for (byte i = 0; i < size; i++) {
|
||||||
|
Serial.write(buffer[i]);
|
||||||
|
}
|
||||||
|
Serial.println();
|
||||||
|
// ------------------------------
|
||||||
|
rfid.PICC_HaltA();
|
||||||
|
|
||||||
playSongByRFID(uidString);
|
playSongByRFID(uidString);
|
||||||
lastInteraction = millis();
|
lastInteraction = millis();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue