Skip to content

Latest commit

 

History

History
1889 lines (1315 loc) · 30.9 KB

API.md

File metadata and controls

1889 lines (1315 loc) · 30.9 KB

Electroniccats_PN7150 API Reference

The Electroniccats_PN7150 class enables Arduino library for I2C access to the PN7150 RFID/Near Field Communication chip.

Class: Electroniccats_PN7150

Include and instantiate the Electroniccats_PN7150 class. Creates a global NFC device interface object, attached to pins 7 (IRQ) and 8 (VEN) and using the default I2C address 0x28

#include <Electroniccats_PN7150.h>

Electroniccats_PN7150 nfc(PN7150_IRQ, PN7150_VEN, PN7150_ADDR);
  • uint8_t PN7150_IRQ: IRQ pin for data interrupt.
  • uint8_t PN7150_VEN: "Reset" or "Enable" pin for device.
  • uint8_t PN7150_ADDR: Hexadecimal address for device, default 0x28 .

Example

#include "Electroniccats_PN7150.h"
#define PN7150_IRQ   (8)
#define PN7150_VEN   (7)
#define PN7150_ADDR  (0x28)

Electroniccats_PN7150 nfc(PN7150_IRQ, PN7150_VEN, PN7150_ADDR); // Creates a global NFC device interface object, attached to pins 7 (IRQ) and 8 (VEN) and using the default I2C address 0x28

void setup(){ 
  Serial.begin(115200);
  while(!Serial);
  Serial.println("Detect NFC readers with PN7150");
  uint8_t statusNFC = setupNFC();
  if (!statusNFC) 
    Serial.println("Set up is ok");
  else
    Serial.println("Error while setting up mode, check connections!");
}

int setupNFC(){
  Serial.println("Initializing...");
  int setupOK = nfc.connectNCI();                     // Wake up the board
  if (!setupOK){
    setupOK = nfc.configMode();                       // Set up the configuration mode
    if (!setupOK) setupOK = nfc.startDiscovery();     // NCI Discovery mode
  }
  return setupOK;
}

Electroniccats_PN7150 Methods

Method: getFirmwareVersion

Get the firmware version of the NXP-NCI controller.

int getFirmwareVersion();

Example

int version = nfc.getFirmwareVersion();

Method: connectNCI

Initialize the connection with the NXP-NCI controller and updates the firmware version that can be obtained with the getFirmwareVersion method.

uint8_t connectNCI();

Returns 0 if the connection is established correctly, otherwise returns 1.

Example

uint8_t statusNFC = nfc.connectNCI();

if (!statusNFC) {
  Serial.println("Set up is ok");
} else {
  Serial.println("Error while setting up mode, check connections!");
}

Method: configMode

Configure the device mode. Reader/Writer as default.

uint8_t configMode();

Returns 0 if the mode is configured correctly, otherwise returns 1.

Example

uint8_t status = nfc.configMode();

if (!status) {
  Serial.println("Set up is ok");
} else {
  Serial.println("Error while setting up mode, check connections!");
}

Method: setReaderWriterMode

Configure the device mode to Reader/Writer.

bool setReaderWriterMode();

Returns true if the mode is configured correctly, otherwise returns false.

Example

bool status = nfc.setReaderWriterMode();

if (status) {
  Serial.println("Set up is ok");
} else {
  Serial.println("Error while setting up mode, check connections!");
}

Method: setEmulationMode

Configure the device mode to Card Emulation.

bool setEmulationMode();

Returns true if the mode is configured correctly, otherwise returns false.

Example

bool status = nfc.setEmulationMode();

if (status) {
  Serial.println("Set up is ok");
} else {
  Serial.println("Error while setting up mode, check connections!");
}

Method: setP2PMode

Configure the device mode to Peer to Peer.

bool setP2PMode();

Returns true if the mode is configured correctly, otherwise returns false.

Example

bool status = nfc.setP2PMode();

if (status) {
  Serial.println("Set up is ok");
} else {
  Serial.println("Error while setting up mode, check connections!");
}

Method: getMode

Get the current device mode.

int getMode();

Example

switch (nfc.getMode()) {
  case nfc.mode.READER_WRITER:
    Serial.println("Reader/Writer mode");
    break;
  case nfc.mode.EMULATION:
    Serial.println("Card Emulation mode");
    break;
  case nfc.mode.P2P:
    Serial.println("Peer to Peer mode");
    break;
  default:
    Serial.println("Unknown mode");
    break;
}

Method: configureSettings

Configure some aspects of the NFC controller, such as the hardware configuration, RF (radio frequency) configuration, and other settings.

bool configureSettings();

A custom NFC UID can be configured by passing the UID and its length as parameters.

bool configureSettings(uint8_t *nfcuid, uint8_t uidlen);

Returns 0 if the parameters are configured correctly, otherwise returns 1.

Example 1

bool status = nfc.configureSettings();

if (!status) {
  Serial.println("Set up is ok");
} else {
  Serial.println("Error while setting up mode, check connections!");
}

Example 2

uint8_t nfcuid[] = {0x08, 0x00, 0x00, 0x00, 0x00, 0x00};
uint8_t uidlen = 6;

bool status = nfc.configureSettings(nfcuid, uidlen);

if (!status) {
  Serial.println("Set up is ok");
} else {
  Serial.println("Error while setting up mode, check connections!");
}

Method: startDiscovery

Start the discovery mode for the device.

uint8_t startDiscovery();

Returns 0 if the mode is configured correctly, otherwise returns 1.

Example

uint8_t status = nfc.startDiscovery();

if (!status) {
  Serial.println("Set up is ok");
} else {
  Serial.println("Error while setting up mode, check connections!");
}

Methods: stopDiscovery

Stop the discovery process of the device.

bool stopDiscovery();

Returns 0. Never returns 1.

Example

nfc.stopDiscovery();

Method: isTagDetected

Returns true if a tag is detected, otherwise returns false. The timeout is set to 500ms by default and can be changed by passing a parameter.

bool isTagDetected(uint16_t tout = 500);

Example

if (nfc.isTagDetected()) {
  Serial.println("Tag detected!");
  // Do something
}

Method: cardModeSend

Send a data packet in card mode.

bool cardModeSend(unsigned char *pData, unsigned char DataSize);

Method: cardModeReceive

Receive a data packet from a card.

bool cardModeReceive(unsigned char *pData, unsigned char *pDataSize);

Method: handleCardEmulation

Resets the card emulation state and processes the card mode for card emulation.

void handleCardEmulation();

Method: waitForTagRemoval

Waits for the tag to be removed.

void waitForTagRemoval();

Example

if (nfc.isTagDetected()) {
  Serial.println("Remove the Card");
  nfc.waitForTagRemoval();
  Serial.println("Card removed!");
}

Method: readerTagCmd

Sends a command to the reader.

bool readerTagCmd(unsigned char *pCommand, unsigned char CommandSize, unsigned char *pAnswer, unsigned char *pAnswerSize);

Method: readerReActivate

Reactivates a target after it has been deactivated.

bool readerReActivate();

Method: activateNextTagDiscovery

Activates the next tag discovered.

bool activateNextTagDiscovery();

Example

if (nfc.isTagDetected()) {
  // It can detect multiple cards at the same time if they use the same protocol
  if (nfc.remoteDevice.hasMoreTags()) {
    Serial.println("Multiple cards are detected!");
    nfc.activateNextTagDiscovery();
  }
}

Method: readNdefMessage

Reads the NDEF message from the tag.

void readNdefMessage();

Example

if (nfc.isTagDetected()) {
  nfc.readNdefMessage();
}

Method: writeNdefMessage

Writes the NDEF message to the tag.

void writeNdefMessage();

Method: nciFactoryTestPrbs

Performs a factory test for the NCI controller.

bool nciFactoryTestPrbs(NxpNci_TechType_t type, NxpNci_Bitrate_t bitrate);

Method: nciFactoryTestRfOn

Performs a factory test for the NCI controller.

bool nciFactoryTestRfOn();

Method: reset

Stops the discovery process, configures the device mode if it is necessary and starts the discovery process again.

bool reset();

Example

nfc.reset();

Method: setReadMsgCallback

Registers a callback function to be called when an NDEF message is received.

void setReadMsgCallback(CustomCallback_t function);

Example

void messageReceived() {
  Serial.println("Message received!");
}

void setup() {
  nfc.setReadMsgCallback(messageReceived);
}

Method: isReaderDetected

Returns true if a reader is detected, otherwise returns false.

bool isReaderDetected();

Example

if (nfc.isReaderDetected()) {
  Serial.println("Reader detected!");
  // Do something
}

Method: closeCommunication

Send a command to the reader to close the communication.

void closeCommunication();

Example

if (nfc.isReaderDetected()) {
  Serial.println("Reader detected!");
  nfc.handleCardEmulation();
  nfc.closeCommunication();
}

Method: sendMessage

Send an NDEF message to the reader.

void sendMessage();

Example

if (nfc.isReaderDetected()) {
  Serial.println("Reader detected!");
  Serial.println("Sending NDEF message...");
  nfc.sendMessage();
}

Class Interface

Constant UNDETERMINED

Constant for the undetermined interface.

UNDETERMINED = 0x0

Example

nfc.interface.UNDETERMINED;

Constant FRAME

Constant for the frame interface.

FRAME = 0x1

Example

nfc.interface.FRAME;

Constant ISODEP

Constant for the ISO-DEP interface.

ISODEP = 0x2

Example

nfc.interface.ISODEP;

Constant NFCDEP

Constant for the NFC-DEP interface.

NFCDEP = 0x3

Example

nfc.interface.NFCDEP;

Constant TAGCMD

Constant for the tag interface.

TAGCMD = 0x80

Example

nfc.interface.TAGCMD;

Class Mode

Constant READER_WRITER

Constant for the Reader/Writer mode.

READER_WRITER = 1

Example

nfc.mode.READER_WRITER;

Constant EMULATION

Constant for the Card Emulation mode.

EMULATION = 2

Example

nfc.mode.EMULATION;

Constant P2P

Constant for the Peer to Peer mode.

P2P = 3

Example

nfc.mode.P2P;

Class ModeTech

Constant POLL

Constant for the Poll mode.

POLL = 0x00

Example

nfc.modeTech.POLL;

Constant LISTEN

Constant for the Listen mode.

LISTEN = 0x80

Example

nfc.modeTech.LISTEN;

Constant MASK

Constant for the Mask mode.

MASK = 0xF0

Example

nfc.modeTech.MASK;

Class Protocol

Constant UNDETERMINED

Constant for the undetermined protocol.

UNDETERMINED = 0x0

Example

nfc.protocol.UNDETERMINED;

Constant T1T

Constant for the T1T protocol.

T1T = 0x1

Example

nfc.protocol.T1T;

Constant T2T

Constant for the T2T protocol.

T2T = 0x2

Example

nfc.protocol.T2T;

Constant T3T

Constant for the T3T protocol.

T3T = 0x3

Example

nfc.protocol.T3T;

Constant ISODEP

Constant for the ISO-DEP protocol.

ISODEP = 0x4

Example

nfc.protocol.ISODEP;

Constant NFCDEP

Constant for the NFC-DEP protocol.

NFCDEP = 0x5

Example

nfc.protocol.NFCDEP;

Constant ISO15693

Constant for the ISO15693 protocol.

ISO15693 = 0x6

Example

nfc.protocol.ISO15693;

Constant MIFARE

Constant for the MIFARE protocol.

MIFARE = 0x80

Example

nfc.protocol.MIFARE;

Class Tech

Constant PASSIVE_NFCA

Constant for the Passive NFC-A technology.

PASSIVE_NFCA = 0

Example

nfc.tech.PASSIVE_NFCA;

Constant PASSIVE_NFCB

Constant for the Passive NFC-B technology.

PASSIVE_NFCB = 1

Example

nfc.tech.PASSIVE_NFCB;

Constant PASSIVE_NFCF

Constant for the Passive NFC-F technology.

PASSIVE_NFCF = 2

Example

nfc.tech.PASSIVE_NFCF;

Constant ACTIVE_NFCA

Constant for the Active NFC-A technology.

ACTIVE_NFCA = 3

Example

nfc.tech.ACTIVE_NFCA;

Constant ACTIVE_NFCF

Constant for the Active NFC-F technology.

ACTIVE_NFCF = 5

Example

nfc.tech.ACTIVE_NFCF;

Constant PASSIVE_15693

Constant for the Passive 15693 technology.

PASSIVE_15693 = 6

Example

nfc.tech.PASSIVE_15693;

Constant PASSIVE_NFCV

Constant for the Passive NFC-V technology (ISO 15693).

PASSIVE_NFCV = 6

Example

nfc.tech.PASSIVE_NFCV;

Class RemoteDevice

A RemoteDevice object represents a remote NFC device such as a tag or a reader.

Getters for device properties

Method: getInterface

Get the interface of the device.

unsigned char getInterface() const;

Example

if (nfc.isTagDetected()) {
  Serial.print("Interface: ");
  switch (nfc.remoteDevice.getInterface()) {
    case nfc.interface.ISODEP:
      Serial.println("ISO-DEP");
      break;
    case nfc.interface.NFCDEP:
      Serial.println("NFC-DEP");
      break;
    case nfc.interface.TAGCMD:
      Serial.println("TAG");
      break;
    case nfc.interface.FRAME:
      Serial.println("FRAME");
      break;
    case nfc.interface.UNDETERMINED:
      Serial.println("UNDETERMINED");
      break;
    default:
      Serial.println("UNKNOWN");
      break;
  }
}

Method: getProtocol

Get the protocol of the device.

unsigned char getProtocol() const;

Example

if (nfc.isTagDetected()) {
  Serial.print("Protocol: ");
  switch (nfc.remoteDevice.getProtocol()) {
    case nfc.protocol.T1T:
      Serial.println("T1T");
      break;
    case nfc.protocol.T2T:
      Serial.println("T2T");
      break;
    case nfc.protocol.T3T:
      Serial.println("T3T");
      break;
    case nfc.protocol.ISODEP:
      Serial.println("ISO-DEP");
      break;
    case nfc.protocol.NFCDEP:
      Serial.println("NFC-DEP");
      break;
    case nfc.protocol.ISO15693:
      Serial.println("ISO15693");
      break;
    case nfc.protocol.MIFARE:
      Serial.println("MIFARE");
      break;
    case nfc.protocol.UNDETERMINED:
      Serial.println("UNDETERMINED");
      break;
    default:
      Serial.println("UNKNOWN");
      break;
  }
}

Method: getModeTech

Get the mode tech of the device.

unsigned char getModeTech() const;

Example

if (nfc.isTagDetected()) {
  Serial.print("Technology: ");
  switch (nfc.remoteDevice.getModeTech()) {
    case nfc.tech.PASSIVE_NFCA:
      Serial.println("PASSIVE NFC A");
      break;
    case nfc.tech.PASSIVE_NFCB:
      Serial.println("PASSIVE NFC B");
      break;
    case nfc.tech.PASSIVE_NFCF:
      Serial.println("PASSIVE NFC F");
      break;
    case nfc.tech.PASSIVE_15693:
      Serial.println("PASSIVE 15693");
      break;
  }
}

Method: hasMoreTags

Returns true if there are more tags to be discovered, otherwise returns false.

bool hasMoreTags() const;

Example

if (nfc.isTagDetected()) {
  if (nfc.remoteDevice.hasMoreTags()) {
    Serial.println("Multiple cards are detected!");
    nfc.activateNextTagDiscovery();
  }
}

Getters for device information properties

Method: getSensResLen

Get the SENS RES length of the device.

unsigned char getSensResLen() const;

Method: getSensRes

Get the SENS RES (ATQA) of the device. Only available for tags that use passive communication and the NFC-A, NFC-B or NFC-F technologies, otherwise returns NULL.

const unsigned char* getSensRes() const;

Example

if (nfc.isTagDetected()) {
  Serial.print("ATQA: ");
  for (int i = 0; i < nfc.remoteDevice.getSensResLen(); i++) {
    Serial.print(nfc.remoteDevice.getSensRes()[i], HEX);
    Serial.print(" ");
  }
  Serial.println();
}

Method: getSelResLen

Get the SEL RES length of the device.

unsigned char getSelResLen() const;

Method: getSelRes

Get the SEL RES (SAK) of the device. Only available for tags that use passive communication and the NFC-A technology, otherwise returns NULL.

const unsigned char* getSelRes() const;

Example

if (nfc.isTagDetected()) {
  Serial.print("SAK: ");
  for (int i = 0; i < nfc.remoteDevice.getSelResLen(); i++) {
    Serial.print(nfc.remoteDevice.getSelRes()[i], HEX);
    Serial.print(" ");
  }
  Serial.println();
}

Method: getNFCIDLen

Get the NFCID length of the device.

unsigned char getNFCIDLen() const;

Method: getNFCID

Get the NFCID of the device. Only available for tags that use passive communication and the NFC-A technology, otherwise returns NULL.

const unsigned char* getNFCID() const;

Example

if (nfc.isTagDetected()) {
  Serial.print("NFCID: ");
  for (int i = 0; i < nfc.remoteDevice.getNFCIDLen(); i++) {
    Serial.print(nfc.remoteDevice.getNFCID()[i], HEX);
    Serial.print(" ");
  }
  Serial.println();
}

Method: getRatsLen

Get the RATS length of the device.

unsigned char getRatsLen() const;

Method: getRats

Get the RATS of the device. Only available for tags that use passive communication and the NFC-A technology, otherwise returns NULL.

const unsigned char* getRats() const;

Example

if (nfc.isTagDetected()) {
  Serial.print("RATS: ");
  for (int i = 0; i < nfc.remoteDevice.getRatsLen(); i++) {
    Serial.print(nfc.remoteDevice.getRats()[i], HEX);
    Serial.print(" ");
  }
  Serial.println();
}

Method: getAttribResLen

Get the ATTRIB RES length of the device.

unsigned char getAttribResLen() const;

Method: getAttribRes

Get the ATTRIB RES of the device. Only available for tags that use passive communication and the NFC-B technology, otherwise returns NULL.

const unsigned char* getAttribRes() const;

Example

if (nfc.isTagDetected()) {
  Serial.print("ATTRIB RES: ");
  for (int i = 0; i < nfc.remoteDevice.getAttribResLen(); i++) {
    Serial.print(nfc.remoteDevice.getAttribRes()[i], HEX);
    Serial.print(" ");
  }
  Serial.println();
}

Method: getBitRate

Get the bit rate of the device. Only available for tags that use passive communication and the NFC-F technology, otherwise returns NULL.

unsigned char getBitRate() const;

Example

Serial.print("Bitrate = ");
Serial.println((nfc.remoteDevice.getBitRate() == 1) ? "212" : "424");

Method: getAFI

Get the AFI of the device. Only available for tags that use passive communication and the NFC-V technology, otherwise returns NULL.

unsigned char getAFI() const;

Example

if (nfc.isTagDetected()) {
  Serial.print("AFI = ");
  Serial.println(nfc.remoteDevice.getAFI());
}

Method: getDSFID

Get the DSF ID of the device. Only available for tags that use passive communication and the NFC-V technology, otherwise returns NULL.

unsigned char getDSFID() const;

Example

if (nfc.isTagDetected()) {
  Serial.print("DSF ID = ");
  Serial.println(nfc.remoteDevice.getDSFID(), HEX);
}

Method: getID

Get the ID of the device. Only available for tags that use passive communication and the NFC-V technology, otherwise returns NULL.

const unsigned char* getID() const;

Example

if (nfc.isTagDetected()) {
  Serial.print("ID: ");
  for (int i = 0; i < sizeof(nfc.remoteDevice.getID()); i++) {
    Serial.print(nfc.remoteDevice.getID()[i], HEX);
    Serial.print(" ");
  }
  Serial.println();
}

Class NdefMessage

A NdefMessage object represents an NDEF message. An NDEF message is a container for one or more NDEF records.

Method: begin

Registers a callback function to be called when an NDEF message is received wich updates the message content.

void begin();

Example

NdefMessage message;

void setup() {
  message.begin();
}

Method: getContentLength

Get the content length of the message.

static unsigned short getContentLength();

Method: getContent

Get the content of the message.

static unsigned char *getContent();

Method: setContent

Set the content of the message.

static void setContent(unsigned char *content, unsigned short contentLength);

Method: getRecord

Get the record of the message.

NdefRecord_t getRecord();

The record is a structure that contains the following properties:

typedef struct {
  NdefRecordType_e recordType;
  unsigned char *recordPayload;
  unsigned int recordPayloadLength;
} NdefRecord_t;

Example

message.getRecord();

Method: isEmpty

Returns true if the message is empty, otherwise returns false.

bool isEmpty();

Example

if (message.isEmpty()) {
  Serial.println("The message is empty!");
}

Method: isNotEmpty

Returns true if the message is not empty, otherwise returns false.

bool isNotEmpty();

Example

if (message.isNotEmpty()) {
  Serial.println("The message is not empty!");
}

Method: hasRecord

Returns true if the message has a record, otherwise returns false.

bool hasRecord();

Example

if (message.hasRecord()) {
  Serial.println("The message has a record!");
}

Method: addTextRecord

Adds a text record to the message.

void addTextRecord(String text);
void addTextRecord(String text, String languageCode);

Example 1

message.addTextRecord("Hello");  // English by default

Example 2

// English explicitly, the library only supports two letter language codes (ISO 639-1) by now
message.addTextRecord("world", "en");

Method: addUriRecord

Adds a URI record to the message.

void addUriRecord(String uri);

Example

message.addUriRecord("https://www.electroniccats.com/");

See URI prefixes for a list of all the prefixes that can be used.

Method: addMimeMediaRecord

Adds a MIME media record to the message.

void addMimeMediaRecord(String mimeType, const char *payload, unsigned short payloadLength);

Example

message.addMimeMediaRecord("text/plain", "Hello world!", 12);  // 12 is the payload length

Method: addWiFiRecord

Adds a WiFi record to the message.

void addWiFiRecord(String ssid, String authenticationType, String encryptionType, String password);

Example

String ssid = "Bomber Cat";
String authentificationType = "WPA2 PERSONAL";
String encryptionType = "AES";
String password = "Password";
message.addWiFiRecord(ssid, authentificationType, encryptionType, password);

See WiFi authentication types and WiFi encryption types for a list of all the types that can be used.

Class NdefRecord

A NdefRecord object represents an NDEF record. An NDEF record is a data structure that contains data that is stored or transported in an NDEF message.

Example

NdefRecord record;

Method: create

Creates a new NDEF record.

void create(NdefRecord_t record);

Example

record.create(message.getRecord());

Method: isEmpty

Returns true if the record is empty, otherwise returns false.

bool isEmpty();

Example

if (record.isEmpty()) {
  Serial.println("The record is empty!");
}

Method: isNotEmpty

Returns true if the record is not empty, otherwise returns false.

bool isNotEmpty();

Example

if (record.isNotEmpty()) {
  Serial.println("The record is not empty!");
}

Method: getType

Get the type of the record.

NdefRecordType_e getType();

The type is a structure that contains the following properties:

typedef enum {
  WELL_KNOWN_SIMPLE_TEXT,
  WELL_KNOWN_SIMPLE_URI,
  WELL_KNOWN_SMART_POSTER,
  WELL_KNOWN_HANDOVER_SELECT,
  WELL_KNOWN_HANDOVER_REQUEST,
  WELL_KNOWN_ALTERNATIVE_CARRIER,
  WELL_KNOWN_COLLISION_RESOLUTION,
  MEDIA_VCARD,
  MEDIA_HANDOVER_WIFI,
  MEDIA_HANDOVER_BT,
  MEDIA_HANDOVER_BLE,
  MEDIA_HANDOVER_BLE_SECURE,
  ABSOLUTE_URI,
  UNSUPPORTED_NDEF_RECORD = 0xFF
} NdefRecordType_e;

Method: getPayloadLength

Get the payload length of the record.

unsigned short getPayloadLength();

Method: getPayload

Get the payload of the record.

unsigned char *getPayload();

Example

Serial.print("Payload: ");
for (int i = 0; i < record.getPayloadLength(); i++) {
  Serial.print(record.getPayload()[i], HEX);
  Serial.print(" ");
}
Serial.println();

Method: getText

Get the text of the record if the type is WELL_KNOWN_SIMPLE_TEXT, otherwise returns "null".

String getText();

Example

Serial.print("Text: ");
Serial.println(record.getText());

Method: getBluetoothName

Get the Bluetooth name of the record if the type is MEDIA_HANDOVER_BT, otherwise returns "null".

String getBluetoothName();

Example

Serial.print("Bluetooth name: ");
Serial.println(record.getBluetoothName());

Method: getBluetoothAddress

Get the Bluetooth address of the record if the type is MEDIA_HANDOVER_BT, otherwise returns "null".

String getBluetoothAddress();

Example

Serial.print("Bluetooth address: ");
Serial.println(record.getBluetoothAddress());

Method: getWifiSSID

Get the WiFi SSID of the record if the type is MEDIA_HANDOVER_WIFI, otherwise returns "null".

String getWifiSSID();

Example

Serial.print("WiFi SSID: ");
Serial.println(record.getWifiSSID());

Method: getWifiPassword

Get the WiFi password of the record if the type is MEDIA_HANDOVER_WIFI, otherwise returns "null".

String getWiFiPassword();

Example

Serial.print("WiFi password: ");
Serial.println(record.getWiFiPassword());

Method: getWiFiAuthenticationType

Get the WiFi authentication type of the record if the type is MEDIA_HANDOVER_WIFI, otherwise returns "null".

String getWiFiAuthenticationType();

Example

Serial.print("WiFi authentication type: ");
Serial.println(record.getWiFiAuthenticationType());

Method: getWiFiEncryptionType

Get the WiFi encryption type of the record if the type is MEDIA_HANDOVER_WIFI, otherwise returns "null".

String getWiFiEncryptionType();

Example

Serial.print("WiFi encryption type: ");
Serial.println(record.getWiFiEncryptionType());

Method: getVCardContent

Get the vCard content of the record if the type is MEDIA_VCARD, otherwise returns "null".

String getVCardContent();

Example

Serial.print("vCard content: ");
Serial.println(record.getVCardContent());

Method: getUri

Get the URI of the record if the type is WELL_KNOWN_SIMPLE_URI, otherwise returns "null".

String getUri();

Example

Serial.print("URI: ");
Serial.println(record.getUri());

Method: setPayload

Set the payload of the record.

void setPayload(String payload);
void setPayload(const char *payload, unsigned short payloadLength);

Example 1

record.setPayload("Hello world!");

Example 2

record.setPayload("Hello world!", 12);

Method: setPayloadLength

Set the payload length of the record.

void setPayloadLength(uint8_t payloadLength);

Example

record.setPayloadLength(12);

Method: setHeaderFlags

Set the header flags of the record.

void setHeaderFlags(uint8_t headerFlags);

Example

record.setHeaderFlags(0x00);

Method: setTypeLength

Set the type length of the record.

void setTypeLength(uint8_t typeLength);

Example

record.setTypeLength(0x00);

Method: setRecordType

Set the record type of the record.

void setRecordType(uint8_t wellKnownType);
void setRecordType(String type);

Example 1

record.setRecordType(NDEF_TEXT_RECORD_TYPE);

Example 2

record.setRecordType("application/vnd.wfa.wsc");

Method: setStatus

Set the status of the record.

void setStatus(uint8_t status);

Example

record.setStatus(NDEF_STATUS);

Method: setLanguageCode

Set the language code of the record.

void setLanguageCode(String languageCode);

Example

record.setLanguageCode("en");

Method: getContentLength

Get the content length of the record.

unsigned short getContentLength();

Example

Serial.print("Content length: ");
Serial.println(record.getContentLength());

Method: getContent

Get the content of the record.

const char *getContent();

Example

Serial.print("Content: ");
for (int i = 0; i < record.getContentLength(); i++) {
  Serial.print(record.getContent()[i], HEX);
  Serial.print(" ");
}
Serial.println();

Appendix

URI prefixes

Here is a list of all the prefixes that can be used with the addUriRecord method.

Prefix Meaning
0x00 No prepending is done, the URI is encoded in its entirety in the record payload
0x01 http://www.
0x02 https://www.
0x03 http://
0x04 https://
0x05 tel:
0x06 mailto:
0x07 ftp://anonymous:anonymous@
0x08 ftp://ftp.
0x09 ftps://
0x0A sftp://
0x0B smb://
0x0C nfs://
0x0D ftp://
0x0E dav://
0x0F news:
0x10 telnet://
0x11 imap:
0x12 rtsp:
0x13 urn:
0x14 pop:
0x15 sip:
0x16 sips:
0x17 tftp:
0x18 btspp://
0x19 btl2cap://
0x1A btgoep://
0x1B tcpobex://
0x1C irdaobex://
0x1D file://
0x1E urn:epc:id:
0x1F urn:epc:tag:
0x20 urn:epc:pat:
0x21 urn:epc:raw:
0x22 urn:epc:
0x23 urn:nfc:

WiFi authentication types

Here is a list of all the authentication types that can be used with the addWiFiRecord method.

Authentication type Meaning
"OPEN" Open
"WPA PERSONAL" WPA Personal
"SHARED" Shared
"WPA ENTERPRISE" WPA Enterprise
"WPA2 ENTERPRISE" WPA2 Enterprise
"WPA2 PERSONAL" WPA2 Personal

Any other value will be interpreted as UNKNOWN.

WiFi encryption types

Here is a list of all the encryption types that can be used with the addWiFiRecord method.

Encryption type Meaning
"NONE" None
"WEP" WEP
"TKIP" TKIP
"AES" AES

Any other value will be interpreted as UNKNOWN.