This program demonstrates how to use a MicroNFCBoard as a peripheral to send emulate a NFC tag.

Dependencies:   MicroNFCBoardAPI mbed

Fork of MicroNFCBoardAPI_Blink by AppNearMe Official

Files at this revision

API Documentation at this revision

Comitter:
AppNearMe
Date:
Thu May 14 17:28:20 2015 +0000
Parent:
1:5b804c0c8aa8
Commit message:
Tag emulator fork

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 5b804c0c8aa8 -r 1f0b5d04ed11 main.cpp
--- a/main.cpp	Thu May 14 16:43:09 2015 +0000
+++ b/main.cpp	Thu May 14 17:28:20 2015 +0000
@@ -23,11 +23,49 @@
 
 int main() {
     nfc.init();
-    bool b = true;
-    for(int i = 0; i < 10; i++)
+
+    //Start polling
+    while(true)
     {
-        nfc.setLeds(b, !b);
-        wait_ms(200);
-        b = !b;
+        if( !nfc.connected() )
+        {
+            printf("Writing message\r\n");
+            nfc.writeNdefText("en", "AppNearMe");
+        }
+
+        printf("Poll\r\n");
+        nfc.startPolling(false, true, false);
+
+        while( nfc.polling() );
+
+        if( nfc.type4Emulator() )
+        {
+            printf("Emulating type 4 tag\r\n");
+        }
+        else
+        {
+          continue;
+        }
+
+        bool ndefRead = false;
+        while( nfc.connected() || nfc.polling() )
+        {
+            if( !ndefRead && nfc.ndefPresent() )
+            {
+                printf("Got message\r\n");
+                char buf[512];
+                if( nfc.readNdefUri(buf, sizeof(buf)) )
+                {
+                  printf("Got URI: %s\r\n", buf);
+                }
+                if( nfc.readNdefText(buf, sizeof(buf)) )
+                {
+                  printf("Got Text: %s\r\n", buf);
+                }
+                ndefRead = true;
+            }
+        }
+
+        printf("Disconnected\r\n");
     }
 }