don / NDEF

NDEF Library for Arduino. Read and Write NDEF Messages to NFC tags with Arduino.
Other
286 stars 142 forks source link

Get message as a String #29

Closed ben14124 closed 9 years ago

ben14124 commented 9 years ago

Hi, is it there any form to get the message that is in the NFC card and store it in a String variable in Arduino?

Thanks!

don commented 9 years ago

@ben14124 the payload comes back as bytes. You can create a string from the bytes.

If you read a TNF_Well_Known tag with RTD of Text, you'd read the first byte to get the length of the language code, then read the language code, then convert the remaining bytes into a string.

The ReadTagExtended.ino example attempts to convert every NDEF message payload into a String. This works for OK some tags and fails miserably for others.

    String payloadAsString = "";
    for (int c = 0; c < payloadLength; c++) {
      payloadAsString += (char)payload[c];
    }
ben14124 commented 9 years ago

Oh yeah, I totally forgot the ReadTagExtended example. That worked perfectly for me. Thanks a lot!