Node-RED InfluxDB Integration
node-red-contrib-influxdb provides a collection of Node-RED nodes designed for seamless interaction with InfluxDB time series databases. It offers robust support for InfluxDB 1.x, InfluxDB 1.8 (leveraging 2.0 API compatibility with Flux queries), and native InfluxDB 2.0, allowing users to write and query data using both InfluxQL and Flux query languages. The current stable version is 0.7.0. The package maintains a steady release cadence, incorporating new features like request timeouts and addressing compatibility updates for InfluxDB versions and underlying Node.js runtimes. A key differentiator is its ability to handle multiple InfluxDB versions and query languages within a single set of nodes, adapting its internal client library based on the configuration.
Common errors
-
Error: A 401 Unauthorized error occurred: {"code":"unauthorized","message":"Unauthorized"}cause Incorrect authentication token, username/password, or using InfluxQL with InfluxDB 2.x which primarily uses Flux.fixFor InfluxDB 2.0, ensure the correct authentication token is provided in the configuration node. For InfluxDB 1.x, verify username/password. Also, ensure the query language (InfluxQL vs Flux) matches the InfluxDB version configured. InfluxDB 2.x primarily uses Flux for querying. -
ECONNREFUSED errors when writing data to influxDB
cause The InfluxDB server is not running, is configured on a different host or port, or a firewall is blocking the connection.fixVerify that your InfluxDB service is running and accessible from the Node-RED host. Check the hostname, port, and protocol settings in the 'influxdb' configuration node. Also, check for any firewall rules that might be blocking the connection. -
Error: "No query specified"
cause An 'influxdb in' (input) node was triggered without a query defined either in its configuration properties or in the incoming `msg.query` property.fixEnsure that the 'influxdb in' node has a valid InfluxQL or Flux query configured in its settings, or that the incoming message (`msg`) contains a `query` property with the desired query string.
Warnings
- breaking Node.js version 8.x is explicitly not supported. Users must use Node.js 10.x or later. Node-RED versions prior to 1.0 are also not supported.
- security A security vulnerability related to the `lodash` dependency was fixed. This may indicate potential risks in older versions if `lodash` was exploited.
- gotcha When writing integer values to InfluxDB 1.8-Flux or 2.0 configurations, JavaScript numbers are typically written as floats. To explicitly write an integer, you must append an 'i' suffix to the number within a string (e.g., '1234i'). This explicit integer type is not supported in 1.x configurations, where all numbers are treated as floats.
- breaking The default request timeout for InfluxDB 1.8 and 2.x configurations was introduced and defaults to 10 seconds. Longer-running queries or write operations might time out if this default is insufficient.
Install
-
npm install node-red-contrib-influxdb -
yarn add node-red-contrib-influxdb -
pnpm add node-red-contrib-influxdb
Imports
- influxdb in
This is a Node-RED node, added via the 'Manage Palette' and configured in the flow editor.
- influxdb out
This is a Node-RED node, added via the 'Manage Palette' and configured in the flow editor.
- influxdb batch
This is a Node-RED node, added via the 'Manage Palette' and configured in the flow editor.
- influxdb (config)
This is a Node-RED configuration node, accessed when setting up an 'influxdb in', 'out', or 'batch' node.
Quickstart
[{"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":false,"tls":"","influxdbVersion":"1.x","url":"http://localhost:8086","rejectUnauthorized":true}]