Replies: 2 comments 16 replies
-
Hi, Thanks for the report and you are right...can you confirm that the drivers also work correctly for influxdb v1.8? |
Beta Was this translation helpful? Give feedback.
8 replies
-
Hi Frangoteam/Fuxa Team,
kindly see attached file index.js for the influxdb 1.8+ version.
i changed the extension to ".txt" due to security issue when sending js
file.
If have questions, please let me know.
Regards
Henjoe
On Sat, May 20, 2023 at 3:08 PM Umberto Nocelli ***@***.***> wrote:
Hi, nice to meet you.
@henjoe <https://github.com/henjoe> you can do the PR or send me the
file, we will be happy to improve support for influxdb with version 1.8
—
Reply to this email directly, view it on GitHub
<#766 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AL3Z67ZZGL3ZXYPGG4BK2ELXHBUYDANCNFSM6AAAAAAWMU36L4>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
/**
* Module to manage the DAQ with influxdb
*/
"use strict";
var utils = require('../../utils');
let influx = require('influx')
//var { InfluxDB, Point, flux } = ***@***.***/influxdb-client');
function Influx(_settings, _log) {
var settings = _settings; // Application settings
var logger = _log; // Application logger
var status = InfluxDBStatusEnum.CLOSE;
var influxError = { error: null, timestamp: 0 };
//var influxdbVersion = VERSION_20;
var client = null;
var clientOptions = null
// var writeApi = null
var queryApi = null
this.init = function () {
// This is where it needs to have a FRONT END so this options is dynamic//----------------------------------->>>
if (settings.daqstore.url != "") {
clientOptions = {
host: "the host or the IP of influxserver (string)",
port: 8086,
protocol: 'https', // *could be http or https
database: "the database name in the influxdb (string)",
username:'username (string)',
password:'password (string)',
options: {
rejectUnauthorized: false // this options is needed when protocol is set to https and the influxdb server is using a self-signed certificate (it is important)
}
}
client = new influx.InfluxDB(clientOptions);
//writeApi = client.getWriteApi(settings.daqstore.organization, settings.daqstore.bucket, 's');
//queryApi = client.getQueryApi(settings.daqstore.organization);
status = InfluxDBStatusEnum.OPEN;
}
}
this.close = function () {
try {
status = InfluxDBStatusEnum.CLOSE;
client.close.then(() => {
logger.info('influxdb-close FINISHED');
})
.catch((e) => {
logger.error(`influxdb-close failed! ${e}`);
});
} catch (error) {
logger.error(`influxdb-close failed! ${error}`);
}
}
this.setCall = function (_fncGetProp) {
fncGetTagProp = _fncGetProp;
return this.addDaqValues;
}
var fncGetTagProp = null;
this.addDaqValue = function (tagId, tagValue) {
logger.error('influxdb-addDaqValue Not supported!');
}
var data_to_write = []
var taglist = []
this.addDaqValues = function (tags, deviceName) {
taglist = tags
for (var tagid in tags) {
if (!tags[tagid].daq || !tags[tagid].daq.enabled) {
continue;
}
//writePoint(tags[tagid], deviceName);
let tag = tags[tagid]
//console.log('taglist: ' + tags)
if (!utils.isNullOrUndefined(tag.value)) {
let tags = {
id: tag.id,
devicename: deviceName
}
let fields = {value:tag.value}
if (utils.isBoolean(tag.value)) {
fields.value = tag.value * 1
}
var pts = {
measurement: tag.name,
tags,
fields,
timestamp: tag.timestamp * 1000000 || new Date().getTime() * 1000000
}
data_to_write.push(pts)
}
}
writePoint(data_to_write)
}
console.log("taglist:" + taglist)
this.getDaqMap = function (tagid) {
var dummy = {};
dummy[tagid] = true;
return dummy;
}
this.getDaqValue = function (tagid, fromts, tots) {
return new Promise(function (resolve, reject) {
var tagname = taglist[tagid].name
console.log('tagname: '+ tagname)
const query = flux`from(bucket: "${settings.daqstore.bucket}") |> range(start: ${new Date(fromts)}, stop: ${new Date(tots)}) |> filter(fn: (r) => r._measurement == "${tagid}")`;
try {
var result = [];
queryApi.queryRows(query, {
next(row, tableMeta) {
const o = tableMeta.toObject(row);
result = result.concat({ dt: new Date(o._time).getTime(), value: o._value });
},
error(error) {
logger.error(`influxdb-getDaqValue failed! ${error}`);
reject(error);
},
complete() {
resolve(result);
}
})
} catch (error) {
logger.error(`influxdb-getDaqValue failed! ${error}`);
reject(error);
}
});
}
async function writePoint(pts) {
try {
await client.writePoints(pts)
//console.log(`writing points: ${JSON.stringify(pts)}`)
data_to_write = []
} catch (error) {
logger.error(`Error writing to database! Please check IP address of influxdb Server is correct.`);
}
}
function setError(error) {
influxError.error = error;
influxError.timestamp = new Date().getTime();
}
this.init();
}
module.exports = {
create: function (data, logger) {
return new Influx(data, logger);
}
};
var InfluxDBStatusEnum = {
OPEN: 'open',
CLOSE: 'close',
}
|
Beta Was this translation helpful? Give feedback.
8 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi I don't know why there is no options to store data in influxdb 1.8 version?
The configuration only allows to use the influxdb V2.
Upon looking at code under ./Client/src/settings.js there is this code defining influxdb version:
and Daqstore type has 3 options:
However on the settings tab only two are selectable: (SqLite and Influxdb which is be default is influxdb V2)
Again, what I wanna do is to send DAQ value to influxdb 1.8, I can actually do this by changing the code under folder ./server/runtime/storage/influxdb.index.js
however, If I change this code, the settings tab UI will not change accordingly to set username,password and database name for influxdb V1.8
Hoping for your help.
Thanks and regards
Henjoe
Beta Was this translation helpful? Give feedback.
All reactions