From a3be4cbb3cc3c4f2bf4f81e6685b44ced2cfc444 Mon Sep 17 00:00:00 2001 From: Stefan Ostermann Date: Thu, 12 Oct 2023 23:19:58 +0200 Subject: [PATCH] RFID test --- src/main.cpp | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/src/main.cpp b/src/main.cpp index e25f859..a9520ed 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -276,6 +276,52 @@ void readRFID() Serial.print("Tag UID: "); String uidString = getRFIDString(rfid.uid.uidByte); 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); lastInteraction = millis(); }