Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
en:iot:examples:nfc [2020/07/20 11:26] – external edit 127.0.0.1en:iot:examples:nfc [2024/06/21 15:41] (current) karllall
Line 12: Line 12:
  
 Needed libraries: Needed libraries:
-<code>lib_deps = ITTIoT@1.0.5, Adafruit PN532</code>+<code>lib_deps = ITTIoT, Adafruit PN532</code>
  
 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 "NFC" topic + * This example will publish to "NFC" topic
  *  *
  * Created 19 Nov 2019  * Created 19 Nov 2019
 + * Modified by Lars Briedis 17 June 2024
  */  */
  
Line 28: Line 30:
 #include <ittiot.h> #include <ittiot.h>
 #include <Adafruit_PN532.h> #include <Adafruit_PN532.h>
 +  
 +#define WIFI_NAME "name" 
 +#define WIFI_PASSWORD "password" 
 + 
 //Define pins for communication with the NFC reader //Define pins for communication with the NFC reader
- 
 #define PN532_SCK  D5 #define PN532_SCK  D5
 #define PN532_MOSI D7 #define PN532_MOSI D7
 #define PN532_SS   D3 #define PN532_SS   D3
 #define PN532_MISO D6 #define PN532_MISO D6
 + 
 //Setup Adafruit PN532 library //Setup Adafruit PN532 library
 Adafruit_PN532 nfc(PN532_SCK, PN532_MISO, PN532_MOSI, PN532_SS); Adafruit_PN532 nfc(PN532_SCK, PN532_MISO, PN532_MOSI, PN532_SS);
- + 
 void iot_connected() void iot_connected()
 { {
   Serial.println("MQTT connected callback");   Serial.println("MQTT connected callback");
-  iot.log("IoT NFC example!");+  Serial.println("IoT NFC example!");
 } }
- +  
-void setup() { +void setup() 
- +{
-  #ifndef ESP8266 +
-  while (!Serial); // for Leonardo/Micro/Zero +
-  #endif+
   Serial.begin(115200);   Serial.begin(115200);
   Serial.println("Booting");   Serial.println("Booting");
-  iot.printConfig(); // print json config to serial //Peale Serial.begin ja enne iot.setup +  
-  iot.setup(); +  //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();   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();+  //iot.handle();
   success = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, uid, &uidLength, 1000); // Card reading function   success = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, uid, &uidLength, 1000); // Card reading function
 + 
   if (success)   if (success)
   {   {
-    //Concatenate card ID  +    //Concatenate card ID 
-    for(int i = 0; i < uidLength;i++){ +    for(int i = 0; i < uidLength;i++) 
-    String(uid[i]).toCharArray(buf,10); +    
-    strcat(str, buf);+      String(uid[i]).toCharArray(buf,10); 
 +      strcat(str, buf);
     }     }
-    iot.publishMsg("NFC", str); // Publish card ID to topic "NFC"+    //iot.publishMsg("NFC", str); // Publish card ID to topic "NFC" 
 +     
 +    Serial.println(str);
     delay(1000);     delay(1000);
   }   }
 } }
 +
 </code> </code>
  
  
en/iot/examples/nfc.1595244384.txt.gz · Last modified: 2020/07/20 09: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