Blog
NFC - How to setup and use NFC with Power Apps
June 27. 2021
Power Apps now offers the ability to read text and URL data from NFC tags. This post describes this new feature, including how to write data to an NFC tag, and how to retreive the values from a canvas app.
NFC (near field communications) is a technology that facilitates short range communication (around 4cms) between two devices. A popular use of NFC is to support contactless payments, such as Apple Pay and Google Pay.
The great news is that the Android and iOS players now provide support for NFC. This post describes this new feature, including how to set up an NFC tag, and how to read the tag data from a canvas app.
What's the use case scenario?
A typical use of NFC is to provide tagging or identification type applications. They provide an alternative to barcoding systems, and work better in dirty environments where scanning barcodes can be difficult.An NFC tag is usually a sticker or some object with an embedded microchip and antenna. When a user places a phone or device near the tag, the antenna captures the radio power from the device and uses it to power the chip. The chip then responds to the device by broadcasting a radio signal that contains the contents of the tag.
Example use case secnarios of NFC could include:
- Inventory/stock control - Users could use an app to record/identify the location of stock, and to help track the movements of products in warehousing type applications.
- Identification of users - Employees could use an app to check-in/check-out of locations by scanning tags that are located in entrances and exits.
- Announcments - Users could scan posters, and an app could open a web page with additional details.
How to obtain/setup NFC tags
NFC tags are easy to obtain, and we can easily purchase them from online retailers like Amazon. In this post, I use basic NFC stickers which cost around $3 for a pack of 10.NTAG chips are ones that are most compatible with a wide range of smartphones. The types of NTAG chip include NTAG203, NTAG212, NTAG213, NTAG215 and NTAG216.
NTAG212 and NTAG213 chips are low cost chips that are suitable for simple, everyday use. The chips higher up in the range are more expensive, but offer better range, speed and memory/capacity.
How to program an NFC tag
Once we obtain an NFC tag, the next step is to write the data that we want to store. To do this, we use an NFC writing app, and there are many that we can install through the App Store of our choice.https://apps.apple.com/gb/app/nfc-tools/id1252962749
https://play.google.com/store/apps/details?id=com.wakdev.wdnfc&hl=en_GB&gl=US
https://play.google.com/store/apps/details?id=com.wakdev.wdnfc&hl=en_GB&gl=US
From NFC tools, we click the 'write' tab, and click the 'Add a record' button to define the text or URL that we want to store. We then click the 'write' button. This prompts us to scan the destination NFC tag, and to write the contents if the scan is successful.
As an example, we'll store the example value "Product123" to the text field, and "http://powerappsguide.com" to the URL field.
How to read an NFC tag from a canvas app
From a canvas app, we call the ReadNFC function to retrieve the contents of an NFC tag. The two key properties that ReadNFC returns are Text and URI.To demonstrate, here's how to read the text data from an NFC tag to a text input control. We can add a button and add the formula beneath to read the NFC tag content, and to save the result to a variable called locNFC. If ReadNFC().Text is blank, this indicates a failure to read the required content, and the formula calls the Notify function to alert the user.
UpdateContext({locNFC:ReadNFC()});
If(IsBlank(ReadNFC().Text),
Notify("Unable to read NFC tag")
)
To display the NFC tag's text content in a text input control, we would set the Default property of the text input control to locNFC.Text.
To demonstrate how to read the URL from an NFC tag and to launch the address in a new browser window, we can add the following formula to a button.
UpdateContext({locNFC:ReadNFC()});
If(IsBlank(ReadNFC().URI),
Notify("Unable to read NFC tag"),
Launch(locNFC.URI)
)
For more details about the ReadNFC function, we can refer to the documentation here: