ecowitt-gateway
Advanced tools
Comparing version
{ | ||
"name": "ecowitt-gateway", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "Retrieve data and get and set settings for Ecowitt Gateways", | ||
@@ -5,0 +5,0 @@ "main": "src/EWGateway.js", |
@@ -8,8 +8,11 @@ const dgram = require('dgram'); | ||
class EWGateway { | ||
constructor(ipAddr, port = 45000) { | ||
constructor(ipAddr, port = 45000, debug = false) { | ||
this.ipAddr = ipAddr; | ||
this.port = port; | ||
this.debug = debug; | ||
this.utils = new GWUtils(); | ||
const gateway = this; | ||
const buildPacket = (command, data) => { | ||
@@ -40,3 +43,5 @@ var size = (data !== null ? data.length : 0) + 3; | ||
client.connect(port, ipAddr, function () { | ||
console.debug(`Connected. Executing CMD 0x${command.toString(16)}`); | ||
if (gateway.debug) { | ||
console.debug(`Connected. Executing CMD 0x${command.toString(16)}`); | ||
} | ||
@@ -47,3 +52,5 @@ client.write(buildPacket(command, data)); | ||
client.on('data', function (buffer) { | ||
console.debug(`Received Data: ${buffer != null ? buffer.length : 0} bytes`); | ||
if (gateway.debug) { | ||
console.debug(`Received Data: ${buffer != null ? buffer.length : 0} bytes`); | ||
} | ||
client.destroy(); // kill client after server's response as to not mix up commands | ||
@@ -57,3 +64,5 @@ | ||
client.on('close', function () { | ||
console.debug('Connection closed'); | ||
if (gateway.debug) { | ||
console.debug('Connection closed'); | ||
} | ||
}); | ||
@@ -60,0 +69,0 @@ }); |
64858
0.44%1444
0.56%