1. Home
  2. Docs
  3. IIoTNext Platform
  4. Gateway Integration
  5. Node-Red

Node-Red

About Node-Red

Node-RED is a programming tool for wiring together hardware devices, APIs, and online services in new and interesting ways. It provides a browser-based editor that makes it easy to wire together flows using the wide range of nodes in the palette that can be deployed to its runtime in a single click.

https://nodered.org/   This guide will help you get Node-RED installed and running in just a few minutes.

Dummy Data from Node-Red to IIoTNext

First, we need to install Node-red https://nodered.org/docs/getting-started/

Node-RED comes with a core set of useful nodes, but there are many more available from both the Node-RED project as well as the wider community.

You can install nodes directly within the editor by selecting the Manage Palette option from the main menu to open the Palette Manager.

The ‘Nodes’ tab lists all of the modules you have installed. It shows which you are using and whether updates are available for any of them. The ‘Install’ tab lets you search the catalog of available node modules and install them.

To generate random values we require additional pallet ‘node-red-node-random’

Here is the sample node-red flow for random value push to IIoTNext Platform random_push_sample.

Flows can be imported to the editor using their JSON format, making it very easy to share flows.

The Import dialog can be used to import a flow by the following methods:

  • pasting in the flow JSON directly,
  • uploading a flow JSON file,
  • browsing the local flow library.

In all cases, the dialog offers the option to import the nodes into the current flow, or to create a new flow for them.

Select the sample flow downloaded previously and import to ‘new flow’, then click import. Now we can see our flow on editor like this:

We have four nodes inflow

1. Inject Node

                    The Inject node can be used to manually trigger a flow by clicking the node’s button within the editor. It can also be used to automatically trigger flows at regular intervals.

The message sent by the Inject node can have its payload and topic properties set.

The payload can be set to a variety of different types:

  • a flow or global context property value
  • a String, number, boolean, Buffer, or Object
  • a Timestamp in milliseconds since January 1st, 1970

Inject node is set to 5 seconds interval, can change interval time to required

2. Random Node

A simple node generates a random number when triggered. If set to return an integer it can include both the low and high values. min <= n <= max – so selecting 1 to 6 will return values 1,2,3,4,5 or 6.

If set to return a floating-point value it will be from the low value, up to, but not including the high value. min <= n < max – so selecting 1 to 6 will return values 1 <= n < 6 .

https://flows.nodered.org/node/node-red-node-random

3. Function Node

The Function node allows JavaScript code to be run against the messages that are passed through it. The message is passed in as an object called msg. By convention, it will have a msg.payload property containing the body of the message. Reference https://nodered.org/docs/user-guide/writing-functions

In the sample code, push random as the value of temperature(Tag name).

4. HTTP Request Node

The HTTP request node can be used for.

  • Retrieving web pages from a website
  • Making API Request
  • Sending and receiving JSON data to a website or API.
  • etc

The node will send a request and receive the response. The node handles both the request and response.

Refer to https://iiotnext.com/docs/iiotnext-platform/device-connectivity/http-device-api/ for more details about HTTP API to IIoTNext Platform

Change URL field <access_token> to IIoTNext Platform device access tocken https://iiotnext.com/docs/iiotnext-platform/security/access-token/

At this point, the nodes only exist in the editor and must be deployed to the server. Click the Deploy button.

After Deploying Node-Red starts to push data in every interval we can see Telemetry data in IIoTNext Platform https://iiotnext.com/docs/iiotnext-platform/admin-ui/devices

Modbus Tags to IioTNext Platform Via Node-Red(HTTPs)

Modbus supports communication to and from multiple devices connected to the same cable or Ethernet network. For example, there can be a device that measures temperature and another device to measure humidity connected to the same cable, both communicating measurements to the same computer.

Sample flow for reading Modbus value and push to IIoTNext Platform through HTTP modbus_read_sample

Reqired Node palette : ‘node-red-contrib-modbustcp’  https://flows.nodered.org/node/node-red-contrib-modbustcp

ModebusTCP-Read Node Properties

Modbustcp-server settings

Modbus Tags to IioTNext Platform Via Node-Red(MQTT)

MQTT is an OASIS standard messaging protocol for the Internet of Things (IoT). It is designed as an extremely lightweight publish/subscribe messaging transport that is ideal for connecting remote devices with a small code footprint and minimal network bandwidth.

Mqtt protocol datapushing to IIoTNext Platform https://iiotnext.com/docs/iiotnext-platform/device-connectivity/mqtt-device-api/

Sample flow for reading Modbus value and push to IIoTNext Platform through MQTT mqtt

Mqtt-out node
                  Node-Red provides both an MQTT subscribe (input) and publish (output) node. The configuration for these nodes is almost Identical as the main part of the configuration concerns the actual client connection.
Give IIoTNext Platform Device access token in security -> user name

Node-Red flows Examples:

How can we help?