openHAB - NFC Bricklet

Warning

The openHAB bindings are still in beta, but the development was stopped.

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

Examples

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

Scan For Tags

Download (ExampleScanForTags.rules)

 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
30
31
32
33
34
35
36
37
// For this example create an item linked to the state channel of your NFC Bricklet.

import java.util.List;
import java.util.stream.Collectors;

val READER_STATE_IDLE = 128
val READER_STATE_REQUEST_TAG_ID_READY = 130
val READER_STATE_REQUEST_TAG_ID_ERROR = 194

rule "NFC"
when
    // Change XYZ_State to the created item name
    Item XYZ_State changed
then
    val stateVal = newState as Number
    val int state = stateVal.intValue
    
    // Change XYZ to the UID of your NFC Bricklet
    val nfc = getActions("tinkerforge", "tinkerforge:brickletnfc:XYZ")

    if (state == READER_STATE_IDLE || state == READER_STATE_REQUEST_TAG_ID_ERROR) {
        nfc.brickletNFCReaderRequestTagID()
    } else if (state == READER_STATE_REQUEST_TAG_ID_READY) {
        logInfo("Example", "tag id ready")
        
        val ret = nfc.brickletNFCReaderGetTagID()
        
        val tagType = ret.get("tagType")
        val tagID = ret.get("tagID") as List<Integer>
        val tag = String.join(" ", tagID.stream().map([i | String.format("0x%02X", i)]).collect(Collectors.toList()));
        
        logInfo("Example", "tag id:" + tag)
        
        // Read tag ID again in one second.
        createTimer(now.plusSeconds(1), [|nfc.brickletNFCReaderRequestTagID()])
    }
end

Thing

UID:
  • tinkerforge:brickletnfc:[UID]
Required firmware version:
  • 2.0.6
Firmware update supported:
  • yes
Channels:
Actions:
Parameters:
  • Mode – Type: Choice, Default: Off
  • The NFC Bricklet supports five 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.
  • Options: Off, Cardemu, P2P, Reader, Simple

  • Detection LED Configuration – Type: Choice, Default: Show Detection
  • 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.
  • Options: Off, On, Show Heartbeat, Show Detection

  • Maximum Timeout – Type: integer, Default: 2000, Min: 0, Max: 65535
  • 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 the readerRequestTagID action 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.

  • Status LED Configuration – Type: Choice, Default: Show Status
  • 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.
  • Options: Off, On, Show Heartbeat, Show Status

Channels

State

The current state of the bricklet. The meaning of the state depends on the configured mode. Calling actions is only allowed in idle, ready and error states (e.g. all states >= 128). The following states are defined:

Reader:

  • 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

Cardemu:

  • 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

P2P:

  • 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
Type:
  • Number
UID:
  • tinkerforge:brickletnfc:[UID]:BrickletNFCState
Read only:
  • Yes
Predicate:
  • This channel will only be available if Mode is one of Off, Cardemu, P2P, Reader.
Tag ID

blah

This channel will only update after the configured update interval, not on changed values.

Type:
  • String
UID:
  • tinkerforge:brickletnfc:[UID]:BrickletNFCLastTagID
Read only:
  • No
Predicate:
  • This channel will only be available if Mode is Simple.
Parameters:
  • Update Interval – Type: integer, Default: 1000, Unit: ms
  • Specifies the update interval in milliseconds. A value of 0 disables automatic updates.
Tag Type

blah

This channel will only update after the configured update interval, not on changed values.

Type:
  • Number:Dimensionless
UID:
  • tinkerforge:brickletnfc:[UID]:BrickletNFCLastTagType
Read only:
  • Yes
Predicate:
  • This channel will only be available if Mode is Simple.
Parameters:
  • Update Interval – Type: integer, Default: 1000, Unit: ms
  • Specifies the update interval in milliseconds. A value of 0 disables automatic updates.
Tag Last Seen

This channel will only update after the configured update interval, not on changed values.

Type:
  • DateTime
UID:
  • tinkerforge:brickletnfc:[UID]:BrickletNFCLastTagSeen
Read only:
  • No
Predicate:
  • This channel will only be available if Mode is Simple.
Parameters:
  • Update Interval – Type: integer, Default: 1000, Unit: ms
  • Specifies the update interval in milliseconds. A value of 0 disables automatic updates.

Actions

Actions can be used in rules by creating an action object. All actions return a Map<String, Object>. Returned values can be accessed by name, sometimes the type deduction needs some hints, as shown below:

val actions = getActions("tinkerforge", "tinkerforge:brickletnfc:[UID]")
val hwVersion = actions.brickletNFCGetIdentity().get("hardwareVersion") as short[]
logInfo("Example", "Hardware version: " + hwVersion.get(0) + "." + hwVersion.get(1) + "." + hwVersion.get(2))

Basic Actions

brickletNFCGetMode()
Return Map:
  • mode – Type: int, Range: See constants, Default: 0

Returns the mode as set by the thing configuration.

The following constants are available for this function:

For mode:

  • val MODE_OFF = 0
  • val MODE_CARDEMU = 1
  • val MODE_P2P = 2
  • val MODE_READER = 3
  • val MODE_SIMPLE = 4
brickletNFCReaderRequestTagID()

After you call ReaderRequestTagID() 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 State channel or you can poll 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 ReaderGetTagID().

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 ReaderRequestTagID() 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 ReaderRequestTagID().

brickletNFCReaderGetTagID()
Return Map:
  • tagType – Type: int, Range: See constants
  • tagID – 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 ReaderRequestTagID().

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

  1. Call ReaderRequestTagID()
  2. Wait for state to change to ReaderRequestTagIDReady (see State or State channel)
  3. Call ReaderGetTagID()

The following constants are available for this function:

For tagType:

  • val TAG_TYPE_MIFARE_CLASSIC = 0
  • val TAG_TYPE_TYPE1 = 1
  • val TAG_TYPE_TYPE2 = 2
  • val TAG_TYPE_TYPE3 = 3
  • val TAG_TYPE_TYPE4 = 4
  • val TAG_TYPE_TYPE5 = 5
brickletNFCReaderGetState()
Return Map:
  • state – Type: int, Range: See constants
  • idle – Type: boolean

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 the thing configuration.

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

Example: If you call ReaderRequestPage(), 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 ReaderReadPage().

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

The following constants are available for this function:

For state:

  • val READER_STATE_INITIALIZATION = 0
  • val READER_STATE_IDLE = 128
  • val READER_STATE_ERROR = 192
  • val READER_STATE_REQUEST_TAG_ID = 2
  • val READER_STATE_REQUEST_TAG_ID_READY = 130
  • val READER_STATE_REQUEST_TAG_ID_ERROR = 194
  • val READER_STATE_AUTHENTICATE_MIFARE_CLASSIC_PAGE = 3
  • val READER_STATE_AUTHENTICATE_MIFARE_CLASSIC_PAGE_READY = 131
  • val READER_STATE_AUTHENTICATE_MIFARE_CLASSIC_PAGE_ERROR = 195
  • val READER_STATE_WRITE_PAGE = 4
  • val READER_STATE_WRITE_PAGE_READY = 132
  • val READER_STATE_WRITE_PAGE_ERROR = 196
  • val READER_STATE_REQUEST_PAGE = 5
  • val READER_STATE_REQUEST_PAGE_READY = 133
  • val READER_STATE_REQUEST_PAGE_ERROR = 197
  • val READER_STATE_WRITE_NDEF = 6
  • val READER_STATE_WRITE_NDEF_READY = 134
  • val READER_STATE_WRITE_NDEF_ERROR = 198
  • val READER_STATE_REQUEST_NDEF = 7
  • val READER_STATE_REQUEST_NDEF_READY = 135
  • val READER_STATE_REQUEST_NDEF_ERROR = 199
brickletNFCReaderWriteNDEF(int[] ndef)
Parameters:
  • ndef – Type: int[], Length: variable, Range: [0 to 255]

Writes NDEF formated data.

This function currently supports NFC Forum Type 2, 4, 5 and Mifare Classic.

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

  1. Call ReaderRequestTagID()
  2. Wait for state to change to ReaderRequestTagIDReady (see State or State channel)
  3. If looking for a specific tag then call ReaderGetTagID() and check if the expected tag was found, if it was not found got back to step 1
  4. Call ReaderWriteNDEF() with the NDEF message that you want to write
  5. Wait for state to change to ReaderWriteNDEFReady (see State or State channel)
brickletNFCReaderRequestNDEF()

Reads NDEF formated data from a tag.

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

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

  1. Call ReaderRequestTagID()
  2. Wait for state to change to RequestTagIDReady (see State or State channel)
  3. If looking for a specific tag then call ReaderGetTagID() and check if the expected tag was found, if it was not found got back to step 1
  4. Call ReaderRequestNDEF()
  5. Wait for state to change to ReaderRequestNDEFReady (see State or State channel)
  6. Call ReaderReadNDEF() to retrieve the NDEF message from the buffer
brickletNFCReaderReadNDEF()
Return Map:
  • 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 ReaderRequestNDEF() beforehand.

brickletNFCReaderAuthenticateMifareClassicPage(int page, int keyNumber, int[] key)
Parameters:
  • page – Type: int, Range: [0 to 216 - 1]
  • keyNumber – Type: int, Range: See constants
  • key – Type: int[], Length: 6, Range: [0 to 255]

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 ReaderRequestTagID()
  2. Wait for state to change to ReaderRequestTagIDReady (see State or State channel)
  3. If looking for a specific tag then call ReaderGetTagID() and check if the expected tag was found, if it was not found got back to step 1
  4. Call ReaderAuthenticateMifareClassicPage() with page and key for the page
  5. Wait for state to change to ReaderAuthenticatingMifareClassicPageReady (see State or State channel)
  6. Call ReaderRequestPage() or ReaderWritePage() to read/write page

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

The following constants are available for this function:

For keyNumber:

  • val KEY_A = 0
  • val KEY_B = 1
brickletNFCReaderWritePage(int page, int[] data)
Parameters:
  • page – Type: int, Range: See constants
  • data – Type: int[], Length: variable, Range: [0 to 255]

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)
  • NFC Forum Type 5 page size: 4 byte

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

  1. Call ReaderRequestTagID()
  2. Wait for state to change to ReaderRequestTagIDReady (see State or State channel)
  3. If looking for a specific tag then call ReaderGetTagID() and check if the expected tag was found, if it was not found got back to step 1
  4. Call ReaderWritePage() with page number and data
  5. Wait for state to change to ReaderWritePageReady (see State or State channel)

If you use a Mifare Classic tag you have to authenticate a page before you can write to it. See ReaderAuthenticateMifareClassicPage().

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 constants are available for this function:

For page:

  • val READER_WRITE_TYPE4_CAPABILITY_CONTAINER = 3
  • val READER_WRITE_TYPE4_NDEF = 4
brickletNFCReaderRequestPage(int page, int length)
Parameters:
  • page – Type: int, Range: See constants
  • length – Type: int, Range: [0 to 213]

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 ReaderReadPage(). 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)
  • NFC Forum Type 5 page size: 4 byte

The general approach for reading a tag is as follows:

  1. Call ReaderRequestTagID()
  2. Wait for state to change to RequestTagIDReady (see State or State channel)
  3. If looking for a specific tag then call ReaderGetTagID() and check if the expected tag was found, if it was not found got back to step 1
  4. Call ReaderRequestPage() with page number
  5. Wait for state to change to ReaderRequestPageReady (see State or State channel)
  6. Call ReaderReadPage() 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 ReaderAuthenticateMifareClassicPage().

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 constants are available for this function:

For page:

  • val READER_REQUEST_TYPE4_CAPABILITY_CONTAINER = 3
  • val READER_REQUEST_TYPE4_NDEF = 4
brickletNFCReaderReadPage()
Return Map:
  • 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 ReaderRequestPage() beforehand.

brickletNFCCardemuGetState()
Return Map:
  • state – Type: int, Range: See constants
  • idle – Type: boolean

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 the thing configuration.

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

Example: If you call CardemuStartDiscovery(), 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 constants are available for this function:

For state:

  • val CARDEMU_STATE_INITIALIZATION = 0
  • val CARDEMU_STATE_IDLE = 128
  • val CARDEMU_STATE_ERROR = 192
  • val CARDEMU_STATE_DISCOVER = 2
  • val CARDEMU_STATE_DISCOVER_READY = 130
  • val CARDEMU_STATE_DISCOVER_ERROR = 194
  • val CARDEMU_STATE_TRANSFER_NDEF = 3
  • val CARDEMU_STATE_TRANSFER_NDEF_READY = 131
  • val CARDEMU_STATE_TRANSFER_NDEF_ERROR = 195
brickletNFCCardemuStartDiscovery()

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 CardemuWriteNDEF() and CardemuStartTransfer().

brickletNFCCardemuWriteNDEF(int[] ndef)
Parameters:
  • ndef – Type: int[], Length: variable, Range: [0 to 255]

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.

brickletNFCCardemuStartTransfer(int transfer)
Parameters:
  • transfer – Type: int, Range: See constants

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 CardemuWriteNDEF() 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 constants are available for this function:

For transfer:

  • val CARDEMU_TRANSFER_ABORT = 0
  • val CARDEMU_TRANSFER_WRITE = 1
brickletNFCP2PGetState()
Return Map:
  • state – Type: int, Range: See constants
  • idle – Type: boolean

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 the thing configuration.

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

Example: If you call P2PStartDiscovery(), 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 constants are available for this function:

For state:

  • val P2P_STATE_INITIALIZATION = 0
  • val P2P_STATE_IDLE = 128
  • val P2P_STATE_ERROR = 192
  • val P2P_STATE_DISCOVER = 2
  • val P2P_STATE_DISCOVER_READY = 130
  • val P2P_STATE_DISCOVER_ERROR = 194
  • val P2P_STATE_TRANSFER_NDEF = 3
  • val P2P_STATE_TRANSFER_NDEF_READY = 131
  • val P2P_STATE_TRANSFER_NDEF_ERROR = 195
brickletNFCP2PStartDiscovery()

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 P2PStartTransfer().

brickletNFCP2PWriteNDEF(int[] ndef)
Parameters:
  • ndef – Type: int[], Length: variable, Range: [0 to 255]

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.

brickletNFCP2PStartTransfer(int transfer)
Parameters:
  • transfer – Type: int, Range: See constants

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 P2PWriteNDEF() 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 P2PReadNDEF() to read the NDEF message that was written by the NFC peer.

The following constants are available for this function:

For transfer:

  • val P2P_TRANSFER_ABORT = 0
  • val P2P_TRANSFER_WRITE = 1
  • val P2P_TRANSFER_READ = 2
brickletNFCP2PReadNDEF()
Return Map:
  • 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 NDEF message is ready if you called P2PStartTransfer() with a read transfer and the P2P state changed to P2PTransferNDEFReady.

Advanced Actions

brickletNFCGetChipTemperature()
Return Map:
  • 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.

brickletNFCGetStatusLEDConfig()
Return Map:
  • config – Type: int, Range: See constants, Default: 3

Returns the configuration as set by the thing configuration

The following constants are available for this function:

For config:

  • val STATUS_LED_CONFIG_OFF = 0
  • val STATUS_LED_CONFIG_ON = 1
  • val STATUS_LED_CONFIG_SHOW_HEARTBEAT = 2
  • val STATUS_LED_CONFIG_SHOW_STATUS = 3
brickletNFCGetSPITFPErrorCount()
Return Map:
  • errorCountAckChecksum – Type: long, Range: [0 to 232 - 1]
  • errorCountMessageChecksum – Type: long, Range: [0 to 232 - 1]
  • errorCountFrame – Type: long, Range: [0 to 232 - 1]
  • errorCountOverflow – Type: long, 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.

brickletNFCReset()

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!

brickletNFCGetIdentity()
Return Map:
  • uid – Type: String, Length: up to 8
  • connectedUid – Type: String, Length: up to 8
  • position – Type: char, Range: ['a' to 'h', 'z']
  • hardwareVersion – Type: short[], Length: 3
    • 0: major – Type: short, Range: [0 to 255]
    • 1: minor – Type: short, Range: [0 to 255]
    • 2: revision – Type: short, Range: [0 to 255]
  • firmwareVersion – Type: short[], Length: 3
    • 0: major – Type: short, Range: [0 to 255]
    • 1: minor – Type: short, Range: [0 to 255]
    • 2: revision – Type: short, Range: [0 to 255]
  • deviceIdentifier – 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

Internal Actions

brickletNFCReadUID()
Return Map:
  • uid – Type: long, Range: [0 to 232 - 1]

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