IMD SolutionComputing LibraryShop main store

How-to

Connect Node-RED to InfluxDB 2.6 with the v2 API

Edge computing and IIoT Published 6 min read

Short answer

Yes: node-red-contrib-influxdb writes to InfluxDB 2.6 over the v2 API. Set the configuration node to 2.0, enter the server URL and API token, then the organization and bucket, and confirm with one controlled test write that shows up in a query against that bucket.

On this page
  1. Which Node-RED package writes to InfluxDB 2.6?
  2. How do you fill in the v2 fields in the out node?
  3. Where do the token, organization ID and bucket come from?
  4. What single test write proves the connection?
  5. Why does the write succeed but the query shows nothing?
  6. What if the panel shows only username and database fields?
  7. How do you keep the token out of exported flows?
  8. Questions asked

Yes — and the whole setup is one package plus four settings. The node-red-contrib-influxdb package supports InfluxDB 1.x and InfluxDB 2.x in a single configuration node, so a Node-RED flow on an edge PC writes to an InfluxDB 2.6 server by choosing 2.0 mode and entering the URL, an API token, the organization and the bucket. This page walks it in the order you meet it: confirm the node, fill in the v2 fields, take the credentials from the server, prove the link with one test write, then fix the two failures that turn up most often.

Which Node-RED package writes to InfluxDB 2.6? #

node-red-contrib-influxdb does: the package's configuration node supports both InfluxDB 1.x and InfluxDB 2.0, selected with the Version combo box, so one install covers a 2.6 server, because 2.0 names the API generation rather than the minor release.

Install it from the palette in the Node-RED editor and restart the editor when prompted. The package provides nodes to save and to query time-series data, so the connection you build here later serves dashboards as well. InfluxDB 2.x serves its API under /api/v2/, which is what 2.0 mode speaks. Write down the release you installed: a later fault is either a compatibility problem or a connection problem, and the release plus the selected mode is what tells them apart.

How do you fill in the v2 fields in the out node? #

Open the InfluxDB out node, set Version to 2.0, then enter the URL and API token in the server configuration and the organization ID and bucket name on the node itself; the 1.x username and database fields are not used in this mode.

The v2 settings replace the old ones like this:

What it identifies 1.x mode 2.0 mode
Credentials Username and password API token
Destination Database Bucket
Account Not used Organization ID

The URL is the address of the InfluxDB service as the Node-RED host reaches it — test it from that host, not from an engineer's workstation, since routing and firewall rules differ by source. Copy the organization ID and bucket name from the server rather than retyping them: hist and hist-org differ by one keystroke and by one failed write. A token authorizes only what it was scoped to, so all four values must come from the same server and organization.

Where do the token, organization ID and bucket come from? #

All three come from the InfluxDB 2.6 server's own UI: generate an API token there, copy the organization ID, and create or pick the bucket — a bucket being the named location where the time-series data is stored, listed per organization.

Generate the token scoped to writing the one production bucket, and keep all-access tokens on the lab bench. The bucket list the API returns for an organization is the same list the UI shows, so when a bucket you expected is missing under a token, the token's scope is the first suspect and troubleshooting InfluxDB UI bucket access covers that fault class.

What single test write proves the connection? #

One inject, one point, one row: fire a single test message through the real out node, query the bucket for that measurement, and the connection is proven when exactly one row comes back carrying the value you sent.

  1. Wire an inject node directly into the InfluxDB out node configured in 2.0 mode.
  2. Make the point unmistakable — in this example, measurement nodered_link_test, one field holding 23.7, tag bench set to edge-pc. The names are yours to choose, so pick ones no other flow on the host uses.
  3. Inject once and read the node status: a connection error points at the path, an authorization error at the token's scope, and no error at all means the server accepted the write.
  4. Query the bucket for that measurement over the last five minutes.
  5. Expect exactly one row holding 23.7.
  6. Restart Node-RED, inject once more, and expect the count to reach two — that proves the saved credentials survived the restart.

Worked example, illustrative numbers: a pilot line logs 12 tags every 5 s, so the steady-state rate is 12 × (60 ÷ 5) = 144 points per minute, or 144 × 60 = 8,640 points per hour. Your test point is one of them. Two rows after a single inject means the inject fired twice — delete one and redo the count. Zero rows with no node error means the query is wrong, not the write: a wrong bucket, a misspelled measurement, or a time range that ends before the write. The pass criterion never changes: one row after one inject, two after the restart.

At that rate the host, not the link, becomes the ceiling, and sizing a self-hosted Node-RED InfluxDB Grafana historian takes that question next.

Why does the write succeed but the query shows nothing? #

Because the write and the query disagree on destination or time: the accepted point landed somewhere the query is not looking, so fix the query's bucket, measurement filter and time range before touching the connection.

A write that raised no node error was transported and authorized, so the failure sits downstream of the database's front door. Check that the dashboard or query names the same bucket the node writes to, filters on the measurement exactly as the test spelled it, and covers a window that includes the write. When the link itself is proven and data still goes missing across the whole stack, troubleshooting missing data in a Node-RED InfluxDB Grafana stack traces it hop by hop.

What if the panel shows only username and database fields? #

Then the installed release predates v2 support: update the package to a release documented for InfluxDB 2.x, instead of pasting a token into legacy fields that cannot address an organization or a bucket.

After the update, the version choice appears in the configuration node and the v2 fields come with it; existing 1.x flows keep running, because 1.x remains a selectable option. Carrying the history itself across is separate from pointing new writes at 2.x, and migrating InfluxDB 1.x data to 2.x buckets handles that side.

How do you keep the token out of exported flows? #

Reference an environment variable in the token field: the package supports configuring the token through an environment variable, so an exported flow carries the variable's name and never the secret itself.

Define the variable in the environment that starts Node-RED on each host, and give the plant box a different value from the lab box when the buckets differ. One security rule, once: a token pasted into a chat message, a screenshot or a shared export is spent — revoke it on the server, generate the scoped replacement, and re-enter it in the node.

Questions asked

Can one configuration node serve both the write node and the query node?

Yes. The server configuration of URL, token and organization is shared, so once the test write passes, a query node pointed at the same configuration reads back from the bucket. Choose the bucket in each node's own settings rather than assuming the query node inherits it from the out node.

Is an all-access token good enough for the plant historian?

It will write, but deploy the narrow way: generate the smallest token the server offers that can write the production bucket. If it ever leaks, a scoped token exposes one bucket, while an all-access token exposes every bucket and setting on the server. Keep all-access tokens on the lab bench, where the worst case is a deleted test bucket.

How do you move the finished flow from the lab box to the plant edge PC?

Export the flow and import it on the plant box; because the token comes from an environment variable, the export carries no secret. Define that variable with the plant token before Node-RED starts there, then run the single-inject test again against the plant bucket and apply the same pass criterion of one row per inject.

Does InfluxDB 2.6 still accept writes with a 1.x username and password?

Configure 2.0 mode instead: the 2.x API authorizes with a token and writes to an organization and bucket, so username-and-database settings belong to flows still pointed at a 1.x server. The version choice lives in the configuration node, so different flows on the same Node-RED host can use different modes for different servers.

Keep reading

  • Troubleshooting

    Troubleshoot missing data in a Node-RED InfluxDB Grafana stack

    Work the chain in order: acquisition into Node-RED, the InfluxDB service and its storage mount, the write settings, then the Grafana query. In a 2.x stack most empty panels trace to a wrong token, bucket, URL or a controller clock that stamps points outside the panel's time range.

    Edge computing and IIoT

  • Troubleshooting

    Fix ECONNREFUSED when Node-RED connects to a remote SQL database

    ECONNREFUSED 127.0.0.1:3306 means the MySQL node dialed loopback on the machine running Node-RED, so the database computer was never contacted. Put the database computer's LAN address in the node's Host field, confirm MariaDB listens on that interface with TCP 3306 open, and create the account with the edge device's address as its host part.

    Edge computing and IIoT

  • Selection guide

    OPC UA and MQTT dashboard comparison for plant data

    Choose Node-RED when the dashboard only displays MQTT or OPC UA values; both protocols have maintained connector packages for it. Choose a tag-based SCADA platform when operators must write values, acknowledge alarms or open trends under accounts, and Grafana on InfluxDB when stored trends are the whole job. The decision hinges on interaction, not rendering.

    Edge computing and IIoT