The NFC Datasource is a custom Data Widget that returns nfc data from the device hardware that can be read or written to. Data read by the NFC widget can be bound to, including serialized url attributes.
Restrictions:
NFC can only be enabled on devices with an NFC reader.
Attributes
Name
Type
Default
Description
Req
id
string
null
The id of the widget used for databinding.
method
string
read
read or write
enabled
bool
true
If the datasource is enabled.
onsuccess
string/Event
null
events the broker will execute upon a successful read or write
onfail
string/Event
null
events the broker will execute if the read or write operation fails
autoexecute
bool
true
if the NFC read/write operation will happen automatically at startup
received
int
The number of NFC tags read.
serial
string
The last NFC tag serial#
payload
string
The last NFC tag text
Data Point
Name
Type
Description
id
The NFC tag serial#
serial
The NFC tag serial#
payload
The NFC tag text
Attributes (Data Specific)
Name
Type
Default
Description
Req
data
List[?]
If the NFC tag text is encoded as a JSON, XML or URL string, it is deserialized, otherwise it is deserialized as a Data Point. Note: URL's do not neeed to be encoded with their fully qualified domain name. To save space, this can be just a query string (with or without the ?). Only the URL's query parameters are deserialized. The resulting item is addressable using standard DOTNOTATION,
queuetype
string
replace
replace, lifo, fifo, append, prepend. Defines the data aggregation strategy for data returned from initial and subsequent calls. replace (default) replaces all data after each subsequent call. lifo (last in first out), fifo (first in first out), append and prepend are all used in conjunction with the maxrecords attribute
maxrecords
int
10000
The maximum size data can grow to. This works in concert with type
root
string
The root tag that defines the repeatable items in data. This can be a nested field. If not specified, the list is segmented by the first repeatable element found in the data set
ttl
int(s,m,h)
0s
Time to Live caches data in the local persistent HIVE database for the period specified. This saves requerying data that changes infrequently
rowcount
int
0
The number of records in data
Methods (Data Specific)
Name
Type
Description
clear()
Clears data. Invoked in any EVENT string using <id>.clear()
add(jsonOrXml, index)
string, int
Deserializes the jsonOrXml string and adds it to the end of data or at position index if specified. Invoked in any EVENT string using <id>.add(jsonOrXml, index)
remove(index)
int
Removes the last item from data or from position index if specified. Invoked in any EVENT string using <id>.remove(index)
reverse()
Reverses data. Invoked in any EVENT string using <id>.reverse()
Events
Name
Type
Description
start()
If method = "read" (default), the NCF starts listening for NCF taps. If method = "write", the NCF starts the write operation using the NCF body. Invoked in any EVENT string using <id>.start()
read()
If method = "read" (default), the NCF starts listening for NCF taps. If method = "write", this operation is ignored. Invoked in any EVENT string using <id>.read()
write(message)
string
If method = "write", the message passed is written to the tag. If the message is null, the NFC body is used. If method = "read", this operation is ignored. Invoked in any EVENT string using <id>.write('some text to write')
stop()
If method = "read" (default), the NCF stops listening for NCF taps. If method = "write", the NCF cancels the write operation. Invoked in any EVENT string using <id>.stop()
clear()
Clears the data bindable. Invoked in any EVENT string using <id>.clear()
Examples
Example #1 (NFC tag body encoded as json)
<NFCid="DB1"/>
<BOXheight="80" />
<TEXTlabel="Reads: {DB1.received}"color="black"size="11"/>
<TEXTlabel="Last Tag#: {DB1.serial}"color="black"size="11"/>
<TEXTlabel="Last Tag: {DB1.payload}"color="black"size="11"/>
<!-- NCF tag body is encoded as a valid json string --><!-- { "book" : { "sku" : "1222345-1", "name" : "Tesla, SpaceX, and the Quest for a Fantastic Future", "author" : "Elon Musk" } } -->
<TEXTlabel="Read Result: {DB1.data.book.sku}"color="black"size="11"/>
<TEXTlabel="Read Result: {DB1.data.book.name}"color="black"size="11"/>
<TEXTlabel="Read Result: {DB1.data.book.author}"color="black"size="11"/>
</BOX>
Example #2 (NFC tag body encoded as a url query string)
<NFCid="DB1"/>
<BOXheight="80" />
<TEXTlabel="Reads: {DB1.received}"color="black"size="11"/>
<TEXTlabel="Last Tag#: {DB1.serial}"color="black"size="11"/>
<TEXTlabel="Last Tag: {DB1.payload}"color="black"size="11"/>
<!-- NCF tag body is encoded as a url query string --><!-- sku=1222345-1&name=Tesla, SpaceX, and the Quest for a Fantastic Future&author=Elon Musk -->
<TEXTlabel="Read Result: {DB1.data.sku}"color="black"size="11"/>
<TEXTlabel="Read Result: {DB1.data.name}"color="black"size="11"/>
<TEXTlabel="Read Result: {DB1.data.author}"color="black"size="11"/>
</BOX>
Example #3 (NFC tag body is a simple string)
<NFCid="DB1"/>
<BOXheight="80" />
<TEXTlabel="Reads: {DB1.received}"color="black"size="11"/>
<TEXTlabel="Last Tag#: {DB1.serial}"color="black"size="11"/>
<TEXTlabel="Last Tag: {DB1.payload}"color="black"size="11"/>
<!-- NCF tag body is encoded as a simple string --><!-- 1222345-1 Tesla, SpaceX, and the Quest for a Fantastic Future Elon Musk -->
<TEXTlabel="Read Result: {DB1.data.serial}"color="black"size="11"/>
<TEXTlabel="Read Result: {DB1.data.payload}"color="black"size="11"/>
</BOX>