Giter Site home page Giter Site 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

Example

UART (using node-serialport)

var pn532 = require('pn532');
var SerialPort = require('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) {
        if (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) {
        if (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

andineck avatar kelvien avatar techniq avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

node-pn532's Issues

SPI Support

Currently only i2c and uart are methods of communication, but the board itself contains an SPI interface.

readNdefData() is returned "UnDefine"

hi,
readNdefData() is returned "UnDefine"

My Test Case is Android NFC and few NFC/RFID Tags

and Test Code is below that examples/read_data.js
var rfid = new pn532.PN532(serialPort); rfid.on( ...... rfid.readNdefData().then(function(data) { .... }); ....
node_pn532 read only one card in test case

Cannot get this to work

I'm using using the adafruit pn532 shield with an arduino UNO. I'm running node v0.12.7 from a Mac.

I'm running the example code to log the firmware data but the rfid.on('ready') never seems to run.

What am I doing wrong?

If I run the log I get this: (then it hangs)

debug: [frame-emitter] listening to data
debug: [hsu] Initializing serial port...
debug: [hsu] Serial port initialized.
info: [pn532] Configuring secure access module (SAM)...
debug: [pn532] Sending buffer: <Buffer 00 00 ff 05 fb d4 14 01 00 01 16 00>
debug: [hsu] Waking up PN532...
debug: [frame-emitter] Data received <Buffer 86 18 60 00 86 86>
debug: [frame-emitter] Processing buffer <Buffer 86 18 60 00 86 86>
debug: [frame-emitter] Data received <Buffer 00 60 1e 66 60 06 06 06 f8 9e 00 60 06 06 06 18 06 60 06 78 06 86 9e 00 18 06 e6>
debug: [frame-emitter] Processing buffer <Buffer 86 18 60 00 86 86 00 60 1e 66 60 06 06 06 f8 9e 00 60 06 06 06 18 06 60 06 78 06 86 9e 00 18 06 e6>
debug: [frame-emitter] Data received <Buffer 9e 00 06 06 60 06 06 06 f8 86 00 86 9e 00 f8 9e 00 fe 9e 00 7e>
debug: [frame-emitter] Processing buffer <Buffer 86 18 60 00 86 86 00 60 1e 66 60 06 06 06 f8 9e 00 60 06 06 06 18 06 60 06 78 06 86 9e 00 18 06 e6 9e 00 06 06 60 06 06 06 f8 86 00

Remove listeners and scanTag timeout

Hello,
I'm playing with your library with Raspberry Pi and PN532 Breakout board. Everything is working well :)

I had the need to set a timeout to the scanTag() function if if nothing had been found. So I needed a function to stop all the pending listeners.
This worked like a charm for me:

removeListeners() {
        this.frameEmitter.removeAllListeners();
}

Maybe this can be useful for others.

Anyway, maybe a timeout parameter on the scanTag() function could be the best option...

Thank you,
Alessandro

Issue with i2C

Hello

I have an issue when i try to use the PN532.

First this is what i use:

=>Raspberry pi 3
=> debian
=> node 4.3.2
=>npm 2.14.12
=> pn532 on 0x24 (i2c)
=> i2c active

I create a file (test.js) with this code:

var pn532 = require('pn532');
var i2c = require('i2c');
var address = 0x24;
var wire = new i2c(address, {device:'/dev/i2c-1',debug:false});
var rfid = new pn532.PN532(wire);

When i run a : node test.js i have this issue :
home/pi/node_modules/i2c/lib/i2c.coffee:88
return callback(err);
^

TypeError: callback is not a function
at Immediate._onImmediate (/home/pi/node_modules/i2c/lib/i2c.coffee:54:9)
at processImmediate [as _immediateCallback] (timers.js:383:17)

I'm lost.

Thank for your help

I2C Support not working

So I've only just got round to working on my project with this (original used UART but my card seems to have stopped working with that so now using I2C with the Raspberry Pi).

It seems that I2C support doesn't work at all, so am going to spend today investigating to see if I can get UART working again. If not I'll sit down and look at implementing the I2C support. (seems there are some missing methods on the wire object for I2C)

Peer to Peer mode with DFRobot NFC Module

Hey guys, I can read and write to an NFC sticker using the DFRobot NFC Module successfully. I can see the url I provide it, etc...

What I want to be able to do is tap my iPhone 11 onto the module and be provided with the redirect to the URL.

If it tap my iPhone 11 on the sticker I just wrote, it redirects perfectly (opens Safari link) but I want to be able to do it directly on the module itself.

Any help is appreciated, this is doing my head in!

Cheers

Card emulation

Can we transfer data between 2 pn532 ? like android beam ? I have a raspberry pi 3 and Pn532 from adafruit in uart mode.

Read data example not decoding NDEF records

Using the read_data.js example, I can't get it to show the parsed NDEF records. It correctly displays the buffer data, but the next line seems to fail silently.

I've tried with NTAG216 and various Mifare cards.

Here's the log:

@katy ➜  node-pn532 git:(master) ❤ node examples/read_data.js
Waiting for rfid ready event...
Listening for a tag scan...
Tag { ATQA: <Buffer 00 44>, SAK: 0, uid: '04:98:e8:12:ff:38:80' }
Reading tag data...
Tag data: <Buffer d1 01 0f 54 02 65 6e 48 65 6c 6c 6f 20 43 61 72 6c 6f 73>

Would you mind double checking this still works for you? The ndef dependency may have changed. I appreciate that this is a side project, and I'm willing to help patch things up if you need me to.

i2c problem

Hi,
I tried your package, and it seems it doesn't work in i2c mode.
The problem comes from this line
var rfid = new pn532.PN532(wire);
I get this error


/home/pi/rfidtest/node_modules/i2c/lib/i2c.coffee:88
          return callback(err);
                 ^
TypeError: callback is not a function

Do you have any idea?
thanks

Polling stops randomly on sending and processing buffer

Hello,
I'm trying to use this library to continually poll my NFC tags and show it to user the UID of the NFC tags that are currently placed in the reader. I use your example code here:
rfid.on('ready', function() { console.log('Listening for a tag scan...'); rfid.on('tag', function(tag) { console.log('tag:', tag.uid); }); });

My NFC reader is able to scan tags for a couple of times, and it will stop after a number of scan (The number is changing) And in the debug mode, it stops on these cases:

  1. When it is sending buffer.
    info: [pn532] Scanning tag... debug: [pn532] Sending buffer: <Buffer 00 00 ff 04 fc d4 4a 01 00 e1 00>
  2. When it is processing buffer:
    debug: [frame-emitter] Data received <Buffer 00 fe e2> debug: [frame-emitter] Processing buffer <Buffer 00 fe e2> debug: [frame-emitter] Data received <Buffer {some buffer}> debug: [frame-emitter] Processing buffer <Buffer {some buffer}>

Do you know what actually is happening here?

I'm using Raspberry Pi 3, Adafruit PN532 Breakout board v1.6

Emulate Tag

Hi, nice driver!

I'm using it for reading data from a NTAG 215 (ISO 14443-3) - works perfectly fine!

Now I want to use the PN532 to emulate a tag and scan it with my phone (e.g. to transfer a link).
I think the the writeNdefData-function is not suitable for that. Or am I wrong?
Can I emulate a tag using your driver?

Thank you in advance!

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.