miguelbalboa / rfid

Arduino RFID Library for MFRC522
The Unlicense
2.73k stars 1.42k forks source link

Can't read payload data #623

Open serkanersozz opened 4 months ago

serkanersozz commented 4 months ago

Step 1: Describe your environment

I'm trying to read from mifare 13,56 rfid tags. I can read UID successfully but not payload.

Below what I tried recently and i'm kinda lost it because it shouldn't this hard so I'm looking in the wrong direction, probably.

String dump_byte_array(byte *buffer, byte bufferSize)
{
  String data = "";
  for (byte i = 0; i < bufferSize; i++)
  {
    data.concat(String(buffer[i] < 0x10 ? "0" : ""));
    data.concat(String(buffer[i], HEX));
  }
  Serial.println(data);
  return data;
}

// Running in a device loop so reader is the device index
if (mfrc522[reader].PICC_IsNewCardPresent() && mfrc522[reader].PICC_ReadCardSerial())
    {
      byte buffer[18];
      byte size = sizeof(buffer);
      mfrc522[reader].MIFARE_Read(4, buffer, &size);
      // BELOW DOES NOT WORKS. PRINTS 300426EE00000000000000009022FB3F
      dump_byte_array(buffer, 16);
      // BELOW WORKS
      card_id = dump_byte_array(mfrc522[reader].uid.uidByte, mfrc522[reader].uid.size);
      mfrc522[reader].PICC_HaltA();
      mfrc522[reader].PCD_StopCrypto1();
    }