Connecting Node-RED to InfluxDB
Prerequisites
Ensure that you have InfluxDB installed and running. For instructions on how to install InfluxDB, click here. Additionally, install the node-red-contrib-influxdb palette in Node-RED.
Adding InfluxDB Node to Node-RED Flow
This guide shows how to use the Node-RED flow from the Processing DRO Data in Node-RED example and add an InfluxDB connection to it.
Purpose
The InfluxDB node is used to store time-series data in an InfluxDB database. This setup helps in differentiating between various topics such as Telemetry/Axes or Telemetry/Spindle within your measurements, avoiding confusion and allowing for more precise data queries.
Getting Started
Take the flow from the "Processing DRO Data in Node-RED" example and add the following nodes:
Function Node: This node formats the payload to include specific topics for better organization in InfluxDB.
InfluxDB Out Node: This node sends the formatted data to InfluxDB.
Configuration Steps
1. Add the Function Node: Format InfluxDB Payload
This node formats the payload to include specific topics, enabling better organization and easier querying within InfluxDB.
Purpose: Adds a
topicandclientIDtag to the payload and removes theclientIDfrom the field.Name: Format InfluxDB Payload.
Function Code:
const fields = msg.payload; const topic = 'Telemetry/Axes'; //Sets the topic to the desired value const tags = { topic: topic, clientID: fields.clientID }; // Remove tag values from fields delete fields.clientID; msg.payload = [fields, tags]; return msg;
2. Add the InfluxDB Out Node
This node sends the formatted data to InfluxDB.
Purpose: Stores time-series data in an InfluxDB database.
Configuration:
Measurement: Acra/ATL-618EVS
Database: database
Precision: ms
Under the storage category, look for the InfluxDB Out node and drag it into your workspace. Double-click the node to open its configuration. First, you will have to define the Organization and Bucket that you want to store the data in, and additionally, you will have to name a measurement that you want to publish under. Below is how we defined it for our case:

Click the + button next to the server field to add a new InfluxDB server that you have previously set up. In this configuration, you will define the version (select 2 if you followed the setup instructions we provided), add the URL, and the token for your server.

Click Update and Deploy to apply the changes and connect to the server.