Skip to content

Instantly share code, notes, and snippets.

@linktohack
Last active February 6, 2017 15:01
Show Gist options
  • Save linktohack/ba3a3306fe1378cdb7999d84cccc357d to your computer and use it in GitHub Desktop.
Save linktohack/ba3a3306fe1378cdb7999d84cccc357d to your computer and use it in GitHub Desktop.
NFC
var nfc = require('nfc').nfc;
var util = require('util');
var Badge = {
logging: true,
read: function(callback) {
var Badge = this;
var i = 0;
Badge.logging && console.log('nfc.version(): ' + util.inspect(nfc.version(), { depth: null }));
Badge.logging && console.log('nfc.scan(): ' + util.inspect(nfc.scan(), { depth: null }));
var loop = function() {
var device = new nfc.NFC();
device.on('read', function(tag) {
Badge.logging && console.log(++i, tag.uid);
callback(tag);
});
device.on('stopped', function() {
Badge.logging && console.log('rebooting');
setTimeout(loop, 1000);
});
device.start();
};
loop();
}
};
Badge.logging = false;
Badge.read(function(tag) {
console.log('tag', tag.uid);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment