-
-
Save parzibyte/43025324f3ad3a3ec29de8e14873700e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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