簡體   English   中英

使用 PN532 和 ArduinoMega 從 android 手機讀取 NFC UID

[英]Reading NFC UID from android phone with PN532 and ArduinoMega

我正在嘗試使用 PN532 從手機(三星 Galaxy S10)讀取我的 NFC UID,但我只收到 08 和另外 3 位隨機值。我讀到以 08 開頭的值是 RID(隨機 ID)。 是否有任何可能的方法來讀取唯一值,或使用 PN532 從我的手機 NFC 中讀取唯一值? 我想使用該值將其與我的代碼中的常量進行比較,並向繼電器發送一個脈沖以打開一扇門。 此代碼來自 da Adafruit_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 用於任何安全目的,因為您可以看到手機出於隱私目的確實會隨機提供一個。

NFC UID 僅用於幫助讀取硬件處理當多個不同標簽在范圍內時向正確卡發送數據的處理。 不能保證 UID 實際上是唯一的並且不能復制(即使使用應該在工廠對其進行編程的標簽,您也可以從中國購買克隆,最終用戶可以對其進行編程)。

如果使用電話提供唯一性以將標簽用於具有安全隱患的任何事物,則最好使用加密方法與存儲在標簽或模擬標簽上的數據。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM