Skip to content

Commit

Permalink
Influx 2.0 support;
Browse files Browse the repository at this point in the history
Readme updates
  • Loading branch information
tagyoureit committed Aug 24, 2021
1 parent e639a4b commit 2f58942
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 26 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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?

Expand Down Expand Up @@ -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`.

Expand Down
18 changes: 17 additions & 1 deletion defaultConfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
50 changes: 32 additions & 18 deletions web/interfaces/influxInterface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 2f58942

Please sign in to comment.