Can't decode message

Hello dude,
I have Seeduino Shield NFC, "http://www.seeedstudio.com/forum/viewtopic.php?f=16&t=6829" and i have a problem,
with

#include <SPI.h>
#include "PN532_SPI.h"
#include "PN532.h"
#include "NfcAdapter.h"

PN532_SPI interface(SPI, 10); // create a SPI interface for the shield with the SPI CS terminal at digital pin 10

NfcAdapter nfc = NfcAdapter(interface); // create an NFC adapter object
 
void setup(void) 
{
    Serial.begin(115200); // start serial comm
    Serial.println("NDEF Reader");
    nfc.begin(); // begin NFC comm
}

void loop(void) 
{
  Serial.println("\nScan an NFC tag\n");
  if (nfc.tagPresent()) // Do an NFC scan to see if an NFC tag is present
  {
      NfcTag tag = nfc.read(); // read the NFC tag
      if(tag.hasNdefMessage())
      {
        NdefMessage message = tag.getNdefMessage();
        for(int i=0;i<message.getRecordCount();i++)
        {
          NdefRecord record = message.getRecord(i);
          int payloadLength = record.getPayloadLength();
          byte payload[payloadLength];
          record.getPayload(payload);
          Serial.write(payload,payloadLength);
        }
      }
  }
  delay(500); // wait half a second (500ms) before scanning again (you may increment or decrement the wait time)
}

normally, u can read the text NFC tag..
but with me, he can't read why ? He can read my UiD but not my message..

Look my screen Screenshot by Lightshot

Normally, with this program, we can read the TAG NFC.. no?

but, with the

#include "SPI.h"
#include "PN532_SPI.h"
#include "emulatetag.h"
#include "NdefMessage.h"

PN532_SPI pn532spi(SPI, 10);
EmulateTag nfc(pn532spi);

uint8_t ndefBuf[120];
NdefMessage message;
int messageSize;

uint8_t uid[3] = { 0x12, 0x34, 0x56 };

void setup()
{
  Serial.begin(115200);
  Serial.println("------- Emulate Tag --------");
  
  message = NdefMessage();
  message.addUriRecord("http://www.seeedstudio.com");
  messageSize = message.getEncodedSize();
  if (messageSize > sizeof(ndefBuf)) {
      Serial.println("ndefBuf is too small");
      while (1) { }
  }
  
  Serial.print("Ndef encoded message size: ");
  Serial.println(messageSize);

  message.encode(ndefBuf);
  
  // comment out this command for no ndef message
  nfc.setNdefFile(ndefBuf, messageSize);
  
  // uid must be 3 bytes!
  nfc.setUid(uid);
  
  nfc.init();
}

void loop(){
    // uncomment for overriding ndef in case a write to this tag occured
    //nfc.setNdefFile(ndefBuf, messageSize); 
    
    // start emulation (blocks)
    nfc.emulate();
        
    // or start emulation with timeout
    /*if(!nfc.emulate(1000)){ // timeout 1 second
      Serial.println("timed out");
    }*/
    
    // deny writing to the tag
    // nfc.setTagWriteable(false);
    
    if(nfc.writeOccured()){
       Serial.println("\nWrite occured !");
       uint8_t* tag_buf;
       uint16_t length;
       
       nfc.getContent(&tag_buf, &length);
       NdefMessage msg = NdefMessage(tag_buf, length);
       msg.print();
    }

    delay(1000);
}

He can read..
look screen Screenshot by Lightshot I put the yellows highlight

I don't understand why...

But i need the first program, i need that my Shield NFC read all the time.

Thanks.. i hope u can help me, i'm beginner ^^

Please ? ^^

Sorry, I cannot help you.

I will warn you that most helpful people on this forum will not go to some web site to look at anything. It could be dangerous. At a minimum, you need to attach text and photos inline.

Oh ok... Sorry.. I repeat x)
I use on my GSM, an application ! "NFC TOOL" We can write a NFC TAG or we can read.
Here, u can see, sorry this is french ^^

when i use the program
#include "SPI.h"
#include "PN532_SPI.h"
#include "emulatetag.h"
#include "NdefMessage.h"

PN532_SPI pn532spi(SPI, 10);
EmulateTag nfc(pn532spi);

uint8_t ndefBuf[120];
NdefMessage message;
int messageSize;

uint8_t uid[3] = { 0x12, 0x34, 0x56 };

void setup()
{
Serial.begin(115200);
Serial.println("------- Emulate Tag --------");

message = NdefMessage();
message.addUriRecord("http://www.seeedstudio.com");
messageSize = message.getEncodedSize();
if (messageSize > sizeof(ndefBuf)) {
Serial.println("ndefBuf is too small");
while (1) { }
}

Serial.print("Ndef encoded message size: ");
Serial.println(messageSize);

message.encode(ndefBuf);

// comment out this command for no ndef message
nfc.setNdefFile(ndefBuf, messageSize);

// uid must be 3 bytes!
nfc.setUid(uid);

nfc.init();
}

void loop(){
// uncomment for overriding ndef in case a write to this tag occured
//nfc.setNdefFile(ndefBuf, messageSize);

// start emulation (blocks)
nfc.emulate();

// or start emulation with timeout
/if(!nfc.emulate(1000)){ // timeout 1 second
Serial.println("timed out");
}
/

// deny writing to the tag
// nfc.setTagWriteable(false);

if(nfc.writeOccured()){
Serial.println("\nWrite occured !");
uint8_t* tag_buf;
uint16_t length;

nfc.getContent(&tag_buf, &length);
NdefMessage msg = NdefMessage(tag_buf, length);
msg.print();
}

delay(1000);
}

when i create a NFC tag text on my application
Look screen :

And i scan my NFC shield,
my serial monitor can receive the message.
look :

It's ok... But when i use the program
#if 1
#include <SPI.h>
#include <PN532_SPI.h>
#include <PN532.h>
#include <NfcAdapter.h>

PN532_SPI pn532spi(SPI, 10);
NfcAdapter nfc = NfcAdapter(pn532spi);
#else

#include <Wire.h>
#include <PN532_I2C.h>
#include <PN532.h>
#include <NfcAdapter.h>

PN532_I2C pn532_i2c(Wire);
NfcAdapter nfc = NfcAdapter(pn532_i2c);
#endif

void setup(void) {
Serial.begin(9600);
Serial.println("NDEF Reader");
nfc.begin();
}

void loop(void) {
Serial.println("\nScan a NFC tag\n");
if (nfc.tagPresent())
{
NfcTag tag = nfc.read();
tag.print();
}
delay(5000);
}

He can't read my NFC tag writted by my application, why ?

Look screen

I hope u can help me, i need that my NFC shield can read a NFC tag writted my smartphone

Please modify your post and use the code button </> so your code looks like this and is easy to copy to a text editor. See How to use the Forum

…R

Unfortunately, Randy68 used angle brackets instead of square brackets. The symbol on the button probably added to the confusion.

For Randy68 to post, Randy68 should:

  1. Use CTRL-T in the Arduino IDE to autoformat your code.
  2. Paste the autoformatted code between code tags (the </> button)
    so that we can easily see and deal with your code.

In one case, you use nfc.getContent() to get the information of interest. In the other case, you are trying to use nfc.read() to get the same information. I can't imagine why you think that should work.

Oh ok, i understood..
Why i use 'Nfc.read' ?? Because i want that he displays just my "Message"..

so, with this program

#include "SPI.h"
#include "PN532_SPI.h"
#include "emulatetag.h"
#include "NdefMessage.h"

PN532_SPI pn532spi(SPI, 10);
EmulateTag nfc(pn532spi);

uint8_t ndefBuf[120];
NdefMessage message;
int messageSize;

uint8_t uid[3] = { 0x12, 0x34, 0x56 };

void setup()
{
  Serial.begin(115200);
  Serial.println("------- Emulate Tag --------");

  message = NdefMessage();
  message.addUriRecord("http://www.seeedstudio.com");
  messageSize = message.getEncodedSize();
  if (messageSize > sizeof(ndefBuf)) {
    Serial.println("ndefBuf is too small");
    while (1) { }
  }

  Serial.print("Ndef encoded message size: ");
  Serial.println(messageSize);

  message.encode(ndefBuf);

  // comment out this command for no ndef message
  nfc.setNdefFile(ndefBuf, messageSize);

  // uid must be 3 bytes!
  nfc.setUid(uid);

  nfc.init();
}

void loop() {
  // uncomment for overriding ndef in case a write to this tag occured
  nfc.setNdefFile(ndefBuf, messageSize);

  // start emulation (blocks)
  nfc.emulate();

  // or start emulation with timeout
  /*if(!nfc.emulate(1000)){ // timeout 1 second
    Serial.println("timed out");
    }*/

  // deny writing to the tag
  // nfc.setTagWriteable(false);

  if (nfc.writeOccured()) {
    Serial.println("\nWrite occured !");
    uint8_t* tag_buf;
    uint16_t length;

    nfc.getContent(&tag_buf, &length);
    NdefMessage msg = NdefMessage(tag_buf, length);
    msg.print();
  }

  delay(1000);
}

I saw, i can read my tag, look here :

But, my goal is to put my message in the variable, so i want just to take the Payload or just the message (He is frame on red)

it is possible ??, i'm beginner as coder...
I search in the library but i can't understand..

Can u help me ? Thanks

But with my program, he displays a lot of message, as

TNF
Type
Type length etc..

I want just take :

but, it's possible to take the payload and put in the variable ? because this is a text on hexa..

because this is a text on hexa..

I have no idea what you think this means.

I have no idea where you got the library that you are using. Surely there is some method in the NdefMessage class to get the actual data from the message. Otherwise, it is a pretty useless class.