I have a NFC handheld sensor device, which data I want to read out with my PN532 shield with Arduino.
Unfortunately I was not able to read out the data, at least the relevant information for me. I guess this is the NDEF message.
When I read out the handheld device with my smart phone I'll get this output with all the relevant information I need:
▪▪ DATA ▪▪
Date Time,Oechsle [deg] ,Brix [%] ,Temp [degC]
2019/09/28 11:19:22, -1, -0.2, 23.7
2019/09/28 11:19:30, -1, -0.2, 23.7
2019/09/28 11:19:41, -1, -0.1, 23.7
▪▪ FORMAT ▪▪
NFC Well Known (0x01)
Defined by RFC 2141, RFC 3986
▪▪ TYPE ▪▪
T
▪▪ PAYLOAD (4888 bytes) ▪▪
0x02 0x65 0x6E 0x44 0x61 0x74 0x65 0x20 0x54 0x69 0x6D 0x65 0x2C 0x4F 0x65 0x63 0x68 0x73 0x6C 0x65 0x20 0x5B 0x64 0x65 0x67 0x5D 0x20 0x20 0x20 0x20 0x20 0x20 0x20 0x20 0x20 0x20 0x20 0x20 0x20 0x20 0x20 0x20 0x20 0x2C 0x42 0x72 0x69 0x78 0x20 0x5B 0x25 0x5D 0x20 0x20 0x20 0x20 0x20 0x20 0x20 0x20 0x20 0x20 0x20 0x20 0x20 0x20 0x20 0x20 0x20 0x20 0x20 0x20 0x20 0x20 0x2C 0x54 0x65 0x6D 0x70 0x20 0x5B 0x64 0x65 0x67 0x43 0x5D 0x0D 0x0A 0x32 0x30 0x31 0x39 0x2F 0x30 0x39 0x2F 0x32 0x38 0x20 0x31 0x31 0x3A 0x31 0x38 0x3A 0x32 0x30 0x2C 0x20 0x20 0x20 0x20 0x20 0x20 0x2D 0x31 0x2C 0x20 0x20 0x20 0x20 0x2D 0x30 0x2E 0x32 0x2C 0x20 0x20 0x20 0x20 0x32 0x33 0x2E 0x37 0x0D 0x0A 0x32 0x30 0x31 0x39 0x2F 0x30 0x39 0x2F 0x32 0x38 0x20 0x31 0x31 0x3A 0x31 0x39 0x3A 0x30 0x33 0x2C 0x20 0x20 0x20 0x20 0x20 0x20 0x2D 0x31 0x2C 0x20 0x20 0x20 0x20 0x2D 0x30 0x2E 0x32 0x2C 0x20 0x20 0x20 0x20 0x32 0x33 0x2E 0x37 0x0D 0x0A 0x32 0x30 0x31 0x39 0x2F 0x30 0x39 0x2F 0x32 0x38 0x20 0x31 0x31 0x3A 0x31 0x39 0x3A 0x31 0x33 0x2C 0x20 0x20 0x20 0x20 0x20 0x20 0x2D 0x31 0x2C 0x20 0x20 0x20 0x20 0x2D 0x30 0x2E 0x32 0x2C 0x20 0x20 0x20 0x20 0x32 0x33 0x2E 0x37 0x0D 0x0A 0x32 0x30 0x31 0x39 0x2F 0x30 0x39 0x2F 0x32 0x38 0x20 0x31 0x31 0x3A 0x31 0x39 0x3A 0x32 0x32 0x2C 0x20 0x20 0x20 0x20 0x20 0x20 0x2D 0x31 0x2C 0x20 0x20 0x20 0x20 0x2D 0x30 0x2E 0x32 0x2C 0x20 0x20 0x20 0x20 0x32 0x33 0x2E 0x37 0x0D 0x0A 0x32 0x30 0x31 0x39 0x2F 0x30 0x39 0x2F 0x32 0x38 0x20 0x31 0x31 0x3A 0x31 0x39 0x3A 0x33 0x30 0x2C 0x20 0x20 0x20 0x20 0x20 0x20 0x2D 0x31 0x2C 0x20 0x20 0x20 0x20 0x2D 0x30 0x2E 0x32 0x2C 0x20 0x20 0x20 0x20 0x32 0x33 0x2E 0x37 0x0D 0x0A 0x32 0x30 0x31 0x39 0x2F 0x30 0x39 0x2F 0x32 0x38 0x20 0x31 0x31 0x3A 0x31 0x39 0x3A 0x34 0x31 0x2C 0x20 0x20 0x20 0x20 0x20 0x20 0x2D 0x31 0x2C 0x20 0x20 0x20 0x20 0x2D 0x30 0x2E 0x31 0x2C 0x20 0x20 0x20 0x20 0x32 0x33 0x2E 0x37 0x0D 0x0A 0x32 0x30 0x31 0x39 0x2F 0x31 0x30 0x2F 0x30 0x37 0x20 0x32 0x31 0x3A 0x35 0x31 0x3A 0x30 0x31 0x2C 0x4C 0x4C 0x4C 0x20 0x20 0x20 0x20 0x20 0x2C 0x4C 0x4C 0x4C 0x20 0x20 0x20 0x20 0x20 0x2C 0x20 0x20 0x20 0x20 0x32 0x34 0x2E 0x30 0x0D 0x0A 0x32 0x30 0x31 0x39 0x2F 0x31 0x30 0x2F 0x30 0x37 0x20 0x32 0x31 0x3A 0x35 0x32 0x3A 0x31 0x30 0x2C 0x4C 0x4C 0x4C 0x20 0x20 0x20 0x20 0x20 0x2C 0x4C 0x4C 0x4C 0x20 0x20 0x20 0x20 0x20 0x2C 0x20 0x20 0x20 0x20 0x32 0x34 0x2E 0x32 0x0D 0x0A 0x32 0x30 0x31 0x39 0x2F 0x31 0x30 0x2F 0x30 0x37 0x20 0x32 0x31 0x3A 0x35 0x32 0x3A 0x32 0x32 0x2C 0x4C 0x4C 0x4C 0x20 0x20 0x20 0x20 0x20 0x2C 0x4C 0x4C 0x4C 0x20 0x20 0x20 0x20 0x20 0x2C 0x20 0x20 0x20 0x20 0x32 0x34 0x2E 0x32 0x0D 0x0A 0x32 0x30 0x31 0x39 0x2F 0x31 0x30 0x2F 0x30 0x37 0x20 0x32 0x31 0x3A 0x35 0x32 0x3A 0x33 0x32 0x2C 0x4C 0x4C 0x4C 0x20 0x20 0x20 0x20 0x20 0x2C 0x4C 0x4C 0x4C 0x20 0x20 0x20 0x20 0x20 0x2C 0x20 0x20 0x20 0x20 0x32 0x34 0x2E 0x32 0x0D 0x0A 0x32 0x30 0x31 0x39 0x2F 0x31 0x30 0x2F 0x30 0x37 0x20 0x32 0x31 0x3A 0x35 0x32 0x3A 0x34 0x33 0x2C 0x4C 0x4C 0x4C 0x20 0x20 0x20 0x20 0x20 0x2C 0x4C 0x4C 0x4C 0x20 0x20 0x20 0x20 0x20 0x2C 0x20 0x20 0x20 0x20 0x32 0x34 0x2E 0x32 0x0D 0x0A 0x32 0x30 0x31 0x39 0x2F 0x31 0x30 0x2F 0x31 0x32 0x20 0x31 0x31 0x3A 0x31 0x31 0x3A 0x34 0x30 0x2C 0x4C 0x4C 0x4C 0x20 0x20 0x20 0x20 0x20 0x2C 0x4C 0x4C 0x4C 0x20 0x20 0x20 0x20 0x20 0x2C 0x20 0x20 0x20 0x20 0x32 0x33 0x2E 0x37 0x0D 0x0A 0x32 0x30 0x31 0x39 0x2F 0x31 0x30 0x2F 0x31 0x32 0x20 0x31 0x31 0x3A 0x31 0x37 0x3A 0x30 0x30 0x2C 0x4C 0x4C 0x4C 0x20 0x20 0x20 0x20 0x20 0x2C 0x4C 0x4C 0x4C 0x20 0x20 0x20 0x20 0x20 0x2C 0x20 0x20 0x20 0x20 0x32 0x34 0x2E 0x36 0x0D 0x0A 0x32 0x30 0x31 0x39 0x2F 0x31 0x31 0x2F 0x31 0x36 0x20 0x31 0x39 0x3A 0x35 0x39 0x3A 0x30 0x36 0x2C 0x4C 0x4C 0x4C 0x20 0x20 0x20 0x20 0x20 0x2C 0x4C 0x4C 0x4C 0x20 0x20 0x20 0x20 0x20 0x2C 0x20 0x20 0x20 0x20 0x32 0x34 0x2E 0x39 0x0D 0x0A 0x32 0x30 0x31 0x39 0x2F 0x31 0x31 0x2F 0x32 0x32 0x20 0x32 0x30 0x3A 0x34 0x38 0x3A 0x35 0x35 0x2C 0x4C 0x4C 0x4C 0x20 0x20 0x20 0x20 0x20 0x2C 0x4C 0x4C 0x4C 0x20 0x20 0x20 0x20 0x20 0x2C 0x20 0x20 0x20 0x20 0x32 0x34 0x2E 0x39 0x0D 0x0A 0x32 0x30 0x31 0x39 0x2F 0x31 0x31 0x2F 0x32 0x32 0x20 0x32 0x30 0x3A 0x35 0x38 0x3A 0x33 0x37 0x2C 0x4C 0x4C 0x4C 0x20 0x20 0x20 0x20 0x20 0x2C 0x4C 0x4C 0x4C 0x20 0x20 0x20 0x20 0x20 0x2C 0x20 0x20 0x20 0x20 0x32 0x35 0x2E 0x31 0x0D 0x0A 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
<there are some more 0x00>
▪▪ PAYLOAD (UTF8) ▪▪
enDate Time,Oechsle [deg] ,Brix [%] ,Temp [degC] 2019/09/28 11:18:20, -1, -0.2, 23.7 2019/09/28 11:19:03, -1, -0.2, 23.7 2019/09/28 11:19:13, -1, -0.2, 23.7 2019/09/28 11:19:22, -1, -0.2, 23.7 2019/09/28 11:19:30, -1, -0.2, 23.7 2019/09/28 11:19:41, -1, -0.1, 23.7 2019/10/07 21:51:01,LLL ,LLL , 24.0 2019/10/07 21:52:10,LLL ,LLL , 24.2 2019/10/07 21:52:22,LLL ,LLL , 24.2 2019/10/07 21:52:32,LLL ,LLL , 24.2 2019/10/07 21:52:43,LLL ,LLL , 24.2 2019/10/12 11:11:40,LLL ,LLL , 23.7 2019/10/12 11:17:00,LLL ,LLL , 24.6 2019/11/16 19:59:06,LLL ,LLL , 24.9 2019/11/22 20:48:55,LLL ,LLL , 24.9 2019/11/22 20:58:37,LLL ,LLL , 25.1
My Arduino runs with this example code from "all about circuits". With the examples from the PN532 Library from Adafruit I was not successful.
[code]#include <Wire.h>
#include <PN532_I2C.h>
#include <PN532.h> // The following files are included in the libraries Installed
#include <NfcAdapter.h>
PN532_I2C pn532_i2c(Wire);
NfcAdapter nfc = NfcAdapter(pn532_i2c); // Indicates the Shield you are using
void setup(void) {
Serial.begin(9600);
Serial.println("NFC TAG READER"); // Header used when using the serial monitor
nfc.begin();
}
void loop(void) {
Serial.println("\nScan your NFC tag on the NFC Shield\n"); // Command so that you an others will know what to do
if (nfc.tagPresent())
{
NfcTag tag = nfc.read();
Serial.print("Nachricht: ");
tag.print();
Serial.println(tag.getTagType());
Serial.print("UID: ");Serial.println(tag.getUidString()); // Retrieves the Unique Identification from your tag
if (tag.hasNdefMessage()) // If your tag has a message
{
NdefMessage message = tag.getNdefMessage();
Serial.print("\nThis Message in this Tag is ");
Serial.print(message.getRecordCount());
Serial.print(" NFC Tag Record");
if (message.getRecordCount() != 1) {
Serial.print("s");
}
Serial.println(".");
// If you have more than 1 Message then it wil cycle through them
int recordCount = message.getRecordCount();
for (int i = 0; i < recordCount; i++)
{
Serial.print("\nNDEF Record ");Serial.println(i+1);
NdefRecord record = message.getRecord(i);
int payloadLength = record.getPayloadLength();
byte payload[payloadLength];
record.getPayload(payload);
String payloadAsString = ""; // Processes the message as a string vs as a HEX value
for (int c = 0; c < payloadLength; c++) {
payloadAsString += (char)payload[c];
}
Serial.print(" Information (as String): ");
Serial.println(payloadAsString);
String uid = record.getId();
if (uid != "") {
Serial.print(" ID: ");Serial.println(uid); // Prints the Unique Identification of the NFC Tag
}
}
}
}
delay(10000);
}
The output over the serial monitor is as follows:
Scan your NFC tag on the NFC Shield
Nachricht: NFC Tag - NFC Forum Type 2
UID 02 84 66 6D 9E 27 FE
NDEF Message 1 record, 3 bytes
NDEF Record
TNF 0x0 Empty
Type Length 0x0 0
Payload Length 0x0 0
Type
Payload
Record is 3 bytes
NFC Forum Type 2
UID: 02 84 66 6D 9E 27 FE
This Message in this Tag is 1 NFC Tag Record.
NDEF Record 1
Information (as String):
As you can see, the message will not be shown.
Any Help?