Эта страница является
переводом страницы
NFC. Перевод выполнен на 100%.
iRidium NFC
NFC - “near field communication” is a short-range wireless data transmission technology that enables data exchange between devices located at a distance of up to 10 centimeters.
What is required:
i3 Pro
The principle of NFC is to read data from a pre-programmed tag. Using NFC tags, you can automatically send any commands to the device. For example: a portable NFC tag can contain an access code to enter a hotel room or register in the system. In public places tags can be used to pay for services and at home they can serve as a signal for activation of a device or the whole scenario.
The driver reads and sends values in the NDEF format with encryption.
Variants of use
1. Limitations for controlling appliances. If there is a child in the family and it is necessary to limit access to certain appliences, it can be done with the help of a routine. When a child enters a house, he is identified by a tag and appliences in the kitchen and several sockets are blocked.
2. An NFC tag can be used to control registration of a person at a definite place of a shopping center or a certain floor of a gym. Statistics of visits can be tracked, light in certain parts of a building can be turned on.
3. The number of places in a parking lot can be tracked. A token is created, where the number is increased by one with each new tag. After a certain value is reached, a signal is sent to a display. If a car leaves the parking lot the number in the token is decreased and a routine to allow entering the parking lot is activated.
Work in iOS and Android
1. iOS NFC
After an NFC scanner is activated in iRidium project, there is a switch to iOS standard menu to work with NFC. Then a user scans a tag, data are sent to a project and iRidium work continues. The NFC scanner in the device is turned off.
2. Android NFC
In the Android version of the app NFC must be turned on in the system menu of Android. This platform does not allow to turn on/off an NFC scanner via iRidium. When NFC is activated on Android platform, the scanner will work all the time till it is turned off in the system menu of the device.
Writing data to NFC tag
Data can be written with the help of apps that can be foud in Google Play or App Store. Some variants are given below:
- NFC TagWriter by NXP
- Trigger (NFC Task Launcher)
- NFC Tools
- NFC Tag writer
After data are written, check them, as apps can write additional symbols. To delete the symbols. write the value from the tag in the variable and cut extra symbols.
Cutting 3 symbols at the start of the value.
var number = value.slice(3);
Cutting 3 symbols at the end of the value
var number = value.slice(-3);
Work in iRidium
1. Create a panel project in iRidium studio. Draw a button in it that will activate an NFC scanner.
2. Create an item to display received data:
3. Go to the Script editor and create a script for NFC driver (you can see a full version of the script at the end of the description).
After a driver is created with the help of the script, it has 1 channel (Commands) “NFCDefaultChannel” and 2 tags for feedback channels (Feedbacks) “NFCDefaultTag” and “NFCSimpleTag”. You can see full information about the driver below in the Driver properties section.
Creation of NFC driver.
IR.CreateDevice(IR.DEVICE_NFC_DEVICE,"NFC") //it creates NFC driver
Activation of NFC scanner by press
IR.AddListener(IR.EVENT_ITEM_PRESS, IR.GetItem("Page 1").GetItem("Item 2"), function ()
{
IR.GetDevice("NFC").Set("NFCDefaultChannel", 1); // it activates NFC scanner by pressing a button
});
4. Creation of a listener to receive data from the driver tags.
IR.AddListener(IR.EVENT_TAG_CHANGE, IR.GetDevice("NFC"), function(name, value)
// a listener is connected to track changes of driver tags
{
// full data are displayed on Item 1:
if(name == "NFCDefaultTag")
IR.GetItem("Page 1").GetItem("Item 1").Text = value;
//the main data are displayed on Item 4:
else
IR.GetItem("Page 1").GetItem("Item 4").Text = value;
});
The driver is ready for work!
A full version of the script
IR.AddListener(IR.EVENT_START,0,function()
{
IR.CreateDevice(IR.DEVICE_NFC_DEVICE,"NFC") //it creates NFC driver
IR.GetItem("Page 1").GetItem("Item 1").Text = driver;
IR.AddListener(IR.EVENT_ITEM_PRESS, IR.GetItem("Page 1").GetItem("Item 2"), function ()//it activates NFC scanner by pressing a button
{
IR.GetDevice("NFC").Set("NFCDefaultChannel", 1); //Value 1 is sent to turn on.
});
IR.AddListener(IR.EVENT_TAG_CHANGE, IR.GetDevice("NFC"), function(name, value) //a listener is connected to track changes of driver tags
{
if(name == "NFCDefaultTag")
IR.GetItem("Page 1").GetItem("Item 1").Text = value; //full data are displayed on Item 1
else
IR.GetItem("Page 1").GetItem("Item 4").Text = value; //the main data are displayed on Item 4
});
});
Driver Properties
Commands
Sending a command to read a tag.
Syntax:
IR.GetDevice(driver).Set(type, value)
| On input |
Value |
Description
|
| driver |
"NFC" |
type: String driver name
|
| type |
“NFCDefaultChannel” |
type: String channel name
|
| value |
1 |
type: Value Sent value: 1 - activation of the scanner, 0 - deactivation of the scanner
|
Feedbacks
Accepting values from an NFC tag.
Syntax:
IR.GetDevice(driver).GetFeedback(name)
| On input |
Value |
Description
|
| driver |
"NFC" |
type: String driver name
|
| name |
“NFCDefaultTag”, “NFCSimpleTag” |
type: String Format of accepted values: - Full data - Main data
|
| Data (NFCDefaultTag) |
{“ID”:”0”,”Type”:””, “Payload”:”12345”} |
type: String Full data
|
| Data (NFCSimpleTag) |
12345 |
type: String Main data
|