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.

A Node-RED flow with a Serial Input connected to 3 functions, Parse DRO Data, Add Timestamp, and Add Client ID. All three outputs go in to a Join Values node, which then outputs to a MQTT out node, a debug node, and another function node which then outputs to the InfluxDB database.

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 topic and clientID tag to the payload and removes the clientID from 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:

    The "Organization" field populated with "purdue_gatewaylabs", the "Bucket" field populated with "gateway_bucket", and the "Measurement" field populated with "Acra/ATL-618EVS".
  • 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.

    In the "properties" tab of the configuration the "Name" field is populated with "Gateway_Influx", the "version" is set to 2.0, the "URL" is populated with "http://192.168.4.128:8086" and the "token" field is populated with the token for the InfluxDB.
  • Click Update and Deploy to apply the changes and connect to the server.

By following these steps, you will be able to add an InfluxDB connection to your existing Node-RED flow, allowing you to store parsed DRO data in an InfluxDB database for further analysis and visualization.