What is the purpose of this article?
This article outlines the steps to set up Node-RED, from installation using Windows/Linux or Raspberry Pi, to module configuration. It explains how to use basic modules for integrating Rheonics sensors via Modbus and publishing data to an MQTT broker.


TABLE OF CONTENTS

1. What is Node-RED

Node-RED is a programming tool based on NodeJS that uses flows for easy implementation of different applications. It is user-friendly and ideal for sending Rheonics sensor data to MQTT brokers for remote monitoring or SCADA integration.


Figure 1: Diagram of Rheonics SME, Node-RED, and MQTT for remote monitoringFigure 1: Diagram of Rheonics SME, Node-RED, and MQTT for remote monitoring


1.1. Devices That Can Run Node-RED

Node-RED can run on many types of hardware, as long as the device supports Node.js and meets the operating system requirements, such as:

  • PCs, or Industrial PCs (IPC) with Windows or Linux OS

  • Single-board computers such as Raspberry Pi (Linux) or BeagleBone Black (Linux) 

If a device, such as PLCs or IoT gateways, already has built-in MQTT functionality, it can connect directly to the MQTT broker without Node-RED. In these cases, Node-RED is optional.


2. Installing Node-RED 

Node-RED can run on different operating systems. In this guide, the installation of Node-RED on Windows, Linux, and Raspberry Pi OS will be explained.

2.1. Windows

2.1.1. Prerequisites

  • OS: Windows 10 or 11 (Windows 7 and Windows Server may work, but they lack support)


2.1.2. Install NodeJS

1. To install NodeJS, go to the following link: Node.js — Run JavaScript Everywhere

  • Minimum recommended Node.js version: 18

2. To verify installation, copy the following commands:

  • Powershell: node --version; npm --version 
  • cmd: node --version && npm --version


Figure 2: Verifying Node.js and npm installation

Figure 2: Verifying Node.js and npm installation


2.1.3. Install Node-RED

1. Run PowerShell as administrator

2. Copy the following to a terminal to install node-RED

npm install -g --unsafe-perm node-red


3. In a terminal, paste the following command to start running Node-RED.

node-red


4. In the HOMEPATH, a new folder called .node-red should appear. 

Figure 3: .node-red Folder created successfully

Figure 3: .node-red Folder created successfully


2.2. Linux

2.2.1. Install NodeJS

1. To install NodeJS, go to the following link: Node.js — Run JavaScript Everywhere

  • Minimum recommended Node.js version: 18

2. To verify installation, copy the following commands in the terminal:

  • node --version
  • npm --version


2.2.2. Install Node-RED

1. Copy the following to a terminal to install node-RED as a global module along with its dependencies.

sudo npm install -g --unsafe-perm node-red


2. If the command succeeded, a similar message should appear:

+ node-red@x.x.x added 332 packages from 341 contributors in 18.494s found 0 vulnerabilities


3. In a terminal, paste the following command to start running Node-RED.

node-red


2.3. Raspberry Pi

2.3.1. Prerequisites

  • In Raspberry Pi OS, Bullseye is the currently supported version.

2.3.1. Install NodeJS and Node-RED

For Raspberry Pi, there is a script that allows installing NodeJS, npm, and Node-RED at the same time. 

  • Open a terminal and paste the following:

bash <(curl -sL https://github.com/node-red/linux-installers/releases/latest/download/update-nodejs-and-nodered-deb)

3. Running Node-RED

1. In a terminal, paste the following command to start running Node-RED.

node-red


2. The terminal will display the corresponding version of Node-RED and indicate that Node-RED is running correctly. The server URL will appear after the Server now running at, in this case, http://127.0.0.1:1880/ 


Figure 4: Node-RED running in a terminal

Figure 4: Node-RED running in a terminal


3. Finally, paste the link in a browser to load Node-RED editor.


Figure 5: Node-RED editor

Figure 5: Node-RED editor


4. Node-RED Modules 

Node-RED modules are visual building blocks, also called nodes, which can perform a specific function. They can be found in the left panel of the Node-RED editor, as shown in the figure below.


Figure 6: Node-RED nodes

Figure 6: Node-RED nodes


4.1. Installing New Modules

There are two ways of installing new modules. 


4.1.1. From Node-RED editor

1. Click the ☰ menu located in the right corner of the editor and select Manage palette.


Figure 7: Manage palette on Node-RED editor

Figure 7: Manage palette on Node-RED editor


2. Press the Install tab and then search for the desired module in the search bar.


Figure 8: Install Tab and Search bar

Figure 8: Install Tab and Search bar


3. Press Install on the desired module.


Figure 9: Module installation

Figure 9: Module installation


4. The installed module will then appear on the Nodes Tab.

Figure 10: Installed modules on the Nodes Tab

Figure 10: Installed modules on the Nodes Tab


4.1.2. From the Terminal

1. Open a terminal.

2. Go to the following directory: $HOMEPATH/.node-red 

3. Paste the following command with the name of the module to install.

npm install <npm-module-name>


Figure 11: Installing Node-RED modules via the Terminal

Figure 11: Installing Node-RED modules via the Terminal


4. Restart Node-RED to visualize the installed module on the Node-RED editor.


4.2. MQTT nodes

4.2.1. What is MQTT?

MQTT (Message Queuing Telemetry Transport) is a lightweight communication protocol used for publishing and subscribing to data over the internet. It is commonly used to enable data exchange between devices, especially in Internet of Things (IoT) applications.


Basic Elements:

  • MQTT Broker: Also known as the server, receives messages from publishing clients and forwards them to the subscribing clients. It acts as an intermediary, using topics to determine where each message should go.
  • MQTT Client: A client can either publish messages to the broker or subscribe to specific topics to receive messages. Devices, applications, or services that use MQTT act as clients.
  • Topics: Identifiers used to organize and route messages. When a client publishes a message, it sends it to a specific topic, which other clients can subscribe to and receive the message.


The MQTT nodes are usually installed by default when installing Node-RED. You can visualize the nodes in the left panel under the network category.


Figure 12: MQTT nodes

Figure 12: MQTT nodes


4.2.2. MQTT-out Node

The MQTT-out node is used to connect to a broker and publish messages.

Figure 13: MQTT-out node

Figure 13: MQTT-out node


By double-clicking on the node, the properties are displayed.

  • Server: MQTT broker
  • Topic: Name of the topic where data will be published 
  • QoS: Quality of service is the level of guarantee for message delivery between the publisher and the broker
    • 0: fire and forget, at most once
    • 1: message delivered at least once
    • 2: message delivered only once 


Figure 14: MQTT-out node configuration

Figure 14: MQTT-out node configuration


4.2.3. MQTT-in node

The MQTT-in node connects to a broker and subscribes to messages to receive data.

Figure 15: MQTT-in nodeFigure 15: MQTT-in node


By double-clicking on the node, we will see the properties.


  • Server: MQTT broker
  • Topic: Name of the topic to subscribe to obtain the data
  • QoS: Quality of service is the level of guarantee for message delivery between the publisher and the broker
    • 0: fire and forget

    • 1: message delivered at least once

    • 2: message delivered only once 

  • Output: Choose how the data is formatted.  


Figure 16: MQTT-in node configuration

Figure 16: MQTT-in node configuration


4.2.4. Adding a new MQTT broker

1. To add a new MQTT broker, click on the plus button next to the Server option found in the MQTT-out or MQTT-in node.


Figure 17: Adding a new MQTT broker

Figure 17: Adding a new MQTT broker


  • Name: Desired name for the broker
  • Server: URL of the broker
  • Port: Port used by the broker
  • Use TLS: Enable if using encrypted communication


Figure 18: Connection Tab properties

Figure 18: Connection Tab properties


2. On the Security Tab, you can add the credentials of the broker in case they are needed.


Figure 19: Security Tab properties

Figure 19: Security Tab properties


3. Press the Add button to correctly add the broker.


4.3. Modbus Module

The module used for accessing data from the Rheonics SME via Modbus TCP is called node-red-contrib-modbus 


1. Install it through the Node-RED editor or the terminal.

2. The nodes should appear in the nodes list in the left panel called modbus.


Figure 20: Modbus nodes

Figure 20: Modbus nodes



4.3.1. Modbus-Read Node

This node allows connecting to a Modbus TCP or serial device to read registers/coils values.

Figure 21: Modbus-Read node

Figure 21: Modbus-Read node


By double-clicking on the node, the properties are displayed.

  • Name: Name of the node
  • Unit-Id: 255 
  • FC: 4 (to read input registers)
  • Address: Starting register address of the input parameter. Input registers can be found in Modbus TCP - Input Registers
  • Quantity: 2
  • Poll Rate: 3 s


Figure 22: Modbus-Read node properties

Figure 22: Modbus-Read node properties


4.3.2 . Adding a New Modbus Client

In Node-RED, a Modbus client needs to be created to read data from the Modbus server, which in this case is the Rheonics SME. This is shown in the diagram below.


Figure 23: Modbus Client-Server DiagramFigure 23: Modbus Client-Server Diagram


1. To add a new Modbus client, click on the plus button next to the Server option found in the Modbus-read node.


Figure 24: Adding a new Modbus Client

Figure 24: Adding a new Modbus Client


2. Fill in the properties of the Modbus client as follows:

  • Name: Name of the client
  • For TCP:
    • Host: IP address of the SME

    • Port: 502 (default)

  • Unit ID

    • TCP: 255


Figure 25: Modbus client TCP

Figure 25: Modbus client TCP



5. Resources