I’m working with an ESP32 and a PN532 NFC tag reader, and I’ve successfully used the code below to read NFC tags.
However, I’d like to identify a phone (Android/iPhone) by placing it near the PN532.
I want to build an iOS/Android app that sends a same NFC data each time, as currently, Android sends a different ID every time a phone is placed near the PN532.
Is there a way, or do you have any suggestions, on how I can use a phone to send an ID or some consistent data to the PN532 so I can identify that it’s my phone and perform a specific task based on that?
I need something similar to what’s shown in this video: https://youtu.be/_kW7hPiGi2o?t=27
But I’m not sure how the phone sends the same ID. My Android phone sends a different ID each time, and my iPhone doesn’t send anything.
#include <Wire.h>
#include <PN532_I2C.h>
#include <PN532.h>
PN532_I2C pn532i2c(Wire);
PN532 nfc(pn532i2c);
void setup() {
nfc.begin();
nfc.setPassiveActivationRetries(0x02);
nfc.SAMConfig();
}
void loop() {
uint8_t uid[] = { 0, 0, 0, 0, 0, 0, 0 };
uint8_t uidLength;
if (nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, &uid[0], &uidLength, 100)) {
String hexString = "";
for (int i = 0; i < uidLength; i++) {
hexString += String(uid[i] >> 4, HEX);
hexString += String(uid[i] & 0x0F, HEX);
}
Serial.print(hexString);
}
}