This program demonstrates how to use a MicroNFCBoard as a peripheral to send a message to a phone/tablet using P2P/SNEP/Android Beam.
Dependencies: MicroNFCBoardAPI mbed
Fork of MicroNFCBoardAPI_P2P_Client by
Diff: main.cpp
- Revision:
- 2:6c08a3907187
- Parent:
- 1:5b804c0c8aa8
--- a/main.cpp Thu May 14 16:43:09 2015 +0000 +++ b/main.cpp Thu May 14 17:22:32 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; + 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 ndefMessageWritten = false; + bool ndefWritingStarted = false; + while( nfc.connected() ) + { + if( !ndefMessageWritten && nfc.ndefWriteable() ) + { + printf("SNEP Push\r\n"); + nfc.writeNdefUri("http://www.micronfcboard.com"); + nfc.ndefWrite(); + ndefWritingStarted = true; + } + if( ndefWritingStarted && !ndefMessageWritten && !nfc.ndefBusy() ) + { + ndefMessageWritten = true; + if( nfc.ndefSuccess() ) + { + printf("Push successful\r\n"); + } + else + { + printf("Push failed\r\n"); + } + } + } + + printf("Disconnected\r\n"); } }