From 2f58942d6585256eb74cce22b3dcfc0c8367f949 Mon Sep 17 00:00:00 2001 From: tagyoureit Date: Mon, 23 Aug 2021 22:26:23 -0700 Subject: [PATCH] Influx 2.0 support; Readme updates --- README.md | 6 ++-- defaultConfig.json | 18 ++++++++++- package-lock.json | 6 ++-- package.json | 2 +- web/interfaces/influxInterface.ts | 50 ++++++++++++++++++++----------- 5 files changed, 56 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index dab36c1a..68a414cd 100755 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ Equipment supported 1. Chemical probes (pH, ORP, flow sensors, EC, etc.) ## Latest Changes -See (Changelog)[https://github.com/tagyoureit/nodejs-poolController/blob/master/Changelog) +See [Changelog](https://github.com/tagyoureit/nodejs-poolController/blob/master/Changelog) ## What's new in 7.0? @@ -84,8 +84,8 @@ To do anything with this app, you need a client to connect to it. A client can * Temperature sensors (10k, NTC) ## Web Clients -1. RECOMMENDED - [nodejs-poolController-dashPanel](https://github.com/rstrouse/nodejs-poolController-dashPanel). Full compatibility with IntelliCenter, *Touch, REM (RelayEquipmentManager). -1. Limited functionality - [nodejs-poolController-webClient](http://github.com/tagyoureit/nodejs-poolController-webClient). Built primarily around EasyTouch/IntelliTouch but will work with other systems. +1. [nodejs-poolController-dashPanel](https://github.com/rstrouse/nodejs-poolController-dashPanel). Full compatibility with IntelliCenter, *Touch, REM (RelayEquipmentManager). +1. Deprecated - ~~[nodejs-poolController-webClient](http://github.com/tagyoureit/nodejs-poolController-webClient). Built primarily around EasyTouch/IntelliTouch but will work with other systems.~~ * This app has the default to only listen to clients from localhost (127.0.0.1). If you need to have clients connect from other machines you will need to change the [ip](#module_nodejs-poolController--config.json) in `config.json`. diff --git a/defaultConfig.json b/defaultConfig.json index e33f6666..2a39a20d 100755 --- a/defaultConfig.json +++ b/defaultConfig.json @@ -100,15 +100,31 @@ "enabled": false, "fileName": "influxDB.json", "options": { + "version": 1, "protocol": "http", "host": "192.168.0.1", - "port": 32770, + "port": 9999, "username": "", "password": "", "database": "pool", "retentionPolicy": "autogen" } }, + "influxDBv2": { + "name": "InfluxDBv2", + "type": "influx", + "enabled": false, + "fileName": "influxDB.json", + "options": { + "version": 2, + "protocol": "http", + "host": "192.168.0.1", + "port": 9999, + "token": "...LuyM84JJx93Qvc7tfaXPbI_mFFjRBjaA==", + "org": "example-org", + "bucket": "57ec4eed2d90a50b" + } + }, "mqtt": { "name": "MQTT", "type": "mqtt", diff --git a/package-lock.json b/package-lock.json index 3b4ff9bb..85b43ec2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -93,9 +93,9 @@ } }, "@influxdata/influxdb-client": { - "version": "1.12.0", - "resolved": "https://registry.npmjs.org/@influxdata/influxdb-client/-/influxdb-client-1.12.0.tgz", - "integrity": "sha512-cbp9struPvs4OxGOQ1eoFlMYHvw3GmAW0mJ73EkL9g/OeX7svjcVjy6Db1ggUajyORulXl4o5Wtld0LQJq5dKg==" + "version": "1.16.0", + "resolved": "https://registry.npmjs.org/@influxdata/influxdb-client/-/influxdb-client-1.16.0.tgz", + "integrity": "sha512-cmempPmtY+W4dq7zT/mFEpNNSzTZOGszEeS52+g5SHsTKWvGjTu70fByOE8IaDgm8BggagDObF6U5J1PZZKhjw==" }, "@nodelib/fs.scandir": { "version": "2.1.4", diff --git a/package.json b/package.json index 2e944394..d95d2a52 100755 --- a/package.json +++ b/package.json @@ -19,7 +19,7 @@ "watch": "tsc -w" }, "dependencies": { - "@influxdata/influxdb-client": "^1.12.0", + "@influxdata/influxdb-client": "^1.16.0", "eslint-config-promise": "^2.0.2", "express": "^4.17.1", "extend": "^3.0.2", diff --git a/web/interfaces/influxInterface.ts b/web/interfaces/influxInterface.ts index 91385c91..7d3ae8a7 100644 --- a/web/interfaces/influxInterface.ts +++ b/web/interfaces/influxInterface.ts @@ -30,28 +30,40 @@ export class InfluxInterfaceBindings extends BaseInterfaceBindings { public events: InfluxInterfaceEvent[]; private init = () => { let baseOpts = extend(true, this.cfg.options, this.context.options); + let url = 'http'; + if (typeof baseOpts.protocol !== 'undefined' && baseOpts.protocol) url = baseOpts.protocol; + url = `${url}://${baseOpts.host}:${baseOpts.port}`; + let influxDB: InfluxDB; + let bucket; + let org; if (typeof baseOpts.host === 'undefined' || !baseOpts.host) { logger.warn(`Interface: ${this.cfg.name} has not resolved to a valid host.`); return; } - if (typeof baseOpts.database === 'undefined' || !baseOpts.database) { - logger.warn(`Interface: ${this.cfg.name} has not resolved to a valid database.`); - return; + if (baseOpts.version === 1) { + if (typeof baseOpts.database === 'undefined' || !baseOpts.database) { + logger.warn(`Interface: ${this.cfg.name} has not resolved to a valid database.`); + return; + } + bucket = `${baseOpts.database}/${baseOpts.retentionPolicy}`; + const clientOptions: ClientOptions = { + url, + token: `${baseOpts.username}:${baseOpts.password}`, + } + influxDB = new InfluxDB(clientOptions); } - // let opts = extend(true, baseOpts, e.options); - let url = 'http'; - if (typeof baseOpts.protocol !== 'undefined' && baseOpts.protocol) url = baseOpts.protocol; - url = `${url}://${baseOpts.host}:${baseOpts.port}`; - // TODO: add username/password - const bucket = `${baseOpts.database}/${baseOpts.retentionPolicy}`; - const clientOptions: ClientOptions = { - url, - token: `${baseOpts.username}:${baseOpts.password}`, + else if (baseOpts.version === 2) { + org = baseOpts.org; + bucket = baseOpts.bucket; + const clientOptions: ClientOptions = { + url, + token: baseOpts.token, + } + influxDB = new InfluxDB(clientOptions); } - const influxDB = new InfluxDB(clientOptions); - this.writeApi = influxDB.getWriteApi('', bucket, 'ms' as WritePrecisionType); - - + this.writeApi = influxDB.getWriteApi(org, bucket, 'ms'); + + // set global tags from context let baseTags = {} baseOpts.tags.forEach(tag => { @@ -175,12 +187,14 @@ export class InfluxInterfaceBindings extends BaseInterfaceBindings { let sec = ts.getSeconds() - 1; ts.setSeconds(sec); point2.timestamp(ts); - logger.silly(`Writing influx ${e.name} inverse data point ${point2.measurement}`) + logger.silly(`Writing influx ${e.name} inverse data point ${point2.toString()})`) this.writeApi.writePoint(point2); } if (typeof point.toLineProtocol() !== 'undefined') { - logger.silly(`Writing influx ${e.name} data point ${point2.measurement}`) + logger.silly(`Writing influx ${e.name} data point ${point.toString()}`) this.writeApi.writePoint(point); + this.writeApi.flush() + .catch(error => { logger.error(error); }); //logger.info(`INFLUX: ${point.toLineProtocol()}`) } else {