Payload Shield NFC

Hello dude, i have a problem ! i am using the NFC shield seeduino v2.1 nfc and i just want to select the payload of what i send trough nfc to arduino to show up on the serial monitor

http://prntscr.com/atgl4y

Here, i want just extract red square. It is possible ?

Just extract "Payload 02 65 6E 4D 79 54 65 78 74 .enMyText"

My current code :

#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);
}

And i change to

#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;
String payload;
int indx;


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);
        String msg = NdefMessage(tag_buf, length);
        indx = msg.indexOf("Payload");
      if (indx != -1) {
     payload = msg.substring(indx);
     Serial.println(payload);
 }
    }

    delay(1000);
}

But, i try... It's doesn't work, can u help me pls ?

Thanks if u help me dude :)

here, this is the error message

C:\Users\Thierry\Desktop\vrai_lire\vrai_lire.ino: In function ‘void loop()’:

vrai_lire:67: error: no matching function for call to ‘String::String(NdefMessage)’

String msg = (String) NdefMessage(tag_buf, length);

^

C:\Users\Thierry\Desktop\vrai_lire\vrai_lire.ino:67:58: note: candidates are:

In file included from C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Arduino.h:223:0,

from sketch\vrai_lire.ino.cpp:1:

C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/WString.h:73:11: note: String::String(double, unsigned char)

explicit String(double, unsigned char decimalPlaces=2);

^

C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/WString.h:73:11: note: no known conversion for argument 1 from ‘NdefMessage’ to ‘double’

C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/WString.h:72:11: note: String::String(float, unsigned char)

explicit String(float, unsigned char decimalPlaces=2);

^

C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/WString.h:72:11: note: no known conversion for argument 1 from ‘NdefMessage’ to ‘float’

C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/WString.h:71:11: note: String::String(long unsigned int, unsigned char)

explicit String(unsigned long, unsigned char base=10);

^

C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/WString.h:71:11: note: no known conversion for argument 1 from ‘NdefMessage’ to ‘long unsigned int’

C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/WString.h:70:11: note: String::String(long int, unsigned char)

explicit String(long, unsigned char base=10);

^

C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/WString.h:70:11: note: no known conversion for argument 1 from ‘NdefMessage’ to ‘long int’

C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/WString.h:69:11: note: String::String(unsigned int, unsigned char)

explicit String(unsigned int, unsigned char base=10);

^

C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/WString.h:69:11: note: no known conversion for argument 1 from ‘NdefMessage’ to ‘unsigned int’

C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/WString.h:68:11: note: String::String(int, unsigned char)

explicit String(int, unsigned char base=10);

^

C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/WString.h:68:11: note: no known conversion for argument 1 from ‘NdefMessage’ to ‘int’

C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/WString.h:67:11: note: String::String(unsigned char, unsigned char)

explicit String(unsigned char, unsigned char base=10);

^

C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/WString.h:67:11: note: no known conversion for argument 1 from ‘NdefMessage’ to ‘unsigned char’

C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/WString.h:66:11: note: String::String(char)

explicit String(char c);

^

C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/WString.h:66:11: note: no known conversion for argument 1 from ‘NdefMessage’ to ‘char’

C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/WString.h:64:2: note: String::String(StringSumHelper&&)

String(StringSumHelper &&rval);

^

C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/WString.h:64:2: note: no known conversion for argument 1 from ‘NdefMessage’ to ‘StringSumHelper&&’

C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/WString.h:63:2: note: String::String(String&&)

String(String &&rval);

^

C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/WString.h:63:2: note: no known conversion for argument 1 from ‘NdefMessage’ to ‘String&&’

C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/WString.h:61:2: note: String::String(const __FlashStringHelper*)

String(const __FlashStringHelper *str);

^

C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/WString.h:61:2: note: no known conversion for argument 1 from ‘NdefMessage’ to ‘const __FlashStringHelper*’

C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/WString.h:60:2: note: String::String(const String&)

String(const String &str);

^

C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/WString.h:60:2: note: no known conversion for argument 1 from ‘NdefMessage’ to ‘const String&’

C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/WString.h:59:2: note: String::String(const char*)

String(const char *cstr = “”);

^

C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/WString.h:59:2: note: no known conversion for argument 1 from ‘NdefMessage’ to ‘const char*’

exit status 1
no matching function for call to ‘String::String(NdefMessage)’

i just want to select the payload of what i send trough nfc to arduino to show up on the serial monitor

This makes no sense. I suggest that you try again.

You don't "send through NFC" anything. The NFC device reports what happened. It is an OUTPUT device.

You can send, or not send, anything that the NFC device says happens to the Serial Monitor application, via the serial port that the Serial instance talks to.

NdefMessage message;

So, NdefMessage is a class, and message is an instance of that class.

        String msg = NdefMessage(tag_buf, length);

The NdefMessage() part of this statement is creating an instance of the NdefMessage class. That instance can NOT be stored in an instance of the String class.

I have NO clue what the hell you are trying to do, but this is NOT how you do it.