Build an RFID Scanner for Blockchain

Send RFID tag data to the EOS blockchain for novel supply chain, manufacturing, tracking and access control applications.

Introduction

Take your RFID tracking applications and ideas to a new level by sending the scanned tag data to a global, decentralized and distributed cloud platform.

This project uses a Raspberry Pi as an IoT device and the EOS blockchain as the global distributed platform.

The IoT device scans RFID chips in keycards, fobs, patches, tags, etc. The tags can be used to uniquely identify the items they are attached to in order to provide proof of location and time in supply chain, manufacturing, asset tracking and access control applications.

Everything you need to build this open source scanner and to access your scanned tag data on the blockchain is provided, including the node.js software, pre-deployed smart contract/dApp, blockchain account and private key. A simple web-application is available to facilitate real-time demonstration of end-to-end scanning, transacting and retrieving of real IoT data on a blockchain.

Update: The scanner device obtains its current location on Planet Earth with a crude IP geolocation lookup at the start of the application. The location is geohashed and combined with the scanned tag data into a data record. The location of the scanned tag, along with the tag data, is viewable on a map in the rfid-html web application.

Instructions to build the device and to use the platform are provided in the next section.

EOS was selected for the project because it offers these key features:

  • EOS offers fast transaction times: a scanned tag appears on-chain within 2 seconds typical.
  • EOS has no transaction fees. The blockchain resources are purchased up-front and one-time only. The IoT device can then transact within allocated resources without incurring additional fees.
  • EOS transactions are efficiently packed binary structures minimizing bandwidth requirements.
  • EOS uses the same globally recognized and hardened security standard as other blockchains like Bitcoin and Ethereum.

Briefly, you’ll connect the MFRC522 RFID chip/antenna board and buzzer to the Pi’s expansion header, download our device software repository to a directory on your Pi, run `npm install`, and then `sudo node rfid-scanner-eos-rpi.js`. Place tags within 2 cm of the antenna and view the webpage to see the scanned tag UID appear with seconds.

The EOS Jungle2.0 Testnet hosts the dApp and device account.

Hardware Setup

This project assumes you’ve already got a Raspberry Pi up and running. If you need get a Pi up from scratch, then there are many great resources out there like this one.

You’ll need:

It might look like this:

Hook it up like this:

There’s a great write-up here if you want to know more about how the MFRC522 can be used with the Pi.

Software Setup

  • Latest Raspbian OS (Project worked on a release download as of April 2019)
  • Recent Node.js. The version (8.11.1) that comes with Raspbian works.
  • NPM package manager. Install it then update it:
  • sudo apt-get install npm
  • sudo npm i -g npm
  • Git (already installed)

Setup

Clone this repository onto your Pi:

  • $ git clone https://github.com/EOSIoT/rfid-scanner-node.git
  • $ cd rfid-scanner-node

Install project dependencies:

  • $ npm install

That should be it for the software. The private key to sign transactions to the EOS blockchain dApp is already encoded in the software. Don’t think you can hack the IoT device account though. Through EOS’ flexible permission management system, a custom permission was created just for the task of submitting RFID data.

Using

Run the application with super-user privileges. Take note of the unique device ID to reference the scanner’s data in the demo web application. In the example below, the device ID is 942140182. Write this down as you’ll need it to filter for your scanner’s data in the web application.

If the application was setup correctly, you will see the results of an initial blockchain info request, showing that communication with the designated EOS API endpoint is working.

Example:

pi@raspberrypi:~/rfid-scanner-node $ sudo node rfid_scanner_eos_rpi.js
[2019-05-11T19:32:07.168Z] Device ID: 942140182 (0x3827eb16)
[2019-05-11T19:32:07.177Z] Blockchain:
[2019-05-11T19:32:07.220Z] scanning…
[2019-05-11T19:32:07.221Z] Please put chip or keycard in the antenna inductive zone!
[2019-05-11T19:32:07.221Z] Press Ctrl-C to stop.
[2019-05-11T19:32:07.402Z] { server_version: ‘448287d5’,
chain_id: ‘aca376f206b8fc25a6ed44dbdc66547c36c6c33e3a119ffbeaef943642f0e906’,
head_block_num: 57633625,
last_irreversible_block_num: 57633298,
last_irreversible_block_id: ‘036f6a124baa3eae12b40fdff2fe53f7796663f79b17559636a750bd1a25fbdc’,
head_block_id: ‘036f6b590d4b20385337d91dc688c46ac92d49bc75a6e0414f48da935c00d94b’,
head_block_time: ‘2019-05-11T19:32:07.000’,
head_block_producer: ‘eos42freedom’,
virtual_block_cpu_limit: 200000000,
virtual_block_net_limit: 1048576000,
block_cpu_limit: 181613,
block_net_limit: 1044592,
server_version_string: ‘v1.7.3’ }
[2019-05-11T19:32:07.746Z] No Card
[2019-05-11T19:32:08.266Z] No Card
[2019-05-11T19:32:08.787Z] No Card
[2019-05-11T19:32:26.074Z] Card detected, CardType: undefined
[2019-05-11T19:32:26.075Z] Card read UID (5): 99 2 f6 5c
[2019-05-11T19:32:26.083Z] Card Memory Capacity: 8
[2019-05-11T19:32:26.096Z] Block: 8 Data: 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
[2019-05-11T19:32:28.864Z] No Card
{ transaction_id: ‘e8672e52f521c003b6d9b767acc1ce2f8f967ae336a3cfd294fb2b8d89ab9d03’,
processed:
{ id: ‘e8672e52f521c003b6d9b767acc1ce2f8f967ae336a3cfd294fb2b8d89ab9d03’,
block_num: 57633669,
block_time: ‘2019-05-11T19:32:29.000’,
producer_block_id: null,
receipt: { status: ‘executed’, cpu_usage_us: 345, net_usage_words: 15 },
elapsed: 345,
net_usage: 120,
scheduled: false,
action_traces: [ [Object] ],
except: null } }
[2019-05-11T19:32:29.382Z] No Card

To scan a card or tag, place it near (within 2 cm) the mfrc522 reader’s top (antenna) side. You’ll hear a beep sound from the buzzer confirming the scan. The tag’s UID and the current time on the RPi IoT device is then bundled up into a transaction and sent to the EOS blockchain where it is quickly absorbed into a block.

The RFID scanner software has a private key enabling it to submit tag data on behalf of the eosiot11node account. The tag’s UID data is placed into a database hosted by a smart contract (dApp) under the eosiot12rfid account.

The dApp is currently hosted on the Jungle 2.0 Testnet until the mainnet solves the CPU crunch problem.

The data generated by the RFID scanner is accessed via simple REST API calls or a javascript library. There is a simple web application I’ve written that you can use to see the scanned tag data appear on the EOS blockchain in near real-time. Go ahead and enter the device ID you see above to view the data posted while testing the project.

Source: Build an RFID Scanner for Blockchain


About The Author

Muhammad Bilal

I am highly skilled and motivated individual with a Master's degree in Computer Science. I have extensive experience in technical writing and a deep understanding of SEO practices.

Leave a Comment

Your email address will not be published. Required fields are marked *