Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created June 4, 2021 17:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parzibyte/43025324f3ad3a3ec29de8e14873700e to your computer and use it in GitHub Desktop.
Save parzibyte/43025324f3ad3a3ec29de8e14873700e to your computer and use it in GitHub Desktop.
bool leer(char mensaje[LONGITUD_BYTES])
{
if (!lector.PICC_IsNewCardPresent())
{
return false;
}
if (!lector.PICC_ReadCardSerial())
{
Serial.println("Error leyendo serial");
return false;
}
byte bloque = 1; // El bloque que leemos
byte longitud = LONGITUD_BYTES;
byte buferLectura[LONGITUD_BYTES];
MFRC522::StatusCode estado;
estado = lector.PCD_Authenticate(MFRC522::PICC_CMD_MF_AUTH_KEY_A, bloque, &clave, &(lector.uid));
if (estado != MFRC522::STATUS_OK)
{
Serial.println("Error autenticando");
Serial.println(lector.GetStatusCodeName(estado));
return false;
}
estado = lector.MIFARE_Read(bloque, buferLectura, &longitud);
if (estado != MFRC522::STATUS_OK)
{
Serial.println("Error leyendo bloque");
Serial.println(lector.GetStatusCodeName(estado));
return false;
}
for (uint8_t i = 0; i < LONGITUD_BYTES - 2; i++)
{
mensaje[i] = buferLectura[i];
}
// Ya pueden retirar la tarjeta
lector.PICC_HaltA();
lector.PCD_StopCrypto1();
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment