Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

rfidgeek

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rfidgeek - npm Package Compare versions

Comparing version 0.1.3 to 0.1.4

43

examples/example_iso15693.js

@@ -17,6 +17,8 @@ /*

// initialize with tcpsocket options
// INITIALIZE WITH TCPSOCKET AND/OR WEBSOCKET OPTIONS
rfid.init({
debug: 'error',
tcpsocket: { port: 6767, host: 'localhost'},
websocket: { port: 6768, host: 'localhost'},
scaninterval: 1000,

@@ -27,4 +29,7 @@ tagtype: 'ISO15693',

// This adds a TCPSOCKET listener that can now be accessed on localhost:6767
//
// This adds:
// a TCPSOCKET listener that can now be accessed on localhost:6767
// a WEBSOCKET listener that can now be accessed on localhost:6768
// TCPSOCKET:
// Connect via telnet and start reader scanning with

@@ -38,6 +43,32 @@ // {"cmd":"SCAN-ON"}

// WEBSOCKET
// e.g. in browser, add a websocket connection:
var ws = new WebSocket("ws://localhost:6768");
ws.onopen = function(evt) { console.log("connection opened"); };
ws.onclose = function(evt) { console.log("connection closed"); };
ws.onerror = function(evt) { console.log(evt); };
ws.onmessage = function(evt) { console.dir(evt.data); };
// Start scanner
ws.send('{"cmd":"SCAN-ON"}');
// and you should receive same data as the tcpsocket example above
// CREATING EVENT LISTENERS
//
rfid.on('tagfound', function(tag) {
console.log("Tag received in external app: "+tag);
//
// You can easily create event listener on the tagsInRange event from reader:
rfid.reader.on('tagsInRange', function(tags) {
console.log(tags);
});
// INITIALIZE WITH WEBSOCKET OPTIONS
rfid.init({
debug: 'error',
scaninterval: 1000,
websocket: { port: 6667, host: 'localhost' },
tagtype: 'ISO15693',
blocks_to_read: '08' // 8+1 blocks * 4 bytes = 36 bytes
});

2

lib/websocket.js

@@ -21,3 +21,3 @@ /*

self.server = wss.on('connection', function(socket) {
logger.log('info', 'Client connected: ' + socket.remoteAddress + ':' + socket.remotePort);
socket.on('message', function(data) {

@@ -24,0 +24,0 @@ //console.log('received: %s', data);

@@ -5,3 +5,3 @@ {

"author": "Benjamin Rokseth <bensinober@gmail.com>",
"version": "0.1.3",
"version": "0.1.4",
"repository": {

@@ -8,0 +8,0 @@ "type": "git",

@@ -46,3 +46,3 @@ /*

*/
var socket,
var sockets = {},
reader,

@@ -68,3 +68,3 @@ readerConfig,

ws.on('ready', function(conn) {
socket = conn;
sockets.websocket = conn;
logger.log("debug", 'Connected to socket');

@@ -82,3 +82,3 @@ });

tcpsocket.on('ready', function(conn) {
socket = conn;
sockets.tcpsocket = conn;
logger.log("debug", 'Connected to socket');

@@ -119,4 +119,4 @@ });

logger.log("debug", 'Tag removed');
if (config.websocket) {
socket.sendUTF("Tag removed");
if (sockets.websocket) {
sockets.websocket.send("Tag removed");
}

@@ -132,3 +132,3 @@ //tagData = '';

logger.log("debug", "New tag(s) found!");
var jsonresponse
var jsonresponse;
tags.forEach(function(tag) {

@@ -144,8 +144,10 @@ if(!tag.validated) {

logger.log("debug", "response to socket: "+jsonresponse);
if (config.websocket) {
socket.send(jsonresponse+"\n");
if (sockets.websocket) {
sockets.websocket.send(jsonresponse+"\n");
}
if (config.tcpsocket) {
socket.write(jsonresponse+"\n");
if (sockets.tcpsocket) {
sockets.tcpsocket.write(jsonresponse+"\n");
}
// emit to event subscribers
reader.emit('tagsInRange', jsonresponse+"\n"); // emit to subscribers
if (tag.status == "TAGS-OK") {

@@ -156,3 +158,2 @@ tag.validated = true;

});
reader.emit('tagsInRange', jsonresponse+"\n"); // emit to subscribers
} else {

@@ -168,16 +169,19 @@ logger.log("debug", "no tags in range...");

tags.forEach(function(tag) {
var response = {
cmd: "READ",
id: reverseTag(tag.id.slice(0,-1))
};
jsonresponse = JSON.stringify(response);
logger.log("debug", "response to socket: "+jsonresponse);
if (config.websocket) {
socket.send(jsonresponse+"\n");
if(!tag.validated) {
var response = {
cmd: "READ",
id: reverseTag(tag.id.slice(0,-1))
};
jsonresponse = JSON.stringify(response);
logger.log("debug", "response to socket: "+jsonresponse);
if (configsockets.websocket) {
sockets.websocket.send(jsonresponse+"\n");
}
if (sockets.tcpsocket) {
sockets.tcpsocket.write(jsonresponse+"\n");
}
reader.emit('tagsInRange', jsonresponse+"\n"); // emit to subscribers
tag.validated = true;
}
if (config.tcpsocket) {
socket.write(jsonresponse+"\n");
}
});
reader.emit('tagsInRange', jsonresponse+"\n"); // emit to subscribers
} else {

@@ -585,3 +589,3 @@ logger.log("debug", "no tags in range...");

stopScan: stopScan,
socket: socket,
sockets: sockets,
tags: tagsInRange,

@@ -626,3 +630,8 @@ // this function writes data to ISO15693 chip

close: function() {
socket.close();
if(sockets.websocket) {
sockets.websocket.close();
}
if(sockets.tcpsocket) {
sockets.tcpsocket.close();
}
}

@@ -629,0 +638,0 @@ }

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc