Shell - NFC Bricklet

This is the description of the Shell API bindings for the NFC Bricklet. General information and technical specifications for the NFC Bricklet are summarized in its hardware description.

An installation guide for the Shell API bindings is part of their general description.

API

Possible exit codes for all tinkerforge commands are:

  • 1: interrupted (ctrl+c)
  • 2: syntax error
  • 21: Python 2.5 or newer is required
  • 22: Python argparse module is missing
  • 23: socket error
  • 24: other exception
  • 25: invalid placeholder in format string
  • 26: authentication error
  • 201: timeout occurred
  • 209: invalid argument value
  • 210: function is not supported
  • 211: unknown error

Command Structure

The common options of the call and dispatch commands are documented here. The specific command structure is shown below.

tinkerforge call nfc-bricklet [<option>..] <uid> <function> [<argument>..]
Parameters:
  • <uid> – Type: String
  • <function> – Type: String

The call command is used to call a function of the NFC Bricklet. It can take several options:

  • --help shows help for the specific call command and exits
  • --list-functions shows a list of known functions of the NFC Bricklet and exits
tinkerforge dispatch nfc-bricklet [<option>..] <uid> <callback>
Parameters:
  • <uid> – Type: String
  • <callback> – Type: String

The dispatch command is used to dispatch a callback of the NFC Bricklet. It can take several options:

  • --help shows help for the specific dispatch command and exits
  • --list-callbacks shows a list of known callbacks of the NFC Bricklet and exits
tinkerforge call nfc-bricklet <uid> <function> [<option>..] [<argument>..]
Parameters:
  • <uid> – Type: String
  • <function> – Type: String

The <function> to be called can take different options depending of its kind. All functions can take the following options:

  • --help shows help for the specific function and exits

Getter functions can take the following options:

  • --execute <command> shell command line to execute for each incoming response (see section about output formatting for details)

Setter functions can take the following options:

  • --expect-response requests response and waits for it

The --expect-response option for setter functions allows to detect timeouts and other error conditions calls of setters as well. The device will then send a response for this purpose. If this option is not given for a setter function then no response is sent and errors are silently ignored, because they cannot be detected.

tinkerforge dispatch nfc-bricklet <uid> <callback> [<option>..]
Parameters:
  • <uid> – Type: String
  • <callback> – Type: String

The <callback> to be dispatched can take several options:

  • --help shows help for the specific callback and exits
  • --execute <command> shell command line to execute for each incoming response (see section about output formatting for details)

Basic Functions

tinkerforge call nfc-bricklet <uid> set-mode <mode>
Parameters:
  • <mode> – Type: Int, Range: See symbols, Default: 0
Output:
  • no output

Sets the mode. The NFC Bricklet supports four modes:

  • Off
  • Card Emulation (Cardemu): Emulates a tag for other readers
  • Peer to Peer (P2P): Exchange data with other readers
  • Reader: Reads and writes tags
  • Simple: Automatically reads tag IDs

If you change a mode, the Bricklet will reconfigure the hardware for this mode. Therefore, you can only use functions corresponding to the current mode. For example, in Reader mode you can only use Reader functions.

The following symbols are available for this function:

For <mode>:

  • mode-off = 0
  • mode-cardemu = 1
  • mode-p2p = 2
  • mode-reader = 3
  • mode-simple = 4
tinkerforge call nfc-bricklet <uid> get-mode
Output:
  • mode – Type: Int, Range: See symbols, Default: 0

Returns the mode as set by set-mode.

The following symbols are available for this function:

For mode:

  • mode-off = 0
  • mode-cardemu = 1
  • mode-p2p = 2
  • mode-reader = 3
  • mode-simple = 4
tinkerforge call nfc-bricklet <uid> reader-request-tag-id
Output:
  • no output

After you call reader-request-tag-id the NFC Bricklet will try to read the tag ID from the tag. After this process is done the state will change. You can either register the reader-state-changed callback or you can poll reader-get-state to find out about the state change.

If the state changes to ReaderRequestTagIDError it means that either there was no tag present or that the tag has an incompatible type. If the state changes to ReaderRequestTagIDReady it means that a compatible tag was found and that the tag ID has been saved. You can now read out the tag ID by calling reader-get-tag-id.

If two tags are in the proximity of the NFC Bricklet, this function will cycle through the tags. To select a specific tag you have to call reader-request-tag-id until the correct tag ID is found.

In case of any ReaderError state the selection is lost and you have to start again by calling reader-request-tag-id.

tinkerforge call nfc-bricklet <uid> reader-get-tag-id
Output:
  • tag-type – Type: Int, Range: See symbols
  • tag-id – Type: Int Array, Length: variable, Range: [0 to 255]

Returns the tag type and the tag ID. This function can only be called if the NFC Bricklet is currently in one of the ReaderReady states. The returned tag ID is the tag ID that was saved through the last call of reader-request-tag-id.

To get the tag ID of a tag the approach is as follows:

  1. Call reader-request-tag-id
  2. Wait for state to change to ReaderRequestTagIDReady (see reader-get-state or reader-state-changed callback)
  3. Call reader-get-tag-id

The following symbols are available for this function:

For tag-type:

  • tag-type-mifare-classic = 0
  • tag-type-type1 = 1
  • tag-type-type2 = 2
  • tag-type-type3 = 3
  • tag-type-type4 = 4
tinkerforge call nfc-bricklet <uid> reader-get-state
Output:
  • state – Type: Int, Range: See symbols
  • idle – Type: Bool

Returns the current reader state of the NFC Bricklet.

On startup the Bricklet will be in the ReaderInitialization state. The initialization will only take about 20ms. After that it changes to ReaderIdle.

The Bricklet is also reinitialized if the mode is changed, see set-mode.

The functions of this Bricklet can be called in the ReaderIdle state and all of the ReaderReady and ReaderError states.

Example: If you call reader-request-page, the state will change to ReaderRequestPage until the reading of the page is finished. Then it will change to either ReaderRequestPageReady if it worked or to ReaderRequestPageError if it didn't. If the request worked you can get the page by calling reader-read-page.

The same approach is used analogously for the other API functions.

The following symbols are available for this function:

For state:

  • reader-state-initialization = 0
  • reader-state-idle = 128
  • reader-state-error = 192
  • reader-state-request-tag-id = 2
  • reader-state-request-tag-id-ready = 130
  • reader-state-request-tag-id-error = 194
  • reader-state-authenticate-mifare-classic-page = 3
  • reader-state-authenticate-mifare-classic-page-ready = 131
  • reader-state-authenticate-mifare-classic-page-error = 195
  • reader-state-write-page = 4
  • reader-state-write-page-ready = 132
  • reader-state-write-page-error = 196
  • reader-state-request-page = 5
  • reader-state-request-page-ready = 133
  • reader-state-request-page-error = 197
  • reader-state-write-ndef = 6
  • reader-state-write-ndef-ready = 134
  • reader-state-write-ndef-error = 198
  • reader-state-request-ndef = 7
  • reader-state-request-ndef-ready = 135
  • reader-state-request-ndef-error = 199
tinkerforge call nfc-bricklet <uid> reader-write-ndef <ndef>
Parameters:
  • <ndef> – Type: Int Array, Length: variable, Range: [0 to 255]
Output:
  • no output

Writes NDEF formated data.

This function currently supports NFC Forum Type 2 and 4.

The general approach for writing a NDEF message is as follows:

  1. Call reader-request-tag-id
  2. Wait for state to change to ReaderRequestTagIDReady (see reader-get-state or reader-state-changed callback)
  3. If looking for a specific tag then call reader-get-tag-id and check if the expected tag was found, if it was not found got back to step 1
  4. Call reader-write-ndef with the NDEF message that you want to write
  5. Wait for state to change to ReaderWriteNDEFReady (see reader-get-state or reader-state-changed callback)
tinkerforge call nfc-bricklet <uid> reader-request-ndef
Output:
  • no output

Reads NDEF formated data from a tag.

This function currently supports NFC Forum Type 1, 2, 3 and 4.

The general approach for reading a NDEF message is as follows:

  1. Call reader-request-tag-id
  2. Wait for state to change to RequestTagIDReady (see reader-get-state or reader-state-changed callback)
  3. If looking for a specific tag then call reader-get-tag-id and check if the expected tag was found, if it was not found got back to step 1
  4. Call reader-request-ndef
  5. Wait for state to change to ReaderRequestNDEFReady (see reader-get-state or reader-state-changed callback)
  6. Call reader-read-ndef to retrieve the NDEF message from the buffer
tinkerforge call nfc-bricklet <uid> reader-read-ndef
Output:
  • ndef – Type: Int Array, Length: variable, Range: [0 to 255]

Returns the NDEF data from an internal buffer. To fill the buffer with a NDEF message you have to call reader-request-ndef beforehand.

tinkerforge call nfc-bricklet <uid> reader-authenticate-mifare-classic-page <page> <key-number> <key>
Parameters:
  • <page> – Type: Int, Range: [0 to 216 - 1]
  • <key-number> – Type: Int, Range: See symbols
  • <key> – Type: Int Array, Length: 6, Range: [0 to 255]
Output:
  • no output

Mifare Classic tags use authentication. If you want to read from or write to a Mifare Classic page you have to authenticate it beforehand. Each page can be authenticated with two keys: A (key_number = 0) and B (key_number = 1). A new Mifare Classic tag that has not yet been written to can be accessed with key A and the default key [0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF].

The approach to read or write a Mifare Classic page is as follows:

  1. Call reader-request-tag-id
  2. Wait for state to change to ReaderRequestTagIDReady (see reader-get-state or reader-state-changed callback)
  3. If looking for a specific tag then call reader-get-tag-id and check if the expected tag was found, if it was not found got back to step 1
  4. Call reader-authenticate-mifare-classic-page with page and key for the page
  5. Wait for state to change to ReaderAuthenticatingMifareClassicPageReady (see reader-get-state or reader-state-changed callback)
  6. Call reader-request-page or reader-write-page to read/write page

The authentication will always work for one whole sector (4 pages).

The following symbols are available for this function:

For <key-number>:

  • key-a = 0
  • key-b = 1
tinkerforge call nfc-bricklet <uid> reader-write-page <page> <data>
Parameters:
  • <page> – Type: Int, Range: See symbols
  • <data> – Type: Int Array, Length: variable, Range: [0 to 255]
Output:
  • no output

Writes a maximum of 8192 bytes starting from the given page. How many pages are written depends on the tag type. The page sizes are as follows:

  • Mifare Classic page size: 16 byte
  • NFC Forum Type 1 page size: 8 byte
  • NFC Forum Type 2 page size: 4 byte
  • NFC Forum Type 3 page size: 16 byte
  • NFC Forum Type 4: No pages, page = file selection (CC or NDEF, see below)

The general approach for writing to a tag is as follows:

  1. Call reader-request-tag-id
  2. Wait for state to change to ReaderRequestTagIDReady (see reader-get-state or reader-state-changed callback)
  3. If looking for a specific tag then call reader-get-tag-id and check if the expected tag was found, if it was not found got back to step 1
  4. Call reader-write-page with page number and data
  5. Wait for state to change to ReaderWritePageReady (see reader-get-state or reader-state-changed callback)

If you use a Mifare Classic tag you have to authenticate a page before you can write to it. See reader-authenticate-mifare-classic-page.

NFC Forum Type 4 tags are not organized into pages but different files. We currently support two files: Capability Container file (CC) and NDEF file.

Choose CC by setting page to 3 or NDEF by setting page to 4.

The following symbols are available for this function:

For <page>:

  • reader-write-type4-capability-container = 3
  • reader-write-type4-ndef = 4
tinkerforge call nfc-bricklet <uid> reader-request-page <page> <length>
Parameters:
  • <page> – Type: Int, Range: See symbols
  • <length> – Type: Int, Range: [0 to 213]
Output:
  • no output

Reads a maximum of 8192 bytes starting from the given page and stores them into a buffer. The buffer can then be read out with reader-read-page. How many pages are read depends on the tag type. The page sizes are as follows:

  • Mifare Classic page size: 16 byte
  • NFC Forum Type 1 page size: 8 byte
  • NFC Forum Type 2 page size: 4 byte
  • NFC Forum Type 3 page size: 16 byte
  • NFC Forum Type 4: No pages, page = file selection (CC or NDEF, see below)

The general approach for reading a tag is as follows:

  1. Call reader-request-tag-id
  2. Wait for state to change to RequestTagIDReady (see reader-get-state or reader-state-changed callback)
  3. If looking for a specific tag then call reader-get-tag-id and check if the expected tag was found, if it was not found got back to step 1
  4. Call reader-request-page with page number
  5. Wait for state to change to ReaderRequestPageReady (see reader-get-state or reader-state-changed callback)
  6. Call reader-read-page to retrieve the page from the buffer

If you use a Mifare Classic tag you have to authenticate a page before you can read it. See reader-authenticate-mifare-classic-page.

NFC Forum Type 4 tags are not organized into pages but different files. We currently support two files: Capability Container file (CC) and NDEF file.

Choose CC by setting page to 3 or NDEF by setting page to 4.

The following symbols are available for this function:

For <page>:

  • reader-request-type4-capability-container = 3
  • reader-request-type4-ndef = 4
tinkerforge call nfc-bricklet <uid> reader-read-page
Output:
  • data – Type: Int Array, Length: variable, Range: [0 to 255]

Returns the page data from an internal buffer. To fill the buffer with specific pages you have to call reader-request-page beforehand.

tinkerforge call nfc-bricklet <uid> cardemu-get-state
Output:
  • state – Type: Int, Range: See symbols
  • idle – Type: Bool

Returns the current cardemu state of the NFC Bricklet.

On startup the Bricklet will be in the CardemuInitialization state. The initialization will only take about 20ms. After that it changes to CardemuIdle.

The Bricklet is also reinitialized if the mode is changed, see set-mode.

The functions of this Bricklet can be called in the CardemuIdle state and all of the CardemuReady and CardemuError states.

Example: If you call cardemu-start-discovery, the state will change to CardemuDiscover until the discovery is finished. Then it will change to either CardemuDiscoverReady if it worked or to CardemuDiscoverError if it didn't.

The same approach is used analogously for the other API functions.

The following symbols are available for this function:

For state:

  • cardemu-state-initialization = 0
  • cardemu-state-idle = 128
  • cardemu-state-error = 192
  • cardemu-state-discover = 2
  • cardemu-state-discover-ready = 130
  • cardemu-state-discover-error = 194
  • cardemu-state-transfer-ndef = 3
  • cardemu-state-transfer-ndef-ready = 131
  • cardemu-state-transfer-ndef-error = 195
tinkerforge call nfc-bricklet <uid> cardemu-start-discovery
Output:
  • no output

Starts the discovery process. If you call this function while a NFC reader device is near to the NFC Bricklet the state will change from CardemuDiscovery to CardemuDiscoveryReady.

If no NFC reader device can be found or if there is an error during discovery the cardemu state will change to CardemuDiscoveryError. In this case you have to restart the discovery process.

If the cardemu state changes to CardemuDiscoveryReady you can start the NDEF message transfer with cardemu-write-ndef and cardemu-start-transfer.

tinkerforge call nfc-bricklet <uid> cardemu-write-ndef <ndef>
Parameters:
  • <ndef> – Type: Int Array, Length: variable, Range: [0 to 255]
Output:
  • no output

Writes the NDEF message that is to be transferred to the NFC peer.

The maximum supported NDEF message size in Cardemu mode is 255 byte.

You can call this function at any time in Cardemu mode. The internal buffer will not be overwritten until you call this function again or change the mode.

tinkerforge call nfc-bricklet <uid> cardemu-start-transfer <transfer>
Parameters:
  • <transfer> – Type: Int, Range: See symbols
Output:
  • no output

You can start the transfer of a NDEF message if the cardemu state is CardemuDiscoveryReady.

Before you call this function to start a write transfer, the NDEF message that is to be transferred has to be written via cardemu-write-ndef first.

After you call this function the state will change to CardemuTransferNDEF. It will change to CardemuTransferNDEFReady if the transfer was successful or CardemuTransferNDEFError if it wasn't.

The following symbols are available for this function:

For <transfer>:

  • cardemu-transfer-abort = 0
  • cardemu-transfer-write = 1
tinkerforge call nfc-bricklet <uid> p2p-get-state
Output:
  • state – Type: Int, Range: See symbols
  • idle – Type: Bool

Returns the current P2P state of the NFC Bricklet.

On startup the Bricklet will be in the P2PInitialization state. The initialization will only take about 20ms. After that it changes to P2PIdle.

The Bricklet is also reinitialized if the mode is changed, see set-mode.

The functions of this Bricklet can be called in the P2PIdle state and all of the P2PReady and P2PError states.

Example: If you call p2p-start-discovery, the state will change to P2PDiscover until the discovery is finished. Then it will change to either P2PDiscoverReady* if it worked or to P2PDiscoverError if it didn't.

The same approach is used analogously for the other API functions.

The following symbols are available for this function:

For state:

  • p2p-state-initialization = 0
  • p2p-state-idle = 128
  • p2p-state-error = 192
  • p2p-state-discover = 2
  • p2p-state-discover-ready = 130
  • p2p-state-discover-error = 194
  • p2p-state-transfer-ndef = 3
  • p2p-state-transfer-ndef-ready = 131
  • p2p-state-transfer-ndef-error = 195
tinkerforge call nfc-bricklet <uid> p2p-start-discovery
Output:
  • no output

Starts the discovery process. If you call this function while another NFC P2P enabled device is near to the NFC Bricklet the state will change from P2PDiscovery to P2PDiscoveryReady.

If no NFC P2P enabled device can be found or if there is an error during discovery the P2P state will change to P2PDiscoveryError. In this case you have to restart the discovery process.

If the P2P state changes to P2PDiscoveryReady you can start the NDEF message transfer with p2p-start-transfer.

tinkerforge call nfc-bricklet <uid> p2p-write-ndef <ndef>
Parameters:
  • <ndef> – Type: Int Array, Length: variable, Range: [0 to 255]
Output:
  • no output

Writes the NDEF message that is to be transferred to the NFC peer.

The maximum supported NDEF message size for P2P transfer is 255 byte.

You can call this function at any time in P2P mode. The internal buffer will not be overwritten until you call this function again, change the mode or use P2P to read an NDEF messages.

tinkerforge call nfc-bricklet <uid> p2p-start-transfer <transfer>
Parameters:
  • <transfer> – Type: Int, Range: See symbols
Output:
  • no output

You can start the transfer of a NDEF message if the P2P state is P2PDiscoveryReady.

Before you call this function to start a write transfer, the NDEF message that is to be transferred has to be written via p2p-write-ndef first.

After you call this function the P2P state will change to P2PTransferNDEF. It will change to P2PTransferNDEFReady if the transfer was successfull or P2PTransferNDEFError if it wasn't.

If you started a write transfer you are now done. If you started a read transfer you can now use p2p-read-ndef to read the NDEF message that was written by the NFC peer.

The following symbols are available for this function:

For <transfer>:

  • p2p-transfer-abort = 0
  • p2p-transfer-write = 1
  • p2p-transfer-read = 2
tinkerforge call nfc-bricklet <uid> p2p-read-ndef
Output:
  • ndef – Type: Int Array, Length: variable, Range: [0 to 255]

Returns the NDEF message that was written by a NFC peer in NFC P2P mode.

The NDEF message is ready if you called p2p-start-transfer with a read transfer and the P2P state changed to P2PTransferNDEFReady.

tinkerforge call nfc-bricklet <uid> simple-get-tag-id <index>
Parameters:
  • <index> – Type: Int, Range: [0 to 255]
Output:
  • tag-type – Type: Int, Range: See symbols
  • tag-id – Type: Int Array, Length: variable, Range: [0 to 255]
  • last-seen – Type: Int, Range: [0 to 232 - 1]

The following symbols are available for this function:

For tag-type:

  • tag-type-mifare-classic = 0
  • tag-type-type1 = 1
  • tag-type-type2 = 2
  • tag-type-type3 = 3
  • tag-type-type4 = 4

New in version 2.0.6 (Plugin).

Advanced Functions

tinkerforge call nfc-bricklet <uid> set-detection-led-config <config>
Parameters:
  • <config> – Type: Int, Range: See symbols, Default: 3
Output:
  • no output

Sets the detection LED configuration. By default the LED shows if a card/reader is detected.

You can also turn the LED permanently on/off or show a heartbeat.

If the Bricklet is in bootloader mode, the LED is off.

The following symbols are available for this function:

For <config>:

  • detection-led-config-off = 0
  • detection-led-config-on = 1
  • detection-led-config-show-heartbeat = 2
  • detection-led-config-show-detection = 3
tinkerforge call nfc-bricklet <uid> get-detection-led-config
Output:
  • config – Type: Int, Range: See symbols, Default: 3

Returns the configuration as set by set-detection-led-config

The following symbols are available for this function:

For config:

  • detection-led-config-off = 0
  • detection-led-config-on = 1
  • detection-led-config-show-heartbeat = 2
  • detection-led-config-show-detection = 3
tinkerforge call nfc-bricklet <uid> set-maximum-timeout <timeout>
Parameters:
  • <timeout> – Type: Int, Unit: 1 ms, Range: [0 to 216 - 1], Default: 2000
Output:
  • no output

Sets the maximum timeout.

This is a global maximum used for all internal state timeouts. The timeouts depend heavily on the used tags etc. For example: If you use a Type 2 tag and you want to detect if it is present, you have to use reader-request-tag-id and wait for the state to change to either the error state or the ready state.

With the default configuration this takes 2-3 seconds. By setting the maximum timeout to 100ms you can reduce this time to ~150-200ms. For Type 2 this would also still work with a 20ms timeout (a Type 2 tag answers usually within 10ms). A type 4 tag can take up to 500ms in our tests.

If you need a fast response time to discover if a tag is present or not you can find a good timeout value by trial and error for your specific tag.

By default we use a very conservative timeout, to be sure that any tag can always answer in time.

New in version 2.0.1 (Plugin).

tinkerforge call nfc-bricklet <uid> get-maximum-timeout
Output:
  • timeout – Type: Int, Unit: 1 ms, Range: [0 to 216 - 1], Default: 2000

Returns the timeout as set by set-maximum-timeout

New in version 2.0.1 (Plugin).

tinkerforge call nfc-bricklet <uid> get-spitfp-error-count
Output:
  • error-count-ack-checksum – Type: Int, Range: [0 to 232 - 1]
  • error-count-message-checksum – Type: Int, Range: [0 to 232 - 1]
  • error-count-frame – Type: Int, Range: [0 to 232 - 1]
  • error-count-overflow – Type: Int, Range: [0 to 232 - 1]

Returns the error count for the communication between Brick and Bricklet.

The errors are divided into

  • ACK checksum errors,
  • message checksum errors,
  • framing errors and
  • overflow errors.

The errors counts are for errors that occur on the Bricklet side. All Bricks have a similar function that returns the errors on the Brick side.

tinkerforge call nfc-bricklet <uid> set-status-led-config <config>
Parameters:
  • <config> – Type: Int, Range: See symbols, Default: 3
Output:
  • no output

Sets the status LED configuration. By default the LED shows communication traffic between Brick and Bricklet, it flickers once for every 10 received data packets.

You can also turn the LED permanently on/off or show a heartbeat.

If the Bricklet is in bootloader mode, the LED is will show heartbeat by default.

The following symbols are available for this function:

For <config>:

  • status-led-config-off = 0
  • status-led-config-on = 1
  • status-led-config-show-heartbeat = 2
  • status-led-config-show-status = 3
tinkerforge call nfc-bricklet <uid> get-status-led-config
Output:
  • config – Type: Int, Range: See symbols, Default: 3

Returns the configuration as set by set-status-led-config

The following symbols are available for this function:

For config:

  • status-led-config-off = 0
  • status-led-config-on = 1
  • status-led-config-show-heartbeat = 2
  • status-led-config-show-status = 3
tinkerforge call nfc-bricklet <uid> get-chip-temperature
Output:
  • temperature – Type: Int, Unit: 1 °C, Range: [-215 to 215 - 1]

Returns the temperature as measured inside the microcontroller. The value returned is not the ambient temperature!

The temperature is only proportional to the real temperature and it has bad accuracy. Practically it is only useful as an indicator for temperature changes.

tinkerforge call nfc-bricklet <uid> reset
Output:
  • no output

Calling this function will reset the Bricklet. All configurations will be lost.

After a reset you have to create new device objects, calling functions on the existing ones will result in undefined behavior!

tinkerforge call nfc-bricklet <uid> get-identity
Output:
  • uid – Type: String, Length: up to 8
  • connected-uid – Type: String, Length: up to 8
  • position – Type: Char, Range: [a to h, z]
  • hardware-version – Type: Int Array, Length: 3
    • 0: major – Type: Int, Range: [0 to 255]
    • 1: minor – Type: Int, Range: [0 to 255]
    • 2: revision – Type: Int, Range: [0 to 255]
  • firmware-version – Type: Int Array, Length: 3
    • 0: major – Type: Int, Range: [0 to 255]
    • 1: minor – Type: Int, Range: [0 to 255]
    • 2: revision – Type: Int, Range: [0 to 255]
  • device-identifier – Type: Int, Range: [0 to 216 - 1]

Returns the UID, the UID where the Bricklet is connected to, the position, the hardware and firmware version as well as the device identifier.

The position can be 'a', 'b', 'c', 'd', 'e', 'f', 'g' or 'h' (Bricklet Port). A Bricklet connected to an Isolator Bricklet is always at position 'z'.

The device identifier numbers can be found here

Callbacks

Callbacks can be used to receive time critical or recurring data from the device:

tinkerforge dispatch nfc-bricklet <uid> example

The available callbacks are described below.

Note

Using callbacks for recurring events is always preferred compared to using getters. It will use less USB bandwidth and the latency will be a lot better, since there is no round trip time.

tinkerforge dispatch nfc-bricklet <uid> reader-state-changed
Output:
  • state – Type: Int, Range: See symbols
  • idle – Type: Bool

This callback is called if the reader state of the NFC Bricklet changes. See reader-get-state for more information about the possible states.

The following symbols are available for this function:

For state:

  • reader-state-initialization = 0
  • reader-state-idle = 128
  • reader-state-error = 192
  • reader-state-request-tag-id = 2
  • reader-state-request-tag-id-ready = 130
  • reader-state-request-tag-id-error = 194
  • reader-state-authenticate-mifare-classic-page = 3
  • reader-state-authenticate-mifare-classic-page-ready = 131
  • reader-state-authenticate-mifare-classic-page-error = 195
  • reader-state-write-page = 4
  • reader-state-write-page-ready = 132
  • reader-state-write-page-error = 196
  • reader-state-request-page = 5
  • reader-state-request-page-ready = 133
  • reader-state-request-page-error = 197
  • reader-state-write-ndef = 6
  • reader-state-write-ndef-ready = 134
  • reader-state-write-ndef-error = 198
  • reader-state-request-ndef = 7
  • reader-state-request-ndef-ready = 135
  • reader-state-request-ndef-error = 199
tinkerforge dispatch nfc-bricklet <uid> cardemu-state-changed
Output:
  • state – Type: Int, Range: See symbols
  • idle – Type: Bool

This callback is called if the cardemu state of the NFC Bricklet changes. See cardemu-get-state for more information about the possible states.

The following symbols are available for this function:

For state:

  • cardemu-state-initialization = 0
  • cardemu-state-idle = 128
  • cardemu-state-error = 192
  • cardemu-state-discover = 2
  • cardemu-state-discover-ready = 130
  • cardemu-state-discover-error = 194
  • cardemu-state-transfer-ndef = 3
  • cardemu-state-transfer-ndef-ready = 131
  • cardemu-state-transfer-ndef-error = 195
tinkerforge dispatch nfc-bricklet <uid> p2p-state-changed
Output:
  • state – Type: Int, Range: See symbols
  • idle – Type: Bool

This callback is called if the P2P state of the NFC Bricklet changes. See p2p-get-state for more information about the possible states.

The following symbols are available for this function:

For state:

  • p2p-state-initialization = 0
  • p2p-state-idle = 128
  • p2p-state-error = 192
  • p2p-state-discover = 2
  • p2p-state-discover-ready = 130
  • p2p-state-discover-error = 194
  • p2p-state-transfer-ndef = 3
  • p2p-state-transfer-ndef-ready = 131
  • p2p-state-transfer-ndef-error = 195

Internal Functions

Internal functions are used for maintenance tasks such as flashing a new firmware of changing the UID of a Bricklet. These task should be performed using Brick Viewer instead of using the internal functions directly.

tinkerforge call nfc-bricklet <uid> set-bootloader-mode <mode>
Parameters:
  • <mode> – Type: Int, Range: See symbols
Output:
  • status – Type: Int, Range: See symbols

Sets the bootloader mode and returns the status after the requested mode change was instigated.

You can change from bootloader mode to firmware mode and vice versa. A change from bootloader mode to firmware mode will only take place if the entry function, device identifier and CRC are present and correct.

This function is used by Brick Viewer during flashing. It should not be necessary to call it in a normal user program.

The following symbols are available for this function:

For <mode>:

  • bootloader-mode-bootloader = 0
  • bootloader-mode-firmware = 1
  • bootloader-mode-bootloader-wait-for-reboot = 2
  • bootloader-mode-firmware-wait-for-reboot = 3
  • bootloader-mode-firmware-wait-for-erase-and-reboot = 4

For status:

  • bootloader-status-ok = 0
  • bootloader-status-invalid-mode = 1
  • bootloader-status-no-change = 2
  • bootloader-status-entry-function-not-present = 3
  • bootloader-status-device-identifier-incorrect = 4
  • bootloader-status-crc-mismatch = 5
tinkerforge call nfc-bricklet <uid> get-bootloader-mode
Output:
  • mode – Type: Int, Range: See symbols

Returns the current bootloader mode, see set-bootloader-mode.

The following symbols are available for this function:

For mode:

  • bootloader-mode-bootloader = 0
  • bootloader-mode-firmware = 1
  • bootloader-mode-bootloader-wait-for-reboot = 2
  • bootloader-mode-firmware-wait-for-reboot = 3
  • bootloader-mode-firmware-wait-for-erase-and-reboot = 4
tinkerforge call nfc-bricklet <uid> set-write-firmware-pointer <pointer>
Parameters:
  • <pointer> – Type: Int, Unit: 1 B, Range: [0 to 232 - 1]
Output:
  • no output

Sets the firmware pointer for write-firmware. The pointer has to be increased by chunks of size 64. The data is written to flash every 4 chunks (which equals to one page of size 256).

This function is used by Brick Viewer during flashing. It should not be necessary to call it in a normal user program.

tinkerforge call nfc-bricklet <uid> write-firmware <data>
Parameters:
  • <data> – Type: Int Array, Length: 64, Range: [0 to 255]
Output:
  • status – Type: Int, Range: [0 to 255]

Writes 64 Bytes of firmware at the position as written by set-write-firmware-pointer before. The firmware is written to flash every 4 chunks.

You can only write firmware in bootloader mode.

This function is used by Brick Viewer during flashing. It should not be necessary to call it in a normal user program.

tinkerforge call nfc-bricklet <uid> write-uid <uid>
Parameters:
  • <uid> – Type: Int, Range: [0 to 232 - 1]
Output:
  • no output

Writes a new UID into flash. If you want to set a new UID you have to decode the Base58 encoded UID string into an integer first.

We recommend that you use Brick Viewer to change the UID.

tinkerforge call nfc-bricklet <uid> read-uid
Output:
  • uid – Type: Int, Range: [0 to 232 - 1]

Returns the current UID as an integer. Encode as Base58 to get the usual string version.