Created
December 11, 2018 10:35
-
-
Save JohnMcLear/e6dd8c05d83d48390524c6744c225fd8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// in ES6 | |
import { NFC } from 'nfc-pcsc'; | |
// without Babel in ES2015 | |
const { NFC } = require('nfc-pcsc'); | |
const nfc = new NFC(); // optionally you can pass logger | |
nfc.on('reader', reader => { | |
console.log(`${reader.reader.name} device attached`); | |
// needed for reading tags emulated with Android HCE | |
// custom AID, change according to your Android for tag emulation | |
// see https://developer.android.com/guide/topics/connectivity/nfc/hce.html | |
reader.aid = 'F222222222'; | |
reader.on('card', card => { | |
// card is object containing following data | |
// [always] String type: TAG_ISO_14443_3 (standard nfc tags like Mifare) or TAG_ISO_14443_4 (Android HCE and others) | |
// [always] String standard: same as type | |
// [only TAG_ISO_14443_3] String uid: tag uid | |
// [only TAG_ISO_14443_4] Buffer data: raw data from select APDU response | |
console.log(`${reader.reader.name} card detected`, card); | |
}); | |
reader.on('card.off', card => { | |
console.log(`${reader.reader.name} card removed`, card); | |
}); | |
reader.on('error', err => { | |
console.log(`${reader.reader.name} an error occurred`, err); | |
}); | |
reader.on('end', () => { | |
console.log(`${reader.reader.name} device removed`); | |
}); | |
}); | |
nfc.on('error', err => { | |
console.log('an error occurred', err); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment