MQTT - NFC Bricklet

This is the description of the MQTT 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 MQTT API bindings is part of their general description.

Examples

The example code below is Public Domain (CC0 1.0).

Scan For Tags

Download (example-scan-for-tags.txt)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# Change XYZ to the UID of your NFC Bricklet

setup:
    # Handle incoming reader state changed callbacks
    subscribe to tinkerforge/callback/nfc_bricklet/XYZ/reader_state_changed
        if a message is received
            # message contains the current state as int with symbols and idle as bool
            
            if state == "RequestTagIDReady"
                subscribe to tinkerforge/response/nfc_bricklet/XYZ/reader_get_tag_id
                    if a message is received
                        # message contains tag_type, id_length and tag_id
                        print tag_type, id_length and tag_id
                    endif
                endsubscribe
                publish '' to tinkerforge/response/nfc_bricklet/XYZ/reader_get_tag_id
            elseif state == "RequestTagIDError"
                print "Request tag ID error."
            endif
            
            if idle
                publish '' to tinkerforge/request/nfc_bricklet/XYZ/reader_request_tag_id 
            endif
        endif
    endsubscribe
    publish '{"register": true}' to tinkerforge/register/nfc_bricklet/XYZ/state_changed
    
    # Enable reader mode
    publish '{"mode": "reader"}' to tinkerforge/request/nfc_bricklet/XYZ/set_mode 

API

All published payloads to and from the MQTT bindings are in JSON format.

If an error occures, the bindings publish a JSON object containing the error message as member _ERROR. It is published on the corresponding response topic: .../response/... for .../request/... and .../callback/... for .../register/....

Basic Functions

request/nfc_bricklet/<UID>/set_mode
Request:
  • mode – Type: int, Range: See symbols
Response:
  • no response

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

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 default mode is "off".

The following symbols are available for this function:

For mode:

  • "Off" = 0
  • "Cardemu" = 1
  • "P2P" = 2
  • "Reader" = 3
request/nfc_bricklet/<UID>/get_mode
Request:
  • empty payload
Response:
  • mode – Type: int, Range: See symbols

Returns the mode as set by request/nfc_bricklet/<UID>/set_mode.

The following symbols are available for this function:

For mode:

  • "Off" = 0
  • "Cardemu" = 1
  • "P2P" = 2
  • "Reader" = 3
request/nfc_bricklet/<UID>/reader_request_tag_id
Request:
  • empty payload
Response:
  • no response

To read or write a tag that is in proximity of the NFC Bricklet you first have to call this function with the expected tag type as parameter. It is no problem if you don't know the tag type. You can cycle through the available tag types until the tag answers the request.

Currently the following tag types are supported:

  • Mifare Classic
  • NFC Forum Type 1
  • NFC Forum Type 2
  • NFC Forum Type 3
  • NFC Forum Type 4

After you call request/nfc_bricklet/<UID>/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 register/nfc_bricklet/<UID>/reader_state_changed callback or you can poll request/nfc_bricklet/<UID>/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 request/nfc_bricklet/<UID>/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 request/nfc_bricklet/<UID>/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 request/nfc_bricklet/<UID>/reader_request_tag_id.

request/nfc_bricklet/<UID>/reader_get_tag_id
Request:
  • empty payload
Response:
  • tag_type – Type: int, Range: See symbols
  • tag_id – Type: [int, ...], 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 request/nfc_bricklet/<UID>/reader_request_tag_id.

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

  1. Call request/nfc_bricklet/<UID>/reader_request_tag_id
  2. Wait for state to change to ReaderRequestTagIDReady (see request/nfc_bricklet/<UID>/reader_get_state or register/nfc_bricklet/<UID>/reader_state_changed callback)
  3. Call request/nfc_bricklet/<UID>/reader_get_tag_id

The following symbols are available for this function:

For tag_type:

  • "MifareClassic" = 0
  • "Type1" = 1
  • "Type2" = 2
  • "Type3" = 3
  • "Type4" = 4
request/nfc_bricklet/<UID>/reader_get_state
Request:
  • empty payload
Response:
  • 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 request/nfc_bricklet/<UID>/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 request/nfc_bricklet/<UID>/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 request/nfc_bricklet/<UID>/reader_read_page.

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

The following symbols are available for this function:

For state:

  • "Initialization" = 0
  • "Idle" = 128
  • "Error" = 192
  • "RequestTagID" = 2
  • "RequestTagIDReady" = 130
  • "RequestTagIDError" = 194
  • "AuthenticateMifareClassicPage" = 3
  • "AuthenticateMifareClassicPageReady" = 131
  • "AuthenticateMifareClassicPageError" = 195
  • "WritePage" = 4
  • "WritePageReady" = 132
  • "WritePageError" = 196
  • "RequestPage" = 5
  • "RequestPageReady" = 133
  • "RequestPageError" = 197
  • "WriteNDEF" = 6
  • "WriteNDEFReady" = 134
  • "WriteNDEFError" = 198
  • "RequestNDEF" = 7
  • "RequestNDEFReady" = 135
  • "RequestNDEFError" = 199
request/nfc_bricklet/<UID>/reader_write_ndef
Request:
  • ndef – Type: [int, ...], Length: variable, Range: [0 to 255]
Response:
  • no response

Writes NDEF formated data with a maximum of 255 bytes.

This function currently supports NFC Forum Type 2 and 4.

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

  1. Call request/nfc_bricklet/<UID>/reader_request_tag_id
  2. Wait for state to change to ReaderRequestTagIDReady (see request/nfc_bricklet/<UID>/reader_get_state or register/nfc_bricklet/<UID>/reader_state_changed callback)
  3. If looking for a specific tag then call request/nfc_bricklet/<UID>/reader_get_tag_id and check if the expected tag was found, if it was not found got back to step 1
  4. Call request/nfc_bricklet/<UID>/reader_write_ndef with the NDEF message that you want to write
  5. Wait for state to change to ReaderWriteNDEFReady (see request/nfc_bricklet/<UID>/reader_get_state or register/nfc_bricklet/<UID>/reader_state_changed callback)
request/nfc_bricklet/<UID>/reader_request_ndef
Request:
  • empty payload
Response:
  • no response

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 request/nfc_bricklet/<UID>/reader_request_tag_id
  2. Wait for state to change to RequestTagIDReady (see request/nfc_bricklet/<UID>/reader_get_state or register/nfc_bricklet/<UID>/reader_state_changed callback)
  3. If looking for a specific tag then call request/nfc_bricklet/<UID>/reader_get_tag_id and check if the expected tag was found, if it was not found got back to step 1
  4. Call request/nfc_bricklet/<UID>/reader_request_ndef
  5. Wait for state to change to ReaderRequestNDEFReady (see request/nfc_bricklet/<UID>/reader_get_state or register/nfc_bricklet/<UID>/reader_state_changed callback)
  6. Call request/nfc_bricklet/<UID>/reader_read_ndef to retrieve the NDEF message from the buffer
request/nfc_bricklet/<UID>/reader_read_ndef
Request:
  • empty payload
Response:
  • ndef – Type: [int, ...], 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 request/nfc_bricklet/<UID>/reader_request_ndef beforehand.

The buffer can have a size of up to 8192 bytes.

request/nfc_bricklet/<UID>/reader_authenticate_mifare_classic_page
Request:
  • page – Type: int, Range: [0 to 216 - 1]
  • key_number – Type: int, Range: See symbols
  • key – Type: [int, ...], Length: 6, Range: [0 to 255]
Response:
  • no response

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 request/nfc_bricklet/<UID>/reader_request_tag_id
  2. Wait for state to change to ReaderRequestTagIDReady (see request/nfc_bricklet/<UID>/reader_get_state or register/nfc_bricklet/<UID>/reader_state_changed callback)
  3. If looking for a specific tag then call request/nfc_bricklet/<UID>/reader_get_tag_id and check if the expected tag was found, if it was not found got back to step 1
  4. Call request/nfc_bricklet/<UID>/reader_authenticate_mifare_classic_page with page and key for the page
  5. Wait for state to change to ReaderAuthenticatingMifareClassicPageReady (see request/nfc_bricklet/<UID>/reader_get_state or register/nfc_bricklet/<UID>/reader_state_changed callback)
  6. Call request/nfc_bricklet/<UID>/reader_request_page or request/nfc_bricklet/<UID>/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:

  • "A" = 0
  • "B" = 1
request/nfc_bricklet/<UID>/reader_write_page
Request:
  • page – Type: int, Range: See symbols
  • data – Type: [int, ...], Length: variable, Range: [0 to 255]
Response:
  • no response

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 request/nfc_bricklet/<UID>/reader_request_tag_id
  2. Wait for state to change to ReaderRequestTagIDReady (see request/nfc_bricklet/<UID>/reader_get_state or register/nfc_bricklet/<UID>/reader_state_changed callback)
  3. If looking for a specific tag then call request/nfc_bricklet/<UID>/reader_get_tag_id and check if the expected tag was found, if it was not found got back to step 1
  4. Call request/nfc_bricklet/<UID>/reader_write_page with page number and data
  5. Wait for state to change to ReaderWritePageReady (see request/nfc_bricklet/<UID>/reader_get_state or register/nfc_bricklet/<UID>/reader_state_changed callback)

If you use a Mifare Classic tag you have to authenticate a page before you can write to it. See request/nfc_bricklet/<UID>/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:

  • "Type4CapabilityContainer" = 3
  • "Type4NDEF" = 4
request/nfc_bricklet/<UID>/reader_request_page
Request:
  • page – Type: int, Range: See symbols
  • length – Type: int, Range: [0 to 216 - 1]
Response:
  • no response

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 request/nfc_bricklet/<UID>/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 request/nfc_bricklet/<UID>/reader_request_tag_id
  2. Wait for state to change to RequestTagIDReady (see request/nfc_bricklet/<UID>/reader_get_state or register/nfc_bricklet/<UID>/reader_state_changed callback)
  3. If looking for a specific tag then call request/nfc_bricklet/<UID>/reader_get_tag_id and check if the expected tag was found, if it was not found got back to step 1
  4. Call request/nfc_bricklet/<UID>/reader_request_page with page number
  5. Wait for state to change to ReaderRequestPageReady (see request/nfc_bricklet/<UID>/reader_get_state or register/nfc_bricklet/<UID>/reader_state_changed callback)
  6. Call request/nfc_bricklet/<UID>/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 request/nfc_bricklet/<UID>/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:

  • "Type4CapabilityContainer" = 3
  • "Type4NDEF" = 4
request/nfc_bricklet/<UID>/reader_read_page
Request:
  • empty payload
Response:
  • data – Type: [int, ...], 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 request/nfc_bricklet/<UID>/reader_request_page beforehand.

The buffer can have a size of up to 8192 bytes.

request/nfc_bricklet/<UID>/cardemu_get_state
Request:
  • empty payload
Response:
  • 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 request/nfc_bricklet/<UID>/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 request/nfc_bricklet/<UID>/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:

  • "Initialization" = 0
  • "Idle" = 128
  • "Error" = 192
  • "Discover" = 2
  • "DiscoverReady" = 130
  • "DiscoverError" = 194
  • "TransferNDEF" = 3
  • "TransferNDEFReady" = 131
  • "TransferNDEFError" = 195
request/nfc_bricklet/<UID>/cardemu_start_discovery
Request:
  • empty payload
Response:
  • no response

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 request/nfc_bricklet/<UID>/cardemu_write_ndef and request/nfc_bricklet/<UID>/cardemu_start_transfer.

request/nfc_bricklet/<UID>/cardemu_write_ndef
Request:
  • ndef – Type: [int, ...], Length: variable, Range: [0 to 255]
Response:
  • no response

Writes the NDEF messages 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.

request/nfc_bricklet/<UID>/cardemu_start_transfer
Request:
  • transfer – Type: int, Range: See symbols
Response:
  • no response

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 request/nfc_bricklet/<UID>/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:

  • "Abort" = 0
  • "Write" = 1
request/nfc_bricklet/<UID>/p2p_get_state
Request:
  • empty payload
Response:
  • 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 request/nfc_bricklet/<UID>/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 request/nfc_bricklet/<UID>/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:

  • "Initialization" = 0
  • "Idle" = 128
  • "Error" = 192
  • "Discover" = 2
  • "DiscoverReady" = 130
  • "DiscoverError" = 194
  • "TransferNDEF" = 3
  • "TransferNDEFReady" = 131
  • "TransferNDEFError" = 195
request/nfc_bricklet/<UID>/p2p_start_discovery
Request:
  • empty payload
Response:
  • no response

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 request/nfc_bricklet/<UID>/p2p_start_transfer.

request/nfc_bricklet/<UID>/p2p_write_ndef
Request:
  • ndef – Type: [int, ...], Length: variable, Range: [0 to 255]
Response:
  • no response

Writes the NDEF messages 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.

request/nfc_bricklet/<UID>/p2p_start_transfer
Request:
  • transfer – Type: int, Range: See symbols
Response:
  • no response

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 request/nfc_bricklet/<UID>/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 request/nfc_bricklet/<UID>/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:

  • "Abort" = 0
  • "Write" = 1
  • "Read" = 2
request/nfc_bricklet/<UID>/p2p_read_ndef
Request:
  • empty payload
Response:
  • ndef – Type: [int, ...], Length: variable, Range: [0 to 255]

Returns the NDEF message that was written by a NFC peer in NFC P2P mode. The maximum NDEF length is 8192 byte.

The NDEF message is ready if you called request/nfc_bricklet/<UID>/p2p_start_transfer with a read transfer and the P2P state changed to P2PTransferNDEFReady.

Advanced Functions

request/nfc_bricklet/<UID>/set_detection_led_config
Request:
  • config – Type: int, Range: See symbols
Response:
  • no response

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:

  • "Off" = 0
  • "On" = 1
  • "ShowHeartbeat" = 2
  • "ShowDetection" = 3
request/nfc_bricklet/<UID>/get_detection_led_config
Request:
  • empty payload
Response:
  • config – Type: int, Range: See symbols

Returns the configuration as set by request/nfc_bricklet/<UID>/set_detection_led_config

The following symbols are available for this function:

For config:

  • "Off" = 0
  • "On" = 1
  • "ShowHeartbeat" = 2
  • "ShowDetection" = 3
request/nfc_bricklet/<UID>/set_maximum_timeout
Request:
  • timeout – Type: int, Range: [0 to 216 - 1]
Response:
  • no response

Sets the maximum timeout in ms.

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 request/nfc_bricklet/<UID>/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.

Default timeout: 2000ms.

New in version 2.0.1 (Plugin).

request/nfc_bricklet/<UID>/get_maximum_timeout
Request:
  • empty payload
Response:
  • timeout – Type: int, Range: [0 to 216 - 1]

Returns the timeout as set by request/nfc_bricklet/<UID>/set_maximum_timeout

New in version 2.0.1 (Plugin).

request/nfc_bricklet/<UID>/get_spitfp_error_count
Request:
  • empty payload
Response:
  • 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.

request/nfc_bricklet/<UID>/set_bootloader_mode
Request:
  • mode – Type: int, Range: See symbols
Response:
  • 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" = 0
  • "Firmware" = 1
  • "BootloaderWaitForReboot" = 2
  • "FirmwareWaitForReboot" = 3
  • "FirmwareWaitForEraseAndReboot" = 4

For status:

  • "OK" = 0
  • "InvalidMode" = 1
  • "NoChange" = 2
  • "EntryFunctionNotPresent" = 3
  • "DeviceIdentifierIncorrect" = 4
  • "CRCMismatch" = 5
request/nfc_bricklet/<UID>/get_bootloader_mode
Request:
  • empty payload
Response:
  • mode – Type: int, Range: See symbols

Returns the current bootloader mode, see request/nfc_bricklet/<UID>/set_bootloader_mode.

The following symbols are available for this function:

For mode:

  • "Bootloader" = 0
  • "Firmware" = 1
  • "BootloaderWaitForReboot" = 2
  • "FirmwareWaitForReboot" = 3
  • "FirmwareWaitForEraseAndReboot" = 4
request/nfc_bricklet/<UID>/set_write_firmware_pointer
Request:
  • pointer – Type: int, Range: [0 to 232 - 1]
Response:
  • no response

Sets the firmware pointer for request/nfc_bricklet/<UID>/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.

request/nfc_bricklet/<UID>/write_firmware
Request:
  • data – Type: [int, ...], Length: 64, Range: [0 to 255]
Response:
  • status – Type: int, Range: [0 to 255]

Writes 64 Bytes of firmware at the position as written by request/nfc_bricklet/<UID>/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.

request/nfc_bricklet/<UID>/set_status_led_config
Request:
  • config – Type: int, Range: See symbols
Response:
  • no response

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:

  • "Off" = 0
  • "On" = 1
  • "ShowHeartbeat" = 2
  • "ShowStatus" = 3
request/nfc_bricklet/<UID>/get_status_led_config
Request:
  • empty payload
Response:
  • config – Type: int, Range: See symbols

Returns the configuration as set by request/nfc_bricklet/<UID>/set_status_led_config

The following symbols are available for this function:

For config:

  • "Off" = 0
  • "On" = 1
  • "ShowHeartbeat" = 2
  • "ShowStatus" = 3
request/nfc_bricklet/<UID>/get_chip_temperature
Request:
  • empty payload
Response:
  • temperature – Type: int, Range: [-215 to 215 - 1]

Returns the temperature in °C 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.

request/nfc_bricklet/<UID>/reset
Request:
  • empty payload
Response:
  • no response

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!

request/nfc_bricklet/<UID>/write_uid
Request:
  • uid – Type: int, Range: [0 to 232 - 1]
Response:
  • no response

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.

request/nfc_bricklet/<UID>/read_uid
Request:
  • empty payload
Response:
  • uid – Type: int, Range: [0 to 232 - 1]

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

request/nfc_bricklet/<UID>/get_identity
Request:
  • empty payload
Response:
  • uid – Type: string, Length: up to 8
  • connected_uid – Type: string, Length: up to 8
  • position – Type: char
  • hardware_version – Type: [int, ...], Length: 3, Range: [0 to 255]
  • firmware_version – Type: [int, ...], Length: 3, Range: [0 to 255]
  • device_identifier – Type: int, Range: [0 to 216 - 1]
  • _display_name – Type: string

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' or 'd'.

The device identifier numbers can be found here. If symbolic output is not disabled, the device identifier is mapped to the corresponding name in the format used in topics.

The display name contains the NFC's name in a human readable form.

Callbacks

Callbacks can be registered to receive time critical or recurring data from the device. The registration is done with the corresponding .../register/... topic and an optional suffix. This suffix can be used to deregister the callback later.

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.

register/nfc_bricklet/<UID>/reader_state_changed
Register Request:
  • register – Type: bool
Callback Response:
  • state – Type: int, Range: See symbols
  • idle – Type: bool

A callback can be registered for this event by publishing to the .../register/nfc_bricklet/<UID>/reader_state_changed[/<SUFFIX>] topic with the payload "true". An added callback can be removed by publishing to the same topic with the payload "false". To support multiple (de)registrations, e.g. for message filtering, an optional suffix can be used.

If the callback is triggered, a message with it's payload is published under the corresponding .../callback/nfc_bricklet/<UID>/reader_state_changed[/<SUFFIX>] topic for each registered suffix.

This callback is called if the reader state of the NFC Bricklet changes. See request/nfc_bricklet/<UID>/reader_get_state for more information about the possible states.

The following symbols are available for this function:

For state:

  • "Initialization" = 0
  • "Idle" = 128
  • "Error" = 192
  • "RequestTagID" = 2
  • "RequestTagIDReady" = 130
  • "RequestTagIDError" = 194
  • "AuthenticateMifareClassicPage" = 3
  • "AuthenticateMifareClassicPageReady" = 131
  • "AuthenticateMifareClassicPageError" = 195
  • "WritePage" = 4
  • "WritePageReady" = 132
  • "WritePageError" = 196
  • "RequestPage" = 5
  • "RequestPageReady" = 133
  • "RequestPageError" = 197
  • "WriteNDEF" = 6
  • "WriteNDEFReady" = 134
  • "WriteNDEFError" = 198
  • "RequestNDEF" = 7
  • "RequestNDEFReady" = 135
  • "RequestNDEFError" = 199
register/nfc_bricklet/<UID>/cardemu_state_changed
Register Request:
  • register – Type: bool
Callback Response:
  • state – Type: int, Range: See symbols
  • idle – Type: bool

A callback can be registered for this event by publishing to the .../register/nfc_bricklet/<UID>/cardemu_state_changed[/<SUFFIX>] topic with the payload "true". An added callback can be removed by publishing to the same topic with the payload "false". To support multiple (de)registrations, e.g. for message filtering, an optional suffix can be used.

If the callback is triggered, a message with it's payload is published under the corresponding .../callback/nfc_bricklet/<UID>/cardemu_state_changed[/<SUFFIX>] topic for each registered suffix.

This callback is called if the cardemu state of the NFC Bricklet changes. See request/nfc_bricklet/<UID>/cardemu_get_state for more information about the possible states.

The following symbols are available for this function:

For state:

  • "Initialization" = 0
  • "Idle" = 128
  • "Error" = 192
  • "Discover" = 2
  • "DiscoverReady" = 130
  • "DiscoverError" = 194
  • "TransferNDEF" = 3
  • "TransferNDEFReady" = 131
  • "TransferNDEFError" = 195
register/nfc_bricklet/<UID>/p2p_state_changed
Register Request:
  • register – Type: bool
Callback Response:
  • state – Type: int, Range: See symbols
  • idle – Type: bool

A callback can be registered for this event by publishing to the .../register/nfc_bricklet/<UID>/p2p_state_changed[/<SUFFIX>] topic with the payload "true". An added callback can be removed by publishing to the same topic with the payload "false". To support multiple (de)registrations, e.g. for message filtering, an optional suffix can be used.

If the callback is triggered, a message with it's payload is published under the corresponding .../callback/nfc_bricklet/<UID>/p2p_state_changed[/<SUFFIX>] topic for each registered suffix.

This callback is called if the P2P state of the NFC Bricklet changes. See request/nfc_bricklet/<UID>/p2p_get_state for more information about the possible states.

The following symbols are available for this function:

For state:

  • "Initialization" = 0
  • "Idle" = 128
  • "Error" = 192
  • "Discover" = 2
  • "DiscoverReady" = 130
  • "DiscoverError" = 194
  • "TransferNDEF" = 3
  • "TransferNDEFReady" = 131
  • "TransferNDEFError" = 195