This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| en:iot:examples:nfc [2019/11/22 13:25] – timothy_r | en:iot:examples:nfc [2024/06/21 15:41] (current) – karllall | ||
|---|---|---|---|
| Line 2: | Line 2: | ||
| {{: | {{: | ||
| {{: | {{: | ||
| - | {{: | + | {{: |
| SCK -> 4 \\ | SCK -> 4 \\ | ||
| Line 12: | Line 12: | ||
| Needed libraries: | Needed libraries: | ||
| - | < | + | < |
| The code below will upload card ID to mqtt server, when a card is present. | The code below will upload card ID to mqtt server, when a card is present. | ||
| <code c> | <code c> | ||
| + | |||
| /* | /* | ||
| * IoT NFC example | * IoT NFC example | ||
| * | * | ||
| - | * This example will publish to " | + | * This example will publish to " |
| * | * | ||
| * Created 19 Nov 2019 | * Created 19 Nov 2019 | ||
| + | * Modified by Lars Briedis 17 June 2024 | ||
| */ | */ | ||
| Line 28: | Line 30: | ||
| #include < | #include < | ||
| #include < | #include < | ||
| + | |||
| + | #define WIFI_NAME " | ||
| + | #define WIFI_PASSWORD " | ||
| + | |||
| //Define pins for communication with the NFC reader | //Define pins for communication with the NFC reader | ||
| - | |||
| #define PN532_SCK | #define PN532_SCK | ||
| #define PN532_MOSI D7 | #define PN532_MOSI D7 | ||
| #define PN532_SS | #define PN532_SS | ||
| #define PN532_MISO D6 | #define PN532_MISO D6 | ||
| + | |||
| //Setup Adafruit PN532 library | //Setup Adafruit PN532 library | ||
| Adafruit_PN532 nfc(PN532_SCK, | Adafruit_PN532 nfc(PN532_SCK, | ||
| - | + | ||
| void iot_connected() | void iot_connected() | ||
| { | { | ||
| Serial.println(" | Serial.println(" | ||
| - | | + | |
| } | } | ||
| - | + | ||
| - | void setup() { | + | void setup() |
| - | + | { | |
| - | #ifndef ESP8266 | + | |
| - | while (!Serial); // for Leonardo/ | + | |
| - | #endif | + | |
| Serial.begin(115200); | Serial.begin(115200); | ||
| Serial.println(" | Serial.println(" | ||
| - | | + | |
| - | iot.setup(); | + | // |
| + | // | ||
| + | //iot.printConfig(); | ||
| + | | ||
| + | |||
| nfc.begin(); | nfc.begin(); | ||
| uint32_t versiondata = nfc.getFirmwareVersion(); | uint32_t versiondata = nfc.getFirmwareVersion(); | ||
| Line 63: | Line 66: | ||
| } | } | ||
| nfc.SAMConfig(); | nfc.SAMConfig(); | ||
| - | } | ||
| + | } | ||
| + | |||
| void loop() | void loop() | ||
| { | { | ||
| Line 72: | Line 76: | ||
| char buf[10]; | char buf[10]; | ||
| char str[70] = ""; | char str[70] = ""; | ||
| - | + | ||
| - | iot.handle(); | + | |
| success = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, | success = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, | ||
| + | |||
| if (success) | if (success) | ||
| { | { | ||
| - | // | + | // |
| - | for(int i = 0; i < uidLength; | + | for(int i = 0; i < uidLength; |
| - | String(uid[i]).toCharArray(buf, | + | |
| - | strcat(str, buf); | + | |
| + | strcat(str, buf); | ||
| } | } | ||
| - | iot.publishMsg(" | + | |
| + | |||
| + | Serial.println(str); | ||
| delay(1000); | delay(1000); | ||
| } | } | ||
| + | } | ||
| + | |||
| </ | </ | ||