Nfc card data decodeing

Hi All,

I am reading an nfc card in and get the following data:
Current data in sector:
1 7 00 00 00 00 00 00 7F 07 88 40 00 00 00 00 00 00 [ 0 1 1 ]
6 62 68 6F 6F 6B 2F 2D 54 61 46 79 4F 39 61 4E 47 [ 0 0 0 ]
5 2E 31 34 37 3A 38 31 32 33 2F 61 70 69 2F 77 65 [ 0 0 0 ]
4 03 5C D1 01 58 55 03 31 39 32 2E 31 36 38 2E 31 [ 0 0 0 ]
i am trying to decode it as it is a url I want to get into nodered

Anyone knows how to do this?
I searched for several hours and can't find a solution :frowning:
thank you all!

Print the data out as ASCII characters, rather than using hexadecimal representation, and check whether they make sense as a URL.

Example (one line):

I tried but its wrong :slightly_frowning_face:

some is correct and then strange characters suddenly

The reader manual or data sheet probably has some useful information.

Also, the code you are using to read the data may have errors.

NFC is a short-range wireless technology that allows your phone to act as a transit pass, credit card, or data transfer tool. Learn how NFC works, what devices have it, and what you can do with it. Is this what we are talking about? Post links to the technical information an your annotated schematic.

The concept of the cards are a bit hard to me as of now tbh
still trying to understand it

my code is this one:

/**
 * ----------------------------------------------------------------------------
 * This is a MFRC522 library example; see https://github.com/miguelbalboa/rfid
 * for further details and other examples.
 *
 * NOTE: The library file MFRC522.h has a lot of useful info. Please read it.
 *
 * Released into the public domain.
 * ----------------------------------------------------------------------------
 * This sample shows how to read and write data blocks on a MIFARE Classic PICC
 * (= card/tag).
 *
 * BEWARE: Data will be written to the PICC, in sector #1 (blocks #4 to #7).
 *
 *
 * Typical pin layout used:
 * -----------------------------------------------------------------------------------------
 *             MFRC522      Arduino       Arduino   Arduino    Arduino          Arduino
 *             Reader/PCD   Uno/101       Mega      Nano v3    Leonardo/Micro   Pro Micro
 * Signal      Pin          Pin           Pin       Pin        Pin              Pin
 * -----------------------------------------------------------------------------------------
 * RST/Reset   RST          9             5         D9         RESET/ICSP-5     RST
 * SPI SS      SDA(SS)      10            53        D10        10               10
 * SPI MOSI    MOSI         11 / ICSP-4   51        D11        ICSP-4           16
 * SPI MISO    MISO         12 / ICSP-1   50        D12        ICSP-1           14
 * SPI SCK     SCK          13 / ICSP-3   52        D13        ICSP-3           15
 *
 * More pin layouts for other boards can be found here: https://github.com/miguelbalboa/rfid#pin-layout
 *
 */

#include <SPI.h>
#include <MFRC522.h>

#define RST_PIN         D8           // Configurable, see typical pin layout above
#define SS_PIN          D4          // Configurable, see typical pin layout above

MFRC522 mfrc522(SS_PIN, RST_PIN);   // Create MFRC522 instance.

MFRC522::MIFARE_Key key;
MFRC522::MIFARE_Key key2;

/**
 * Initialize.
 */
void setup() {
    Serial.begin(9600); // Initialize serial communications with the PC
    while (!Serial);    // Do nothing if no serial port is opened (added for Arduinos based on ATMEGA32U4)
    SPI.begin();        // Init SPI bus
    mfrc522.PCD_Init(); // Init MFRC522 card

    // Prepare the key (used both as key A and as key B)
    // using FFFFFFFFFFFFh which is the default at chip delivery from the factory
      key.keyByte[0] = 0xd3;
      key.keyByte[1] = 0xf7;
      key.keyByte[2] = 0xd3;
      key.keyByte[3] = 0xf7;
      key.keyByte[4] = 0xd3;
      key.keyByte[5] = 0xf7;

      key2.keyByte[0] = 0xFF;
      key2.keyByte[1] = 0xFF;
      key2.keyByte[2] = 0xFF;
      key2.keyByte[3] = 0xFF;
      key2.keyByte[4] = 0xFF;
      key2.keyByte[5] = 0xFF;

    Serial.println(F("Scan a MIFARE Classic PICC to demonstrate read and write."));
    Serial.print(F("Using key (for A and B):"));
    dump_byte_array(key.keyByte, MFRC522::MF_KEY_SIZE);
    Serial.println();
}

/**
 * Main loop.
 */
void loop() {
    // Reset the loop if no new card present on the sensor/reader. This saves the entire process when idle.
    if ( ! mfrc522.PICC_IsNewCardPresent())
        return;

    // Select one of the cards
    if ( ! mfrc522.PICC_ReadCardSerial())
        return;

    // Show some details of the PICC (that is: the tag/card)
    Serial.print(F("Card UID:"));
    dump_byte_array(mfrc522.uid.uidByte, mfrc522.uid.size);
    Serial.println();
    Serial.print(F("PICC type: "));
    MFRC522::PICC_Type piccType = mfrc522.PICC_GetType(mfrc522.uid.sak);
    Serial.println(mfrc522.PICC_GetTypeName(piccType));

    // Check for compatibility
    if (    piccType != MFRC522::PICC_TYPE_MIFARE_MINI
        &&  piccType != MFRC522::PICC_TYPE_MIFARE_1K
        &&  piccType != MFRC522::PICC_TYPE_MIFARE_4K) {
        Serial.println(F("This sample only works with MIFARE Classic cards."));
        return;
    }

    // In this sample we use the second sector,
    // that is: sector #1, covering block #4 up to and including block #7
    byte sector         = 1;
    byte blockAddr      = 4;
    byte dataBlock[]    = {
        0x01, 0x02, 0x03, 0x04, //  1,  2,   3,  4,
        0x05, 0x06, 0x07, 0x08, //  5,  6,   7,  8,
        0x09, 0x0a, 0xff, 0x0b, //  9, 10, 255, 11,
        0x0c, 0x0d, 0x0e, 0x0f  // 12, 13, 14, 15
    };
    byte trailerBlock   = 7;
    MFRC522::StatusCode status;
    byte buffer[18];
    byte size = sizeof(buffer);

    // Authenticate using key A
    Serial.println(F("Authenticating using key A..."));
    status = (MFRC522::StatusCode) mfrc522.PCD_Authenticate(MFRC522::PICC_CMD_MF_AUTH_KEY_A, trailerBlock, &key, &(mfrc522.uid));
    if (status != MFRC522::STATUS_OK) {
        Serial.print(F("PCD_Authenticate() failed: "));
        Serial.println(mfrc522.GetStatusCodeName(status));
        return;
    }

    // Show the whole sector as it currently is
    Serial.println(F("Current data in sector:"));
    mfrc522.PICC_DumpMifareClassicSectorToSerial(&(mfrc522.uid), &key, sector);
    Serial.println();

    // Read data from the block
    Serial.print(F("Reading data from block ")); Serial.print(blockAddr);
    Serial.println(F(" ..."));
    status = (MFRC522::StatusCode) mfrc522.MIFARE_Read(blockAddr, buffer, &size);
    if (status != MFRC522::STATUS_OK) {
        Serial.print(F("MIFARE_Read() failed: "));
        Serial.println(mfrc522.GetStatusCodeName(status));
    }
    Serial.print(F("Data in block ")); Serial.print(blockAddr); Serial.println(F(":"));
    dump_byte_array(buffer, 16); Serial.println();
    Serial.println();


    // Authenticate using key B
    Serial.println(F("Authenticating again using key B..."));
    status = (MFRC522::StatusCode) mfrc522.PCD_Authenticate(MFRC522::PICC_CMD_MF_AUTH_KEY_B, trailerBlock, &key2, &(mfrc522.uid));
    if (status != MFRC522::STATUS_OK) {
        Serial.print(F("PCD_Authenticate() failed: "));
        Serial.println(mfrc522.GetStatusCodeName(status));
        return;
    }

    
    // Dump the sector data
    Serial.println(F("Current data in sector:"));
    mfrc522.PICC_DumpMifareClassicSectorToSerial(&(mfrc522.uid), &key, sector);
    Serial.println();

    // Halt PICC
    mfrc522.PICC_HaltA();
    // Stop encryption on PCD
    mfrc522.PCD_StopCrypto1();
}

/**
 * Helper routine to dump a byte array as hex values to Serial.
 */
void dump_byte_array(byte *buffer, byte bufferSize) {
    for (byte i = 0; i < bufferSize; i++) {
        Serial.print(buffer[i] < 0x10 ? " 0" : " ");
        Serial.print(buffer[i], HEX);
    }
}

You forgot to mention what sort of card and reader you have, so it is unlikely that people on this forum will be able to give you a clear answer.

Did you notice this comment?

  • NOTE: The library file MFRC522.h has a lot of useful info. Please read it.

If you want to extract the useful data from the card, your main choices are 1) study the manual/data sheet, understand how the data are stored on the card and write code to extract the useful parts or 2) find code that happens to do what you want or 3) hire someone to write the code.

thank you so much for telling me there is a lot to cards :smiley:
I ordered some cheap nfc cards from aliexpress.
Turned out to be (scanned with my andro phone and the app NFC writer from Manjul Saini) Mifare classic 1k card

a short google session later I found a page with something about ndef libraries. Searched in the IDE for ndef and installed NDEF_MFRC522
Opened the example that came with it (readtag)
Changed the mfrc522 instance to my pins

#define RST_PIN D8
#define SS_PIN D4

got some error and decided to actually read (as you suggested) the beginning of the example that clearly states:
// This example requires #define NDEF_USE_SERIAL to be uncommented in Ndef.h

found Ndef.h in my Documents\Arduino\libraries\NDEF_MFRC522\src folder

uncommented the existing line with #define NDEF_USE_SERIAL and then compiled.

and surprise surprise, it works and shows HEX as well as the String on the card.

Thank you so much everyone telling me to read, turns out reading educates people