node-rfid
v1.0.7
Published
A node module to interface rc522 rfid reader with raspberry pi via node js!!!
Downloads
163
Readme
node-rfid
This module supports both Raspberry Pi (RPi) and BeagleBone Black development boards.
It requires your RPi (or BeagleBone Black) SPI interface to be enabled for being used. For that:
a) Go the terminal and type:
sudo raspi-config
b) This will open your raspi-config interface. Choose Advanced Options if no Interfacing Options is found else choose Interfacing Options.
c) This will redirect you to next interface with various interfaces options. From those options choose the option SPI.
After following these procedures, just hook up your rc522 rfid reader to the RPi (or BeagleBone Black) with the following datasheet:
The schematic image for raspberry pi is:
Note: The image is for RPi2, but the same works for RPi3 too!!!
After this, just browse to your node working directory through terminal via the command:
cd /folder_path
Then just install this node module as:
npm install node-rfid
This will add the node-rfid module to your node_modules folder
Now in your working nodejs code (or by creating a new file) just following the below guideline example:
Simple reading
This code waits the until the rfid tag is shown to the rfid reader
var rfid=require('node-rfid');
rfid.read(function(err,result){
if(err) console.log("Sorry, some hardware error occurred"); //some kind of hardware/wire error
console.log(result); //print rfid tag UID
});
Reading with time limit
This code waits thr rfid tag to be shown to the rfid reader within a time linit, else displays timeout message. The following sample waits for 5000 ms (5 s) for the rfid reader to get rfid tag shown to it. On reaching or exceeding the time limit, the timeout message is displayed. You may change the time limit by passing the time in millisecond as the first parameter in the function "readintime". For example: for 1 second time limit, just pass 1000.
var rfid=require('node-rfid');
rfid.readintime(5000,function(err,result){
if(err) console.log("Sorry, some hardware error occurred"); //some kind of hardware/wire error
if(result=="timeout"){
console.log("Sorry, You timed out"); //check if time exceeded the time you passed as argument and print timeout message
}else{
console.log(result); //print rfid tag UID
}
});
Now just run your js file as below and see the output in the terminal:
node /file_name