使用PN532和ArduinoMega从安卓手机读取NFC UID



我正试图使用PN532从手机(三星Galaxy S10(读取我的NFC UID,但我只收到了08和另外3位随机值。我读到一个以08开头的值是一个RID(随机ID(。有没有任何可能的方法可以读取唯一的值,或者使用PN532从我的手机NFC中读取唯一的东西?我想用这个值将其与代码中的常数进行比较,并向继电器发送脉冲以打开门。此代码来自da Adafuit_PN532库。

#include <Wire.h>
#include <SPI.h>
#include <Adafruit_PN532.h>
#define PN532_IRQ   (2)
#define PN532_RESET (3)  // Not connected by default on the NFC Shield
// Or use this line for a breakout or shield with an I2C connection:
Adafruit_PN532 nfc(PN532_IRQ, PN532_RESET);
void setup(void) {
Serial.begin(115200);
Serial.println("Hello!");
nfc.begin();
uint32_t versiondata = nfc.getFirmwareVersion();
if (! versiondata) {
Serial.print("Didn't find PN53x board");
while (1); // halt
}
Serial.print("Found chip PN5"); Serial.println((versiondata >> 24) & 0xFF, HEX);
Serial.print("Firmware ver. "); Serial.print((versiondata >> 16) & 0xFF, DEC);
Serial.print('.'); Serial.println((versiondata >> 8) & 0xFF, DEC);
// configure board to read RFID tags
nfc.SAMConfig();
Serial.println("Waiting for an ISO14443A Card ...");
}

void loop(void) {
uint8_t success;
uint8_t uid[] = { 0, 0, 0, 0, 0, 0, 0 };  // Buffer to store the returned UID
uint8_t uidLength;                        // Length of the UID (4 or 7 bytes depending on ISO14443A card type)
// Wait for an ISO14443A type cards (Mifare, etc.).  When one is found
// 'uid' will be populated with the UID, and uidLength will indicate
// if the uid is 4 bytes (Mifare Classic) or 7 bytes (Mifare Ultralight)
success = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, uid, &uidLength);
if (success) {
// Display some basic information about the card
Serial.println("Found an ISO14443A card");
Serial.print("  UID Length: "); Serial.print(uidLength, DEC); Serial.println(" bytes");
Serial.print("  UID Value: ");
nfc.PrintHex(uid, uidLength);
if (uidLength == 4) {
// We probably have a Mifare Classic card ...
uint32_t cardid = uid[0];
cardid <<= 8;
cardid |= uid[1];
cardid <<= 8;
cardid |= uid[2];
cardid <<= 8;
cardid |= uid[3];
Serial.print("Seems to be a Mifare Classic card #");
Serial.println(cardid);
}
delay(2000);
}
}

请勿出于任何安全目的使用NFC UID,因为您可以看到,出于隐私目的,手机会随机提供一个UID。

NFC UID仅用于在多个不同标签在范围内时帮助读取硬件处理向正确卡发送数据的处理。无法保证UID实际上是唯一的,并且不能复制(即使使用本应在工厂编程的Tag,您也可以从中国购买克隆,最终用户可以在那里对其进行编程(。

如果使用手机提供唯一性,则最好使用加密方法将数据存储在标签或模拟标签上,以便将标签用于任何具有安全含义的内容。

相关内容

  • 没有找到相关文章

最新更新