I've been using RFID2 reader with simple read and write examples, and have been working fine.
Now I need to access tags that has JSON code, and I just can't access this information
using Android NFC Tools, this is the information I have from the tag:
![]()
DATA ![]()
![]()
{"pin":"5585"}
![]()
FORMAT ![]()
![]()
Media (0x02)
Defined by RFC 2046
![]()
TYPE ![]()
![]()
application/json
![]()
PAYLOAD (14 bytes) ![]()
![]()
0x7B 0x22 0x70 0x69 0x6E 0x22 0x3A 0x22 0x35 0x35 0x38 0x35 0x22 0x7D
![]()
PAYLOAD (UTF8) ![]()
![]()
{"pin":"5585"}
![]()
PAYLOAD (ASCII) ![]()
![]()
{"pin":"5585"}
I've been trying many different libraries without any success. .
Is there any way to have access to this information? Any tip or guidance will be more than welcome.
This is a program I am using to check every block on the tags, and with this specific tag it simply gives error in every blocks. There must be something I am missing.
Thanks!
#include <Wire.h>
#include "MFRC522_I2C.h"
#include <ArduinoJson.h>
#define BLOCK_NUM 4 // Bloco onde o PIN está armazenado
#define RST_PIN 23 // No M5Atom, o reset pode ser ignorado
MFRC522 mfrc522(0x28); // Instância do leitor MFRC522
#define TOTAL_BLOCOS 64
int pinCode;
// Definição da chave padrão do Mifare Classic
MFRC522::MIFARE_Key keyA;
void setup() {
Serial.begin(115200);
Serial2.begin(9600, SERIAL_8N1, 19, 22); // Comunicação UART com outro dispositivo RX TX
Wire.begin();
mfrc522.PCD_Init();
// Inicializar a chave de autenticação
for (byte i = 0; i < 6; i++) {
keyA.keyByte[i] = 0xFF; // Chave padrão
}
}
void loop() {
// Verifica se há um novo cartão presente
if (!mfrc522.PICC_IsNewCardPresent() || !mfrc522.PICC_ReadCardSerial()) {
return;
}
Serial.print("\nUID da tag: ");
for (byte i = 0; i < mfrc522.uid.size; i++) {
Serial.print(mfrc522.uid.uidByte[i], HEX);
Serial.print(" ");
}
Serial.println("\nLendo todos os blocos...");
// Loop para ler todos os blocos disponíveis (16 blocos por setor)
for (int bloco = 0; bloco < 64; bloco++) {
if ((bloco + 1) % 4 == 0) { // pula o bloco trailer
continue;
}
if (authenticateBlock(bloco)) { // Autentica o setor antes de ler
byte buffer[18]; // Buffer para armazenar os dados do bloco
byte bufferLen = sizeof(buffer);
if (mfrc522.MIFARE_Read(bloco, buffer, &bufferLen) == MFRC522::STATUS_OK) {
Serial.print("Bloco ");
Serial.print(bloco);
Serial.print(": ");
// Imprime os bytes do bloco em formato HEX
for (byte j = 0; j < 16; j++) {
Serial.print(buffer[j], HEX);
Serial.print(" ");
}
Serial.println();
} else {
Serial.print("Erro ao ler o bloco ");
Serial.println(bloco);
}
//if (bloco == 4) { // Se for o bloco 4 (onde os dados foram gravados)
//extrairCodigo(buffer);
//}
} else {
Serial.print("Falha na autenticação do bloco ");
Serial.println(bloco);
}
}
mfrc522.PICC_HaltA(); // Finaliza comunicação com o cartão
mfrc522.PCD_StopCrypto1(); // Para a autenticação do cartão
Serial.println("Tem o pin: " + String(pinCode));
Serial.println("\nLeitura completa! Remova a tag.");
delay(3000);
}