Giter VIP home page Giter VIP logo

node-pn532's Introduction

PN532

Driver for the PN532 NFC chip. Provides an event and promise-based API, and requires either:

This implementation does not require libnfc, and should work on both X86 (32-bit or 64-bit) and ARM (RPi / Beaglebone) systems

Tested on a Mac OSX 10.9 system using a UART/FTDI cable to an Adafruit breakout board and on a BeagleBone using UART. I2C support is currently a WIP at the moment.

API is subject to change until the 1.0.0 release

Install

npm install pn532

and npm install serialport or npm install i2c

Credit Card EMV

Added ability to parse data to read credit cards, still a work in progress

  • using FTDI cable and PN532
  • enabled Visa and Mastercard selection
  • extracting credit card number and expiration
  • TODO: find out if the cards in canada have names on them (getting blank value presently)

Example

UART (using node-serialport)

var pn532 = require('pn532');
var SerialPort = require('serialport').SerialPort;

var serialPort = new SerialPort('/dev/tty.usbserial-AFWR836M', { baudrate: 115200 });
var rfid = new pn532.PN532(serialPort);

I2C (using node-i2c)

var pn532 = require('pn532');
var i2c = require('i2c');

var wire = new i2c(pn532.I2C_ADDRESS, {device: '/dev/i2c-1'});
var rfid = new pn532.PN532(wire);

Scan a tag

rfid.on('ready', function() {
    rfid.scanTag().then(function(tag) {
        console.log('tag:', tag.uid);
    });
});

Poll for a tag

rfid.on('ready', function() {
    console.log('Listening for a tag scan...');
    rfid.on('tag', function(tag) {
        console.log('tag:', tag.uid);
    });
});

Retrieve the firmware version

rfid.on('ready', function() {
    rfid.getFirmwareVersion().then(function(data) {
        console.log('firmware: ', data);
    });
});

Read and write tag data (using ndef library)

Tested using NTAG203 tags. Should support other NTAG and Mifare Ultralight tags. Mifare Classic tags are currently NOT supported, but could be in the future.

Read

rfid.on('ready', function() {
    rfid.on('tag', function(tag) {
        rfid.readNdefData().then(function(data) {
            var records = ndef.decodeMessage(Array.from(data));
            console.log(records);
        });
    });
});

Write

rfid.on('ready', function() {
    rfid.scanTag().then(function(tag) {
        var messages = [
            ndef.uriRecord('http://www.google.com'),
            ndef.textRecord('test')
        ];
        var data = ndef.encodeMessage(messages);

        rfid.writeNdefData(data).then(function(response) {
            console.log('Write successful');
        });
    });
});

Examples

Examples are available under the examples directory

Debug logging

PN532_LOGGING=debug node examples/card_scan.js

Note for using UART on a Raspberry Pi 3

If you are using this library on a Raspberry Pi 3, you will likely encounter an issue with the device sending or receiving data over UART due to some hardware and configuration changes with regards to the serial port.

TLDR workaround:

  1. Add core_freq=250 in the /boot/cmdline.txt
  2. Use /dev/ttyS0 instead of /dev/ttyAMA0

For details on why these changes are needed, see here and here

Links

node-pn532's People

Contributors

techniq avatar marc-pelland avatar kelvien avatar

Stargazers

Matthew Potter avatar

Watchers

Matthew Potter avatar James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.