Demonstration of possible usage of the the NFCController class.
NFC SmartPoster example
Demonstration of possible usage of the the NFCController class.
The application creates a smart poster record and sends it when a connected peer requests it. The smart poster record generated contains:
- A URI: https://www.mbed.com
- A title: "mbed website"
- An action: EXECUTE which asks the peer to open the URI.
Running the application
Verification of the sample application can be seen on any a smartphone with an NFC reader. After running you will be able to read the tag with an NFC tag reader application.
Information about activity is also printed over the serial connection - please have a client open. You may use:
Tera Term - https://ttssh2.osdn.jp/index.html.en
This example is known to work on boards connected to a PN512 shield.
Diff: main.cpp
- Revision:
- 1:6c82b777db0b
- Parent:
- 0:9a16c3f036b0
--- a/main.cpp Mon Sep 24 17:09:42 2018 +0100 +++ b/main.cpp Wed Sep 26 15:01:02 2018 +0100 @@ -103,15 +103,10 @@ /* ------------------------------------------------------------------------ * Implementation of NFCRemoteInitiator::Delegate */ - virtual void on_connected() - { - printf("Connected\r\n"); - } + virtual void on_connected() { } virtual void on_disconnected() { - printf("Disconnected\r\n"); - // reset the state of the remote initiator _nfc_remote_initiator->set_delegate(NULL); _nfc_remote_initiator.reset(); @@ -120,15 +115,10 @@ _nfc_controller.start_discovery(); } - virtual void parse_ndef_message(const Span<const uint8_t> &buffer) - { - printf("Received an ndef message of size %d\r\n", buffer.size()); - } + virtual void parse_ndef_message(const Span<const uint8_t> &buffer) { } virtual size_t build_ndef_message(const Span<uint8_t> &buffer) { - printf("Building SmartPoster message\r\n"); - // build the smart poster object we want to send SmartPoster smart_poster( URI(URI::HTTPS_WWW, span_from_cstr("mbed.com")) @@ -151,7 +141,6 @@ */ virtual void on_discovery_terminated(nfc_discovery_terminated_reason_t reason) { - printf("Discovery terminated: %u\r\n", reason); if(reason != nfc_discovery_terminated_completed) { _nfc_controller.start_discovery(); } @@ -159,8 +148,6 @@ virtual void on_nfc_initiator_discovered(const SharedPtr<NFCRemoteInitiator> &nfc_initiator) { - printf("Initiator discovered\r\n"); - // setup the local remote initiator _nfc_remote_initiator = nfc_initiator; _nfc_remote_initiator->set_delegate(this);