This example aims at starting a local Node.js server handling the NFC reading task.
Whenever an NFC tag is read, a web-socket is sent to a front-end application to communicate the payload.
First, navigate to the local server folder.
$ cd REPOSITORY_FOLDER/2-local-nfc-server/nfc-server
This project aims at starting a local server to interact with a USB NFC Reader and send read tags via websockets.
It has been tested with this configuration:
- NFC Reader: ACR122U
- Tags: NTAG213
On connection
events, the server starts listening for require-scan
events.
It interacts with the NFC USB Reader and sends the detected payload thanks to a nfc-tag-scanned
event to the socket.
To install the required dependencies, please run the following command:
# NPM
$ npm install
# Yarn alternative
$ yarn install
To start the local server, please run the following command:
# NPM
$ npm start
# Yarn alternative
$ yarn start
Navigate now to the client application folder.
$ cd REPOSITORY_FOLDER/2-local-nfc-server/client-app
This application is the client communicating via web-sockets with the previously started local Node.js serving handling the NFC scanning behaviour.
When loading the application and the <Home />
component, a require-scan
event is sent to the web-sockets server.
Afterwards, the server will answer by sending nfc-tag-scanned
events to the client, with the read payload.
To install the required dependencies, please run the following command:
# NPM
$ npm install
# Yarn alternative
$ yarn install
To run the client app locally, please run the following command:
# NPM
$ npm start
# Yarn alternative
$ yarn start
For this demo, I used NXP Mifare Ultralight NTAG213.
To simplify the payload decoding, I chose to encode the payload between slashes such as /THIS IS MY PAYLOAD/
. Indeed, when reading from the buffer, it simplifies the way we decode the payload.
You can also encode your own message using an external application such as NFC-Tools.
Whenever both the local server and the client application are running, and the NFC Reader is plugged (ACR122U in my example), a loader is displayed.
Afterwards, you can approach your previously written tag on the NFC reader so as to decode its content. If it is read successfully, the payload is sent via web-sockets and a card is displayed.