RFID tag match issue - Solved post #4

I have a RFID ( MIFARE type ) tag reader data in : byte readCard[4]

I am reading the reference Tag details from a SD card with following code :

char letter;

dataFile.seek(rfidPosition);
  for ( int i = 0; i < 8; i++ )  {                         // Read the eight positions of RFID reference
    letter = dataFile.read();
    rec_char_RFID[i] = letter;
  }

The output of the above read is like A02B94FF.

Need a method to find if rec_car_RFID matches with readCard. Checked some examples here but none addresses such a requirement exactly…

Any help ??

Use a for loop to compare the individual elements of the arrays one by one.

This works but only for numerics …possibly I need to check if its a numeric or character from A-F and decide on whether to OR 0x30 or 0x41 ? Is this an opton?

// FUNCTION TO CONVERT A BYTE ARRAY TO A CHAR ARRAY. EXAMPLE : 4 BYTE ARRAY IS CONVERTED TO CHAR ARRAY WITH 8 ELEMENTS

void RFID_To_Char (byte* byteArray, char* charArray, int ByteArraySize) {
  int byteCount ;
  int charCount = 0;
  for ( byteCount = 0; byteCount < ByteArraySize; byteCount++ ) {
    charArray[charCount] = (byteArray[byteCount] >> (4)) | 0x30 ;
    charArray[charCount + 1] = (byteArray[byteCount] & 0x0f )| 0x30;
    charCount += 2;
  }
}

Even tried sprint as in code below. Still no luck - and the worse thing the LCD message reads like below ( First line is tag ref from SD card read by another routine, second line is the output of RFID reader and last line verdict )

A02B94FF
A02B94FF
NO MATCH

// FUNCTION TO CHECK IF THE SCANNED RFID MATCHES WITH REQUIRED RFID AND DISPLAY VERDICT....

int rfidMatchDisp() {

  char rec_char_RFID[9];
  char act_char_RFID[9];
  rec_char_RFID[8] = '\0';                                                 // Null Terminate the strings
  act_char_RFID[8] = '\0';
  int result = -1;
  char letter ;

  int rfidPosition = 0;

  File dataFile = SD.open("ACTUAL.CSV", FILE_READ);        // Open the file
  dataFile.seek(seekPoint + 1);                              // Got to the valid begining of record to process..
  statusToken = dataFile.read();                            // Save the Token to decide what to display..
  rfidPosition = dataFile.position() + 1;                   // Index the RFID position for reading
  dataFile.seek(rfidPosition);
  for ( int i = 0; i < 8; i++ )  {                               // Read the eight positions of RFID reference
    letter = dataFile.read();
    rec_char_RFID[i] = letter;
  }
    
  sprintf ( tagActual, "%02X%02X%02X%02X", readCard[0], readCard[1], readCard[2], readCard[3]);
  result = strcmp (rec_char_RFID, tagActual);
  dataFile.close();

  lcd.setCursor( 0, 2);
  lcd.print( tagActual);
  lcd.setCursor( 0, 3);
  if ( result == 0 ) {
    lcd.print ( "MATCHED");
  }
  else {
    lcd.print ( "NO MATCH");
  }
}

The sprint() which I posted above finally worked. I had actually made a mistake in displaying the tag ref from SD card and RFID Reader.

Guess will go forward and use this as in any case the rest of code uses sprint() anyway for some LCD message updates.