ecowitt-gateway
Advanced tools
Comparing version 1.0.2 to 1.0.3
{ | ||
"name": "ecowitt-gateway", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"description": "Retrieve data and get and set settings for Ecowitt Gateways", | ||
@@ -5,0 +5,0 @@ "main": "src/EWGateway.js", |
@@ -19,2 +19,4 @@ # Ecowitt Gateway | ||
``` js | ||
constructor('IP_ADDRESS', PORT, USE_RAIN_DATA, DEBUG) //Only IP_ADDRESS is required, port is 45000 by default, USE_RAIN_DATA is null by default which will check the firmware for optimal use and can be set to true or false | ||
getSensors({ //Optional filter can be by type and/or status. Accepts strings or arrays of strings for type and status. | ||
@@ -21,0 +23,0 @@ type: 'WH65', |
@@ -8,3 +8,3 @@ const dgram = require('dgram'); | ||
class EWGateway { | ||
constructor(ipAddr, port = 45000, debug = false) { | ||
constructor(ipAddr, port = 45000, useReadRainData = null, debug = false) { | ||
@@ -16,2 +16,4 @@ this.ipAddr = ipAddr; | ||
this.useReadRainData = false; | ||
const gateway = this; | ||
@@ -74,2 +76,15 @@ | ||
}; | ||
if (useReadRainData == null) | ||
{ | ||
this.getFirmwareVersion() | ||
.then(firmware => { | ||
if (firmware && !firmware.toUpperCase().includes('GW2000')) { | ||
this.useReadRainData = true; | ||
} | ||
}) | ||
.catch(); | ||
} else{ | ||
this.useReadRainData = useReadRainData; | ||
} | ||
} | ||
@@ -106,3 +121,3 @@ | ||
const appendRain = (data) => { | ||
this.getRain() | ||
(this.useReadRainData ? this.getRainData() : this.getRain()) | ||
.then(rainData => { | ||
@@ -176,3 +191,7 @@ Object.assign(data, rainData); | ||
.then(buffer => { | ||
res(this.utils.parseRainData(buffer)); | ||
try { | ||
res(this.utils.parseRainData(buffer)); | ||
} catch (error) { | ||
rej(error); | ||
} | ||
}) | ||
@@ -234,3 +253,7 @@ .catch(rej); | ||
.then(buffer => { | ||
res(this.utils.parseRain(buffer)); | ||
try { | ||
res(this.utils.parseRain(buffer)); | ||
} catch (error) { | ||
rej(error) | ||
} | ||
}) | ||
@@ -237,0 +260,0 @@ .catch(rej); |
66568
1485
76