system
December 23, 2014, 3:55pm
1
hi everyone,
iam using the seedstudio v2 nfc board and i only want to select the payload of what i send trough nfc to arduino to show up on the serial monitor. (Tag emulation)
this is my 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];
//////////////////////////////
const int led = 13;
String content = "";
char character;
void setup()
{
Serial.begin(9600);
Serial.println("------- Emulate Tag --------");
pinMode(led, OUTPUT);
nfc.init();
}
void loop(){
// start emulation (blocks)
nfc.emulate();
if(nfc.writeOccured()){
digitalWrite(led, HIGH);
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);
}
currently i get this is my serial monitor:
////////////////////////////////////////////////////
Write occured !
NDEF Message 1 record, 16 bytes
NDEF Record
TNF 0x1 Well Known
Type Length 0x1 1
Payload Length 0xC 12
Type 54 T
Payload 02 65 6E 6F 6E 6C 79 20 74 68 69 73 .only this <-- thats the only thing i want to show in the serial monitor
Record is 16 bytes
////////////////////////////////////////////////////////
things i tried to select the payload: indexof(), msg.substring() and tried this (stackoverflow)
i hope you guys can help me out a bit, would really appreciate it
system
December 23, 2014, 11:15pm
2
Links to the libraries you are using would be good.
testmaniac:
hi everyone,
iam using the seedstudio v2 nfc board and i only want to select the payload of what i send trough nfc to arduino to show up on the serial monitor. (Tag emulation)
::::SNIP::::
things i tried to select the payload: indexof(), msg.substring() and tried this (stackoverflow)
i hope you guys can help me out a bit, would really appreciate it
The easiest way is to change it to a String object.
References:
The Arduino programming language Reference, organized into Functions, Variable and Constant, and Structure keywords.
The Arduino programming language Reference, organized into Functions, Variable and Constant, and Structure keywords.
This should work. If it does not, I'll be happy to help.
Change from:
NdefMessage msg = NdefMessage(tag_buf, length);
msg.print();
to:
String msg = NdefMessage(tag_buf, length);
indx = msg.indexOf('Payload');
if (indx != -1) {
payload = msg.substring(indx)
Serial.println(payload);
}
It's work ??? Because me not work..
when i change
"NdefMessage msg = NdefMessage(tag_buf, length);
msg.print(); "
to
" String msg = NdefMessage(tag_buf, length);
indx = msg.indexOf('Payload');
if (indx != -1) {
payload = msg.substring(indx)
Serial.println(payload);
}"
there is a problem :
C:\Users\Thierry\Desktop\emulation\emulation.ino:34:21: warning: character constant too long for its type [enabled by default]
indx = msg.indexOf('Payload');
^
C:\Users\Thierry\Desktop\emulation\emulation.ino: In function 'void loop()':
emulation:33: error: conversion from 'NdefMessage' to non-scalar type 'String' requested
String msg = NdefMessage(tag_buf, length);
^
emulation:34: error: 'indx' was not declared in this scope
indx = msg.indexOf('Payload');
^
C:\Users\Thierry\Desktop\emulation\emulation.ino:34:30: warning: overflow in implicit constant conversion [-Woverflow]
indx = msg.indexOf('Payload');
^
emulation:36: error: 'payload' was not declared in this scope
payload = msg.substring(indx)
^
emulation:37: error: expected ';' before 'Serial'
Serial.println(payload);
^
exit status 1
conversion from 'NdefMessage' to non-scalar type 'String' requested
do u have an answer ? Can u read the only payload ?
system
April 28, 2016, 3:42pm
6
do u have an answer ?
Do not do things that do not make sense. You can NOT assign an instance of NdefMessage to a String.
YOU must look at the NdefMessage class and figure out how to print (or save) just the portion you want.