don/NDEF

compare String

Closed this issue · 0 comments

Hi, im use this code for store NDEF to String variable
String payloadAsString = ""; for (int c = 0; c < payloadLength; c++) { payloadAsString += (char)payload[c]; }
I would comparison this variable with Another variable
for this job I have defined a variable and inside it saved The string to be compared and compare this one with Posted NDEF meesage by tag or other nfc device.
But when i send equale string my answer of copmare is negative
I wrote this with help of example

please Help me :(
thanks a lot
my code is

`#include <SPI.h>
#include <PN532_SPI.h>
#include <PN532.h>
#include <NfcAdapter.h>
PN532_SPI pn532spi(SPI, 10);
NfcAdapter nfc = NfcAdapter(pn532spi);

void setup() {
Serial. begin(9600);
Serial. println("NDEF Reader" );
nfc. begin();
}
void loop() {
Serial. println(" \nScan a NFC tag\n" );
if (nfc. tagPresent()) {
NfcTag tag = nfc. read();
Serial. println(tag. getTagType());
Serial. print("UID: " );
Serial. println(tag. getUidString());
if (tag. hasNdefMessage()) {
NdefMessage message = tag. getNdefMessage();
tag.print();
Serial. print(" \nThis NFC Tag contains an NDEF Message with " );
Serial. print(message. getRecordCount());
Serial. print(" NDEF Record" );

  int recordCount = message. getRecordCount();
  for (int i = 0; i < recordCount; i++)
  {
    Serial. print(" \nNDEF Record " );
    Serial. println(i + 1);
    NdefRecord record = message. getRecord(i);
    Serial. print(" TNF: " );
    Serial. println(record. getTnf());
    Serial. print(" Type: " );
    Serial. println(record. getType());

int payloadLength = record. getPayloadLength();
byte payload[payloadLength];
record. getPayload(payload);
record.print();
String payloadAsString = "" ;
String mycode ="enABC";
for (int c = 0; c < payloadLength; c++) {
payloadAsString += (char)payload[c];
Serial.println("code");
Serial.println(payloadAsString);
}
if (payloadAsString == (mycode)) {
Serial.println("true");

              Serial. print(" Payload (as String): " );
              Serial. println(payloadAsString);
            }
            else {
              Serial.println("false");
              Serial. print(" Payload (as String): " );
              Serial. println(payloadAsString);

String uid = record. getId();
if (uid != "" ) {
Serial. print(" ID: " ); Serial. println(uid);
}

  }
}
delay(3000);  // delay before next read

}
}
}
`