Skip to content

JavaScript module for the PN532 driver for RFID.

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT
Notifications You must be signed in to change notification settings

tessel/rfid-pn532

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

RFID

Code of Conduct

Driver for the rfid-pn532 Tessel RFID module. The hardware documentation for this module can be found here.

If you run into any issues you can ask for support on the Module Forums.

Installation

npm install rfid-pn532

Example

/*********************************************
This basic RFID example listens for an RFID
device to come within range of the module,
then logs its UID to the console.
*********************************************/

var tessel = require('tessel');
var rfidlib = require('rfid-pn532');

var rfid = rfidlib.use(tessel.port['A']); 

rfid.on('ready', function (version) {
  console.log('Ready to read RFID card');

  rfid.on('data', function(card) {
    console.log('UID:', card.uid.toString('hex'));
  });
});

Methods

# rfid.setPollPeriod( pollPeriod, callback(err) )
Set the time in milliseconds between each check for an RFID device. The poll period is 500ms by default.

# rfid.mifareClassicAuthenticateBlock( cardUID, blockNumber, authType, authKey, callback(err) )
Authenticate a block of memory to read or write on a MIFARE classic card. cardUID is the UID of the card to authenticate. blockNumber is the block address to authenticate. authType can be 0 for authorization type A or 1 for type B. authKey is an array containing the authorization key for the memory block, most commonly [0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF].

# rfid.mifareClassicReadBlock( blockNumber, callback(err, data) )
Read a block of memory on a MIFARE classic card. blockNumber is the address of the block to read.

# rfid.mifareClassicWriteBlock( blockNumber, data, callback(err) )
Write a block of memory on a MIFARE classic card. blockNumber is the address of the block to write. data is an array containing the 16 bytes of data to write to the block.

# rfid.startListening( callback(err) )
Tell the RFID module to start listening for targets. Only necessary when configuring the module for manual target reading.

# rfid.stopListening( callback() )
Tell the RFID module to stop listening for targets. This will also disable automatic listening for targets.

Events

# rfid.on( 'data', callback(data) )
Emitted when an RFID target comes within range of the module.

# rfid.on( 'read', callback(data) )
Same as 'data' event.

# rfid.on( 'error', callback(err) )
Emitted upon error.

# rfid.on( 'ready', callback() )
Emitted upon first successful communication between the Tessel and the module.

Further Examples

  • Mifare Classic. This example authorizes a mifare classic for read/write operations. First it will read a block of data off the card, write new data over the block, and then read back the data on the card to verify that the data on the card has changed.

Configuration

You can optionally configure how the RFID module listens for targets with an options argument in the .use() method. The supported options are listen and delay. Set listen to true to automatically listen for targets coming in range, or to false to manually control when the module should read targets. The default for this option is true. The delay option is used to set the amount of time in milliseconds to wait after reading a target to start listening again. The default for delay is 500 milliseconds. This option is ignored when listen is set to false.

var tessel = require('tessel');
var rfid = require('rfid-pn532').use(
  tessel.port['A'],
  {
    listen: true, 
    delay: 500
  }
);

TODO

Implement commands for additional NFC card/tag types

License

MIT or Apache 2.0, at your option

About

JavaScript module for the PN532 driver for RFID.

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published