NFC näidis

SCK → 4
MISO → 5
MOSI → 6
SS → 13
VCC → 8
GND → 15

Vajaminevad teegid:

lib_deps = ITTIoT, Adafruit PN532

Näidiskood laeb kaardi olemasolu puhul kaardi ID mqtt serverisse:

/*
 * IoT NFC example
 *
 * This example will publish to "NFC" topic
 *
 * Created 19 Nov 2019
 */
#include <Arduino.h>
#include <ittiot.h>
#include <Adafruit_PN532.h>
 
#define WIFI_NAME "name"
#define WIFI_PASSWORD "password"
 
//Define pins for communication with the NFC reader
#define PN532_SCK  D5
#define PN532_MOSI D7
#define PN532_SS   D3
#define PN532_MISO D6
 
//Setup Adafruit PN532 library
Adafruit_PN532 nfc(PN532_SCK, PN532_MISO, PN532_MOSI, PN532_SS);
 
void iot_connected()
{
  Serial.println("MQTT connected callback");
  iot.log("IoT NFC example!");
}
 
void setup()
{
  Serial.begin(115200);
  Serial.println("Booting");
 
  //iot.setConfig("wname", WIFI_NAME);
  //iot.setConfig("wpass", WIFI_PASSWORD);  
  iot.printConfig(); // print json config to serial //Peale Serial.begin ja enne iot.setup
  iot.setup();
 
  nfc.begin();
  uint32_t versiondata = nfc.getFirmwareVersion();
  if (! versiondata) {
    Serial.println("Didn't find PN53x board");
    while (1);
  }
  nfc.SAMConfig();
}
 
void loop()
{
  boolean success;
  uint8_t uid[] = { 0, 0, 0, 0, 0, 0, 0 };
  uint8_t uidLength;
  char buf[10];
  char str[70] = "";
 
  iot.handle();
  success = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, uid, &uidLength, 1000); // Card reading function
 
  if (success)
  {
    //Concatenate card ID
    for(int i = 0; i < uidLength;i++)
    {
      String(uid[i]).toCharArray(buf,10);
      strcat(str, buf);
    }
    iot.publishMsg("NFC", str); // Publish card ID to topic "NFC"
    delay(1000);
  }
}
et/iot/examples/nfc.txt · Last modified: 2023/01/28 10:00 (external edit)
CC Attribution-Share Alike 4.0 International
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0