This program demonstrates how to use a MicroNFCBoard as a peripheral to receive a message from a phone/tablet using P2P/SNEP/Android Beam.
Dependencies: MicroNFCBoardAPI mbed
Fork of MicroNFCBoardAPI_P2P_Server by
Revision 2:37d78773f875, committed 2015-05-14
- Comitter:
- AppNearMe
- Date:
- Thu May 14 17:24:49 2015 +0000
- Parent:
- 1:5b804c0c8aa8
- Commit message:
- P2P Server fork
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r 5b804c0c8aa8 -r 37d78773f875 main.cpp --- a/main.cpp Thu May 14 16:43:09 2015 +0000 +++ b/main.cpp Thu May 14 17:24:49 2015 +0000 @@ -23,11 +23,43 @@ 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; + printf("Poll\r\n"); + nfc.startPolling(false, false, true); + + while( nfc.polling() ); + + if( nfc.p2p() ) + { + printf("Connected in P2P mode\r\n"); + } + else + { + continue; + } + + bool ndefRead = false; + while( nfc.connected() ) + { + if( !ndefRead && nfc.ndefPresent() ) + { + printf("Received 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"); } }