Giter VIP home page Giter VIP logo

node-red-contrib-influxdb's Introduction

node-red-contrib-influxdb

Node-RED nodes to write and query data from an InfluxDB time series database.

These nodes support both InfluxDB 1.x and InfluxDb 2.0 databases selected using the Version combo box in the configuration node. See the documentation of the different nodes to understand the options provided by the different versions. Currently the node uses two client libraries.

When version 1.x is selected these nodes use the influxDB 1.x client for node.js, specifically calling the writePoints(), and query() methods. Currently they can only communicate with one influxdb host. These nodes are used for writing and querying data in InfluxDB 1.x to 1.8+.

When version 1.8-flux is selected, the nodes use the influxDB 2.0 API compatibility endpoints available in the InfluxDB 2.0 client libraries for node.js. These nodes are used for writing and querying data with Flux in InfluxDB 1.8+.

When version 2.0 is selected, the nodes make use of the InfluxDB 2.0 client libraries for writing and querying data with Flux in InfluxDB 2.0.

Prerequisites

To run this you'll need access to an InfluxDB database version 1.x, 1.8+ or 2.0. See the InfluxDB site for more information. The latest release of this node has been tested with InfluxDB 1.8 and 2.0. This node supports Node.js 10.x, 12.x and 14.x LTS releases. It does not support Node.js 8.x. This node does not support Node-RED before version 1.0.

Install

You can use the Node-RED Manage Palette feature, or run the following command in the root directory of your Node-RED install. Usually this is ~/.node-red .

npm install node-red-contrib-influxdb

Usage

Nodes to write and query data from an influxdb time series database. Supports InfluxDb versions 1.x to 2.0.

Input Node

Queries one or more measurements in an influxdb database. The query is specified in the node configuration or in the msg.query property. Setting it in the node will override the msg.query. The result is returned in msg.payload.

With a v1.x InfluxDb configuration, use the InfluxQL query syntax. With a v1.8-Flux or 2.0 configuration, use the Flux query syntax.

For example, here is a simple flow to query all of the points in the test measurement of the test database. The query is in the configuration of the influxdb input node (copy and paste to your Node-RED editor). We are using a v1.x InfluxDb here, so an InfluxQL query is used.

[{"id":"39aa2ca9.804da4","type":"debug","z":"6256f76b.e596d8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":530,"y":100,"wires":[]},{"id":"262a3923.e7b216","type":"influxdb in","z":"6256f76b.e596d8","influxdb":"eeb221fb.ab27f","name":"","query":"SELECT * from test","rawOutput":false,"precision":"","retentionPolicy":"","org":"my-org","x":310,"y":100,"wires":[["39aa2ca9.804da4"]]},{"id":"803d82f.ff80f8","type":"inject","z":"6256f76b.e596d8","name":"","repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":100,"y":100,"wires":[["262a3923.e7b216"]]},{"id":"eeb221fb.ab27f","type":"influxdb","hostname":"127.0.0.1","port":"8086","protocol":"http","database":"test","name":"test","usetls":true,"tls":"d50d0c9f.31e858","influxdbVersion":"1.x","url":"http://localhost:8086","rejectUnauthorized":true},{"id":"d50d0c9f.31e858","type":"tls-config","name":"","cert":"","key":"","ca":"","certname":"","keyname":"","caname":"","servername":"","verifyservercert":false}]

In this example, we query the same database for all points from a day ago using a 1.8-flux configuration using the Flux query language:

[{"id":"dd32f825.863798","type":"influxdb in","z":"6256f76b.e596d8","influxdb":"2ff2a476.a6d2ec","name":"","query":"from(bucket: \"test/autogen\") |> range(start: -1d, stop: now())","rawOutput":false,"precision":"","retentionPolicy":"","org":"my-org","x":410,"y":220,"wires":[["17314806.c732c8"]]},{"id":"17314806.c732c8","type":"debug","z":"6256f76b.e596d8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":670,"y":280,"wires":[]},{"id":"eadef241.cf6fd","type":"inject","z":"6256f76b.e596d8","name":"","repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":100,"y":160,"wires":[["dd32f825.863798"]]},{"id":"2ff2a476.a6d2ec","type":"influxdb","hostname":"127.0.0.1","port":"8086","protocol":"http","database":"database","name":"test 1.8 flux","usetls":false,"tls":"d50d0c9f.31e858","influxdbVersion":"1.8-flux","url":"https://localhost:8086","rejectUnauthorized":false},{"id":"d50d0c9f.31e858","type":"tls-config","name":"","cert":"","key":"","ca":"","certname":"","keyname":"","caname":"","servername":"","verifyservercert":false}]

This flow performs the same, but using the msg.query property:

[{"id":"2d5d7690.e5e77a","type":"influxdb in","z":"6256f76b.e596d8","influxdb":"2ff2a476.a6d2ec","name":"","query":"","rawOutput":false,"precision":"","retentionPolicy":"","org":"my-org","x":300,"y":380,"wires":[["6ab91739.fa71b8"]]},{"id":"6ab91739.fa71b8","type":"debug","z":"6256f76b.e596d8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":490,"y":380,"wires":[]},{"id":"daff744d.5538c8","type":"function","z":"6256f76b.e596d8","name":"set query","func":"msg.query = 'from(bucket: \"test/autogen\") |> range(start: -1d, stop: now())'\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":240,"y":300,"wires":[["2d5d7690.e5e77a"]]},{"id":"3e65472c.652658","type":"inject","z":"6256f76b.e596d8","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":100,"y":300,"wires":[["daff744d.5538c8"]]},{"id":"2ff2a476.a6d2ec","type":"influxdb","hostname":"127.0.0.1","port":"8086","protocol":"http","database":"database","name":"test 1.8 flux","usetls":false,"tls":"d50d0c9f.31e858","influxdbVersion":"1.8-flux","url":"https://localhost:8086","rejectUnauthorized":false},{"id":"d50d0c9f.31e858","type":"tls-config","name":"","cert":"","key":"","ca":"","certname":"","keyname":"","caname":"","servername":"","verifyservercert":false}]

The function node in this flow sets the msg.query property as follows:

msg.query = 'from(bucket: "test/autogen") |> range(start: -1d, stop: now())'
return msg;

Output Node

Writes one or more points (fields and tags) to a measurement.

The fields and tags to write are in msg.payload. If the message is a string, number, or boolean, it will be written as a single field to the specified measurement called value.

Note: Javascript numbers are always written as a float. When using the 1.8-flux or 2.0 configuration, you can explicitly write an integer using a number in a string with an 'i' suffix, for example, to write the integer 1234 use the string '1234i'. This is not supported using 1.x configurations; all numbers are written as float values.

For example, the following flow injects a single random field called value into the measurement test in the database test with the current timestamp.

[{"id":"17bd4566.e842bb","type":"influxdb out","z":"6256f76b.e596d8","influxdb":"eeb221fb.ab27f","name":"","measurement":"test","precision":"","retentionPolicy":"","database":"","retentionPolicyV18Flux":"","org":"","bucket":"","x":440,"y":460,"wires":[]},{"id":"be93bfeb.416c4","type":"function","z":"6256f76b.e596d8","name":"single value","func":"msg.payload = Math.random()*10;\nreturn msg;","outputs":1,"noerr":0,"x":270,"y":460,"wires":[["17bd4566.e842bb"]]},{"id":"31f9f174.ce060e","type":"inject","z":"6256f76b.e596d8","name":"","repeat":"","crontab":"","once":false,"topic":"","payload":"","payloadType":"date","x":120,"y":460,"wires":[["be93bfeb.416c4"]]},{"id":"eeb221fb.ab27f","type":"influxdb","hostname":"127.0.0.1","port":"8086","protocol":"http","database":"test","name":"test","usetls":true,"tls":"d50d0c9f.31e858","influxdbVersion":"1.x","url":"http://localhost:8086","rejectUnauthorized":true},{"id":"d50d0c9f.31e858","type":"tls-config","name":"","cert":"","key":"","ca":"","certname":"","keyname":"","caname":"","servername":"","verifyservercert":false}]

The function node consists of the following:

msg.payload = Math.random()*10;
return msg;

If msg.payload is an object containing multiple properties, all of the the fields will be written to the measurement.

For example, the following flow injects four fields, intValue, numValue, randomValue and strValue into the test2 measurement with the current timestamp using a 1.8-Flux configuration.

[{"id":"6849966e.e53528","type":"inject","z":"6256f76b.e596d8","name":"","repeat":"","crontab":"","once":false,"topic":"","payload":"","payloadType":"date","x":120,"y":520,"wires":[["c8865cec.261cd"]]},{"id":"c8865cec.261cd","type":"function","z":"6256f76b.e596d8","name":"Fields","func":"msg.payload = {\n    intValue: '12i',\n    numValue: 123.0,\n    strValue: \"message\",\n    randomValue: Math.random()*10\n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":268,"y":520,"wires":[["72bf0ba5.6e63d4"]]},{"id":"72bf0ba5.6e63d4","type":"influxdb out","z":"6256f76b.e596d8","influxdb":"2ff2a476.a6d2ec","name":"","measurement":"test2","precision":"","retentionPolicy":"","database":"test","precisionV18FluxV20":"ms","retentionPolicyV18Flux":"","org":"","bucket":"","x":458,"y":520,"wires":[]},{"id":"2ff2a476.a6d2ec","type":"influxdb","hostname":"127.0.0.1","port":"8086","protocol":"http","database":"database","name":"test 1.8 flux","usetls":false,"tls":"d50d0c9f.31e858","influxdbVersion":"1.8-flux","url":"https://localhost:8086","rejectUnauthorized":false},{"id":"d50d0c9f.31e858","type":"tls-config","name":"","cert":"","key":"","ca":"","certname":"","keyname":"","caname":"","servername":"","verifyservercert":false}]

The function node in the flow above consists of the following:

msg.payload = {
    intValue: '10i',
    numValue: 123.0,
    strValue: "message",
    randomValue: Math.random()*10
}
return msg;

If msg.payload is an array containing two objects, the first object will be written as the set of named fields, the second is the set of named tags.

For example, the following simple flow uses an InfluxDb 2.0 database and injects four fields as above, along with two tags, tag1 and tag2:

[{"id":"15c79e62.9294c2","type":"inject","z":"6256f76b.e596d8","name":"","repeat":"","crontab":"","once":false,"topic":"","payload":"","payloadType":"date","x":120,"y":560,"wires":[["a97b005f.7f22e"]]},{"id":"a97b005f.7f22e","type":"function","z":"6256f76b.e596d8","name":"Fields and Tags","func":"msg.payload = [{\n    intValue: '10i',\n    numValue: 12,\n    randomValue: Math.random()*10,\n    strValue: \"message2\"\n},\n{\n    tag1:\"sensor1\",\n    tag2:\"device2\"\n}];\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":280,"y":560,"wires":[["a91d522b.9a077"]]},{"id":"a91d522b.9a077","type":"influxdb out","z":"6256f76b.e596d8","influxdb":"5d7e54ca.019d44","name":"","measurement":"test","precision":"ms","retentionPolicy":"","database":"test","precisionV18FluxV20":"ms","retentionPolicyV18Flux":"","org":"my-org","bucket":"test","x":510,"y":560,"wires":[]},{"id":"5d7e54ca.019d44","type":"influxdb","hostname":"127.0.0.1","port":"8086","protocol":"http","database":"database","name":"","usetls":false,"tls":"d50d0c9f.31e858","influxdbVersion":"2.0","url":"https://localhost:9999","rejectUnauthorized":false},{"id":"d50d0c9f.31e858","type":"tls-config","name":"","cert":"","key":"","ca":"","certname":"","keyname":"","caname":"","servername":"","verifyservercert":false}]

The function node consists of the following code:

msg.payload = [{
    intValue: '10i',
    numValue: 12,
    randomValue: Math.random()*10,
    strValue: "message2"
},
{
    tag1:"sensor1",
    tag2:"device2"
}];
return msg;

Finally, if msg.payload is an array of arrays, it will be written as a series of points containing fields and tags.

For example, the following flow injects two points into an InfluxDb 2.0 database with timestamps specified.

[{"id":"a67139c7.15ec68","type":"inject","z":"6256f76b.e596d8","name":"","repeat":"","crontab":"","once":false,"topic":"","payload":"","payloadType":"date","x":120,"y":620,"wires":[["15047e0e.e613f2"]]},{"id":"15047e0e.e613f2","type":"function","z":"6256f76b.e596d8","name":"multiple readings","func":"msg.payload = [\n    [{\n        numValue: 10,\n        randomValue: Math.random()*10,\n        strValue: \"message1\",\n        time: new Date().getTime()-1\n    },\n    {\n        tag1:\"sensor1\",\n        tag2:\"device2\"\n    }],\n    [{\n        numValue: 20,\n        randomValue: Math.random()*10,\n        strValue: \"message2\",\n        time: new Date().getTime()\n    },\n    {\n        tag1:\"sensor1\",\n        tag2:\"device2\"\n    }]\n];\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":320,"y":620,"wires":[["8caaee80.33352"]]},{"id":"8caaee80.33352","type":"influxdb out","z":"6256f76b.e596d8","influxdb":"5d7e54ca.019d44","name":"","measurement":"test","precision":"ms","retentionPolicy":"","database":"test","precisionV18FluxV20":"ms","retentionPolicyV18Flux":"","org":"my-org","bucket":"test","x":590,"y":620,"wires":[]},{"id":"5d7e54ca.019d44","type":"influxdb","hostname":"127.0.0.1","port":"8086","protocol":"http","database":"database","name":"","usetls":false,"tls":"d50d0c9f.31e858","influxdbVersion":"2.0","url":"https://localhost:9999","rejectUnauthorized":false},{"id":"d50d0c9f.31e858","type":"tls-config","name":"","cert":"","key":"","ca":"","certname":"","keyname":"","caname":"","servername":"","verifyservercert":false}]

The function node in the above flow looks as follows:

msg.payload = [
    [{
        intValue: '9i',
        numValue: 10,
        randomValue: Math.random()*10,
        strValue: "message1",
        time: new Date().getTime()-1
    },
    {
        tag1:"sensor1",
        tag2:"device2"
    }],
    [{
        intValue: '11i',
        numValue: 20,
        randomValue: Math.random()*10,
        strValue: "message2",
        time: new Date().getTime()
    },
    {
        tag1:"sensor1",
        tag2:"device2"
    }]
];
return msg;

Note how timestamps are specified here - the number of milliseconds since 1 January 1970 00:00:00 UTC. In this case do not forget to set the precision to "ms" in "Time Precision" of the "Influx Out Node". We make sure the timestamps are a different so the first element doesn't get overwritten by the second.

The Batch Output Node

The batch output node (influx batch) sends a list of points together in a batch to InfluxDB in a slightly different format from the output node. Using the batch node you must specify the measurement name to write into as well as a list of tag and field values. Optionally, you can specify the timestamp for the point, defaulting to the current time.

Note: Javascript numbers are always written as a float. As in the output node, when using the 1.8-flux or 2.0 configuration, you can explicitly write an integer using a number in a string with an 'i' suffix, for example, to write the integer 1234 use the string '1234i'. This is not supported using 1.x configurations; all numbers are written as float values.

By default the node will write timestamps using ms precision since that's what JavaScript gives us. if you specify the timestamp as a Date object, we'll convert it to milliseconds.

If you provide a string or number as the timestamp, we'll pass it straight into Influx to parse using the specified precision, or the default precision in nanoseconds if it is left unspecified.

Note that the default precision is nanoseconds, so if you pass in a number such as date.getTime(), and do not specify millisecond precision, your timestamp will be orders of magnitude incorrect.

The following example flow writes two points to two measurements, setting the timestamp to the current date.

[{"id":"4a271a88.499184","type":"function","z":"87205ed6.329bc","name":"multiple measurement points","func":"msg.payload = [\n    {\n        measurement: \"weather_sensor\",\n        fields: {\n            temp: 5.5,\n            light: 678,\n            humidity: 51\n        },\n        tags:{\n            location:\"garden\"\n        },\n        timestamp: new Date()\n    },\n    {\n        measurement: \"alarm_sensor\",\n        fields: {\n            proximity: 999,\n            temp: 19.5\n        },\n        tags:{\n            location:\"home\"\n        },\n        timestamp: new Date()\n    }\n];\nreturn msg;","outputs":1,"noerr":0,"x":400,"y":280,"wires":[["748a06bd.675ed8"]]},{"id":"6493a442.1cdcbc","type":"inject","z":"87205ed6.329bc","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"x":140,"y":220,"wires":[["4a271a88.499184"]]},{"id":"748a06bd.675ed8","type":"influxdb batch","z":"87205ed6.329bc","influxdb":"6ca8bde.9eb2f44","name":"","x":670,"y":220,"wires":[]},{"id":"6ca8bde.9eb2f44","type":"influxdb","z":"","hostname":"localhost","port":"8086","protocol":"https","database":"new_db","name":"","usetls":true,"tls":"f7f39f4e.896ae"},{"id":"f7f39f4e.896ae","type":"tls-config","z":"","name":"local-tls","cert":"","key":"","ca":"","certname":"","keyname":"","caname":"","verifyservercert":false}]

The function node generates sample points as follows:

msg.payload = [
    {
        measurement: "weather_sensor",
        fields: {
            temp: 5.5,
            light: 678,
            humidity: 51
        },
        tags:{
            location:"garden"
        },
        timestamp: new Date()
    },
    {
        measurement: "alarm_sensor",
        fields: {
            proximity: 999,
            temp: 19.5
        },
        tags:{
            location:"home"
        },
        timestamp: new Date()
    }
];
return msg;

Catching Failed Reads and Writes

Errors in reads and writes can be caught using the node-red catch node as usual. Standard error information is availlable in the default msg.error field; additional information about the underlying error is in the msg.influx_error field. Currently, this includes the HTTP status code returned from the influxdb server. The influx-read node will always throw a 503, whereas the write nodes will include other status codes as detailed in the Influx API documentation.

Support for Complete Node

All of the nodes make the required done() call to support the complete node as described in the related blog post. When an error is logged, catch nodes will receive a message, but an associated complete node will not.

node-red-contrib-influxdb's People

Contributors

aarmijo avatar dependabot[bot] avatar elvistheking avatar jmikerq avatar mal-w avatar mattocchi avatar mblackstock avatar suda avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

node-red-contrib-influxdb's Issues

batch node not working -

28 May 12:03:15 - [info] Node-RED version: v1.0.6
28 May 12:03:15 - [info] Node.js version: v12.13.0
28 May 12:03:15 - [info] Darwin 18.7.0 x64 LE

While the 'influxdb out' node is working fine, the 'influx batch' node does not work.

Using the example flow provided in the nodes flow page, the following error is reported in a catch node:

Error: write EPROTO 4488598976:error:1408F10B:SSL routines:ssl3_get_record:wrong version number:../deps/openssl/openssl/ssl/record/ssl3_record.c:332:

and the stack shows

Error: write EPROTO 4488598976:error:1408F10B:SSL routines:ssl3_get_record:wrong version number:../deps/openssl/openssl/ssl/record/ssl3_record.c:332: at WriteWrap.onWriteComplete [as oncomplete] (internal/stream_base_commons.js:87:16)

Write tag with specific timestamp

Hello,
is possible to write data to database with specific timestamp?

I'm handling with data from MQTT and sometimes data has a delay (due connection issue). They are written to database with same timestamp when they all come. My option is sending timestamp at MQTT message and use it for timestamp for Influx.

Thank you.

Support for InfluxDB 2.0 Cloud

Hi, thank you for your node-plugin!

I've not been able to test it yet as I'm using the 2.0 Cloud version of InfluxDB.
Please excuse my usage of the "Issue-Tracker" as I don't know how to start a normal conversation over here.

May it be possible to support the InfluxDB 2.0 Cloud (API) to write (and read) to the InfluxDB Cloud database?
I would like to run InfluxDB in the cloud as my Node Red instance runs on an internet server, too. Bus therefore I cannot run InfluxDB on a local machine.

I would be very grateful.
Thank you! Best regards!

Unable to write a value to influxdb

I am trying to write an MQTT message to influxdb, and getting strange results. The message originates in OwnTracks, so it looks like so:

{
  "_type":"location",
  "acc":39,
  "alt":195,
  "batt":61,
  "conn":"w",
  "inregions":["Home"],
  "lat":55.0,
  "lon":37.0,
  "t":"p",
  "tid":"s5",
  "tst":1548442037,
  "vac":16,
  "vel":0
}

I am feeding it through the json parse node and straight into influxdb, and getting this error back:

Error: A 400 Bad Request error occurred: {"error":"unable to parse 'track _type=\"location\",acc=39,alt=195,batt=61,conn=\"w\",inregions=Home,lat=55.0,lon=37.0,t=\"u\",tid=\"s5\",tst=1548436524,vac=16,vel=0': invalid boolean"}

Other sources of data logged into influxdb, which are also blocks of json taken straight out of MQTT messages, do not have any problems, and I can't help but notice that something strange happened to inregions. Am I doing something wrong, or are arrays of strings not being handled correctly?

Batch node expects the time to be in nanoseconds

When writing to influx using the batch node and providing a timestamp the readme says that it should be in milliseconds or should be a javascript Date object. It appears that in fact the time has to be provided in nanoseconds.

Write to influxDB interval

Dear Sir, may I know if there is a limitation to write data on influxDB?
I have this data that updates data every 100ms interval, what I want is to write data to influxDB using the influxdb out node at that speed interval (100ms), but I notice that on my database my data is in somehow 1-5s interval (randomly). I am just thinking that is there any limitations on the speed to write data in influxdb out?
Thank you.

Looking forward.

Writing with retention Policies

Hi,

Thanks for your node contribution, I use it a lot and really handy!

When using retention policies, the data does not end up in the measurements. If you check the log file you will see a 204 http return code that will say it is cached. But somehow it is not ending up into the DB.

Could you please check this?

Influx DB query node won't return multiple measurements properly

When using a query node for multiple measurements the data is all concatenated together. So it isn't clear what segment of data belongs to which measurement.

Is there a way to make it return a dictionary for each measurement with the key being the measurement name?

Add explicit outpouts to the influx out and influx batch nodes

On the same vein as the error handing in #46 would it be ok to add result handling for successes of influx writes?

What I'm thinking is we add an output to influx batch with a .then on the writePoints which sends a message containing the 204 for the successful write.

Should I add this to the influx batch node or do you think it belongs in a separate node?

Some Errors in NodeRed Logs

Hello, I have a influxdb nonde inserting records into my InfluxDb Database, the problem is that sometimes, without apparent reason, I get:

Error: Internal Server Error
Error: No host available

What is the timeout? My hosts are always available!

Thank you

Unable to write integer to influxDB

The syntax for integer is ###i, but assigning such value in the payload would be treated as a string when passing it through the in node. Regular numeric values are treated as float in influxdb.

400 Bad Request

My JS Node (output gets fed into Influx node)


/* Example Payload

"{ "ServiceId": "urn:upnp-org:serviceId:TemperatureSensor1", "CurrentTemperature": 18.62, "DeviceId": 420, "DeviceName": "Utetemperatur", "Time": 1527632216, "RoomName": "Garage/Ute", "OldCurrentTemperature": 18.68, "Variable": "CurrentTemperature", "RoomId": 18, "DeviceType": "urn:schemas-micasaverde-com:device:TemperatureSensor:1" }"

*/

let pl = msg.payload;
if (pl === "testament_msg")
    return null;
pl = JSON.parse(pl);     

return {
    measurement: pl.DeviceName + " - " + pl.RoomName,
    payload: [{
        v: pl[pl.Variable],
    },{
        //serviceId: pl.ServiceId,
        deviceId: pl.DeviceId,
        deviceName: pl.DeviceName,
        roomId: pl.RoomId,
        roomName: pl.RoomName,
        //deviceType: pl.DeviceType            
    }]
};

Trying to write the following msg object:
{"measurement":"Kontakt Tvrum - TV-rum","payload":[{"v":1},{"deviceId":474,"deviceName":"Kontakt Tvrum","roomId":7,"roomName":"TV-rum"}],"_msgid":"1fbecdf8.afdac2"}

But getting
Error: A 400 Bad Request error occurred: {"error":"unable to parse 'Kontakt Tvrum - TV-rum,deviceId=474,deviceName=Kontakt\\ Tvrum,roomId=7,roomName=TV-rum v=1': invalid field format"}

Inserting a value with a timestamp, tags and no fields results in a 400

Hi, I'm trying to insert a value in InfluxDb with just a timestamp and tags:

This works fine when setting a field, here "value":
msg.payload = [
{value: 1, time: 1},
{tag: "Test"}
];

This doesn't work with just the timestamp (no "value" field):
msg.payload = [{time: 1}, {tag: "Test"}];

=> Error: A 400 Bad Request error occurred:
{"error":"unable to parse 'mymeasurement,tag=Test': invalid field format"}

Same exemple works using the CLI:

insert mymeasurement tag="Test" 1
select * from mymeasurement
name: mymeasurement
time tag
1 Test

Workaround is to add a dummy field, but ideally I'd like not to

15 Jun 13:47:18 - [error] [influxdb out:6c73de65.8cb15] Error: self signed certificate

Mike, I'm running influxdb 1.1 on a RPI far a long while.
I've just added HTTPs to influx using a self singed cert as per
https://docs.influxdata.com/influxdb/v1.2/administration/https_setup/#setup-https-with-a-self-signed-certificate.

HTTPS is working, I can connect using Grafana and the old influx web ui.
I get the error
15 Jun 13:47:18 - [error] [influxdb out:6c73de65.8cb15] Error: self signed certificate

Feels like the issue is in node-influx?
Any thoughts.

All best
Lawrence

Line Protocol Support?

Hi Mike,

first of all thank you very much for your influxd node.
I would like to ask if it is supporting the influxdb line protocol? I have got everything to work but only when I format the data I am sending from my microcontroller as JSON. Then I have to put a JSON node between my receiving node and the influxdb node.
As I am a complete beginner it could be that I am doing something wrong.

Kind regards,
Tom

InfluxDB v2.0

Aloha, thanks for your node contribution, I use it a lot! I am migrating some systems to Influx 2 and currently I am just using raw queries in Node-RED to interact with InfluxDB2 API. I was considering making a new set of contrib nodes specifically for InfluxDB 2, but wanted to get your take on it first. Do you think a new project is justified? Or perhaps you would like to roll support for V2 into this project? The official node client is out and works great.

Here are some references:

influxdb out inserts two records (duplicates)

when I inset one record in an influxdb database I get the record inserted twice with a very little difference in time:
Record format (passed as msg.payload):
Capture

If I query the database

> Select * FROM meteo WHERE time >= '2019-03-20T08:05:00Z' and "deviceId"='Jardin' limit 2
name: meteo
time                           HPa  deviceId hAire hCrudo hSuelo l/m2 temp
----                           ---  -------- ----- ------ ------ ---- ----
2019-03-20T09:09:13.709229151Z 1030 Jardin   56    195    36     0    7.1
2019-03-20T09:09:13.712843732Z 1030 Jardin   56    195    36     0    7.1
>

I only call influxdbout once, but there are two records with less than 4/1000 of a second difference.
Is this a known bug or I am doing something wrong? (I have not found it reported)
Regards

"Error: connect ECONNREFUSED 127.0.0.1:8086"

I have:

  1. setup Docker on a Pi3 B+
  2. successfully installed InfluxDB on Docker
  3. successfully created a database and user
  4. successfully inserted data via Raspbian command line
  5. successfully installed Node-RED on Docker
  6. successfully installed node-red-contrib-influxdb
  7. successfully created a simple flow using Output Node example modified to talk to localhost:8086 and my DB name

executing the flow gives the standard message that it successfully injected timestamp, whereas looking at the debug messages, I get the ECONNREFUSED message

I suspect this connection issue is related to trying to connect from the Node-RED connection which is within its own containers to InfluxDB which is a different container.

Have you ever seen this?
Is this container to container trust?

How to set time zone?

If i query the database, the timestamps are in GMT and do not consider the timezone of the client.
Also, i couldn't find a possibility to set the time zone manually.

Configuration is missing in node-red API GET request

Hey,

I am not sure if this is an issue with node-red-contrib-influxdb or node-red themselves, so I would ask you first.

The issue is; when you GET a flow which includes an influxdb node via node-red API GET localhost:1880/flow/{id}, the configuration of the influxdb node is not included in the response. So, if you POST the same flow in another node-red instance for example you get
[error] [influxdb out:2ebbdce2.4d8274] Configuration missing

However, the configuration can be found if you export the same flow via the node-red UI

An example of the missing config

{
   "id": "24b1fa97.98b266",
   "type": "influxdb",
   "z": "",
   "hostname": "127.0.0.1",
   "port": "8086",
   "protocol": "http",
   "database": "images",
   "name": ""
 } 

Thank you

Insert all topic From mqtt

Hello.
How Can I insert to InfluxDB from all topic mqtt?
I used Node -red Mqtt # -> influxDB out
What me need to insert in Measurement that would get the name of topics?

Status on successful operation?

I am able to use the catch node to trap errors on a DB write, but how do I react to a successful operation? This node doesn't appear to set a status on success, and the write has no output. So for example, I have a flow that accepts an HTTP POST, formats the data, and writes it to InfluxDB. I can catch an error and send an appropriate HTTP response (4xx, 5xx, etc). But since I can't seem to trap a successful operation, I have no way to send a 200 OK response from my flow, other than to just trust that the operation succeeded. Maybe I'm missing something obvious?

InfluxDB out node set timestamp manually does not insert values

When using the influxdb out node to manually set a timestamp, the values are not written in the database (no error is returned or visible in the debug console).

Example code of the function before the node:

msg.payload = {
    time: new Date().getTime(),
    measurement1: 2,
    measurement1: 0
}

This is not written to the database. When leaving the time field out of the object, everything works as expected.

I am running the latest version of influxDB (1.2)

Multiple measurement at the same time

First, thank you for your influx node for nodered.

I have a question, is there a way to send multiple different measurements at the same time ? A few is ok but when I increase the number, the influxdb node will send me a timeout error.

Thank you for your help.

Benjamin

Trouble with strings from Node-Red to InfluxDB

Something is wrong with the string I'm extracting from a Modbus buffer and transmitting to InfluxDB. The string looks right everywhere I debug it, but it's clear from InfluxDB queries that there is an issue with the string it records.
Here's my function as it sends to the db:

gwSerialString = "GTYA002018";
gwSerial = msg.responseBuffer.buffer.toString('utf8',0,16);
gwPower  = msg.responseBuffer.buffer.readInt32BE(28)/10;

msg.payload = [
    {
        measurement: "test",
        fields: {
            power: gwPower
        },
        tags:{
            serialString: gwSerialString,
            serial: gwSerial
        },
        timestamp: new Date()
    }
];
return msg;

Which appears in the debug window to return the same string as follows:
screenshot 2018-06-27 21 08 11

However, the InfluxDB does not see them the same way because trying to use the hard coded string works fine but using the one passed from the buffer.toString gives the following error when used in queries:
found �GTYA002018, expected identifier, string, number, bool
Which interestingly when pasted into this window and previewed I can now see an there's an extra character I haven't seen before before the expected string. This may be the clue as to where the issue is coming from.

I don't think anything is wrong with the batch uploader, but I cannot figure out where this string is getting messed up or how to "cleanse" it appropriately.

Timestamp issue in samples

I today detected an issue when using the "out" node.
We tried to use the provided sample but the inserted sets were always dated to UNIX start date in 1970. After some time we recognized that everything works fine if we do not use the ".getTime()" for the Date object.

I used:
InfluxDB: 1.7.10
node-red-contrib-influxdb 0.4.0
Node-RED 1.0.4 on latest non-LTS NodeJS

Couldn't figure out whether this is already fixed.

Enable Token authentication

I am using Influx Cloud 2.0. In this hosted influxdb, the access is regulated by a token auth, but I don't see how to use your node to connect to influx cloud.

Should be good to add output on "influxdb out"

Hello,

It should be good to add an output to "influxdb out" node as callback, for example for me to notify success on the node red dashboard and empty the form.

What do you think ?

Regards,

no need to set 'advancedOptions' flag in backend

There is no need to set this configuraiton in the backend since it is just a front end UI thing. Just show the advanced options if retentionPolicy and timeprecision are set to non-default values or not set.

Unable to write null values to db

I find I am unable to push null values to the db. Sending a message {topic: some_topic, payload: null} results in the error
Error: {"error":"unable to parse 'tydwr value=null': invalid number"}
Here is a sample flow:
[
{
"id": "d1592df1.f9427",
"type": "inject",
"z": "e122f88c.3fc3c8",
"name": "",
"topic": "",
"payload": "",
"payloadType": "date",
"repeat": "",
"crontab": "",
"once": false,
"x": 189.5,
"y": 1141,
"wires": [
[
"8d921e96.1de868"
]
]
},
{
"id": "8d921e96.1de868",
"type": "function",
"z": "e122f88c.3fc3c8",
"name": "Null payload",
"func": "msg = {topic: "bedroom/radtemp", payload: null}\nreturn msg;",
"outputs": 1,
"noerr": 0,
"x": 377.5,
"y": 1140,
"wires": [
[
"e18ce4c0.21f96",
"eeb056ca.f8c358"
]
]
},
{
"id": "eeb056ca.f8c358",
"type": "debug",
"z": "e122f88c.3fc3c8",
"name": "",
"active": true,
"console": "false",
"complete": "true",
"x": 722.5,
"y": 957,
"wires": []
},
{
"id": "e18ce4c0.21f96",
"type": "influxdb out",
"z": "e122f88c.3fc3c8",
"influxdb": "55ac6d48.e3ffbc",
"name": "",
"measurement": "tydwr",
"x": 994,
"y": 469,
"wires": []
},
{
"id": "55ac6d48.e3ffbc",
"type": "influxdb",
"z": "",
"hostname": "127.0.0.1",
"port": "8086",
"protocol": "http",
"database": "tydwr",
"name": "localhost_tydwr"
}
]

Insert value + tags

Hello!

Your contribution is really helping me! Thank you!
I'm already able to insert data into my Influx database, but there's something to be done so it would be perfet!

How would I add tags to the valeu?

The name of my measurement is "variaveis"
I want to add information on "value" --this is working
But also want to complete "desc" and "tag" values... and this is my problem. Would you help me?

Thanks in advance!

captura

Influx 1.2.2-1 influxdb output error

I had a working flow with influx v0.13 and earlier node-red-contrib-influxdb.

I installed a new RPI3 with the actual sw components (Influx 1.2.2-1) and the same flow and all the influxdb output nodes in node-red produce the following error at deploying:

TypeError: Object function Object() { [native code] } has no method 'assign'

The function before influxdb node as an example is the following: ( I wouldn't think that the problem is here)

msg.payload = [{
value: Number(msg.payload)
},
{
sensor:"moisture"
}];
return msg;

Added support for for influxdb chunk for large datasets

Trying to utilize influxdb and tensorflow to train from large datasets. Would like to 'stream' the query, transform it to tensorflow dataset to be consumed by tensorflow js. If this is out of scope of this project, please let me know.

A 400 Bad Request for some object keys

I try to insert a bunch of values that I query from my heatpump controller but for some of the values I get an A 400 Bad Request.
At first i thought that it is caused by the Umlauts but they work for some values, so I have no idea what causes this problem.
This is the object I send into the out node (copy&past from the debug panel, so not properly json formated ;-) ):

Vorlauf: 32.5
Rücklauf: 30.1
Rückl.-Soll: 15
Rückl.-Extern: 24.9
Heissgas: 28.8
Aussentemperatur: 34.3
Mitteltemperatur: 23.3
Warmwasser-Ist: 49
Warmwasser-Soll: 50
Wärmequelle-Ein: 24.2
Wärmequelle-Aus: 24.4
Mischkreis1-Vorlauf: 24.3
Mischkreis1-VL-Soll: 20
Solarkollektor: 5
Solarspeicher: 150
Externe-Energ.Quelle: 5
Vorlauf-max.: 64
Ansaug-VD: 29.5
Überhitzung: 5
Überhitzung-Soll: 6

And that's the error message:

Error: A 400 Bad Request error occurred: {"error":"unable to parse 'temperatures Ansaug-VD=29.5,Aussentemperatur=34.3,Externe-Energ.Quelle=5,Heissgas=28.8,Mischkreis1-VL-Soll=20,Mischkreis1-Vorlauf=24.3,Mitteltemperatur=23.3,Rückl.-Extern=24.9,Rückl.-Soll=15,Rücklauf=30.1,Solarkollektor=5,Solarspeicher=150,Vorlauf=32.5,Vorlauf-max.=64,Warmwasser-Ist=49,Warmwasser-Soll=50,Wärmequelle-Aus=24.4,Wärmequelle-Ein=24.2,Überhitzung=5,Überhitzung': invalid field format"}

If I reduce the object to the first 7 elements, it works, but when I include "Warmwasser-Ist" I get the error.
It doesnt's make sense to me at all.

make precision property available

Mike Looking at influx library the IQueryOptions exposes the precision property making that available would make sense.

Also I could see some users wanting an epoch returned instead of default RFC3339 time stamp
However to get that you need to call epoch=[ns,u,µ,ms,s,m,h] in the HTTP/s api
https://docs.influxdata.com/influxdb/v1.2/tools/api/#query-string-parameters
But the influx library doesn't support this

https://groups.google.com/forum/#!searchin/node-red/influxdb%7Csort:relevance/node-red/BJp_MEhoZIE/QbfSZwbaCwAJ

FEATURE REQUEST: Reconfigure influx node at runtime

Would be more useful if all the configuration entered in the UI could be altered via a new node.

This would mean that the flows could be scaled and the only difference between them would be the JSON passed to it at startup.

What do you think?

Multiple Tag and Retention Policies for different Fields within Batch updater

Within a single Measurement I would like to assign different Tags to Fields and hopefully also define different retention policies for individual Fields. Is this something that can be done within a single Batch update function or is it something where I have to have functions for each unique combination and then have them use the same timestamp for each to help keep the database optimized?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.