Manage Node-red flows with Cumulocity IoT and thin-edge.io

Introduction

This article should show how the device management of Cumulocity IoT together with thin-edge.io can be used to manage/distribute/update node-red flows from a central platform instance to multiple devices. Hence thin-edge.io can be extended via plugins as well as Cumulocity IoT with micro frontends this can be a guide of how various such use cases can be implemented. You can find the repository in the example section of thin-edge.io.


Edge computing

Edge computing in the context of IoT refers to the processing and analysis of data from IoT devices at the edge of the network, rather than in a central cloud or data center. This allows for faster data processing and decision-making, as the data does not need to be transmitted over a network to a centralized location for processing.

One way to implement edge computing in an IoT system is through the use of Node-red, an open-source programming tool. By using Node-red locally, data can be processed and analyzed at the edge of the network, enabling real-time decision-making and reducing the reliance on a central cloud or data center.

Proper device management is essential in an IoT system that utilizes edge computing, as it ensures that the devices are functioning correctly and are able to transmit data to the edge for processing. This can be achieved through the use of tools such as device monitoring software, which alerts users to any issues with their devices and allows them to troubleshoot and fix problems in real-time.

Cumulocity IoT - The leading device management platform

Cumulocity IoT is a leading device management platform that provides a range of tools and services for managing IoT devices. It allows you to monitor your devices in real-time, configure them remotely, and access a wide range of analytics and reporting tools.

With Cumulocity IoT, you can:

  • Monitor your devices in real-time and receive alerts when something goes wrong

  • Configure your devices remotely and apply updates or patches as needed

  • Use APIs and integrations to connect your devices to other platforms and systems

  • Benefit from a range of security features, including secure communication, authentication, and access control

  • Cumulocity IoT is designed to be scalable and flexible, whether you are managing a few hundred devices or a few million.

thin-edge.io - The open source framework

thin-edge.io is an open-source project initiated by Software AG and partners to provide a cloud-agnostic edge framework. It is much more generic than the device management agent, so it can connect to multiple IoT Platforms, and it allows flexible logic executed on the device. It is optimized for a very small footprint and high performance.

062ba3b1d4c3da28e250e7cf38bc09ed08cb52a9_2_690x327

Node-Red

Node-RED is a visual programming tool that allows you to build and deploy IoT applications quickly and easily. It is particularly useful for edge computing, as it allows devices to process data locally and make real-time decisions. In that context Node-RED can be used to build flows that run on edge devices and process data locally. This can improve the performance and reliability of IoT systems, especially in situations where internet connectivity is limited.

Prerequisite

To follow this guide, you only need the following:

Installation

This repository consists of several parts that need to be up an running:

  • Node-Red locally on the device

  • The Node-Red UI/Backend on Cumulocity

  • The device management plugin that allows management and distribution of the node-red flows

  • thin-edge.io plugin to inject or delete the flows in the local node-red runtime

Node-red

There are several ways on how to run node-red locally on the device. However basically only two methods are mentioned here:

Native installation via npm

Make sure that you have npm installed on your system. npm is typically installed automatically with Node.js, so if you have Node.js installed, you should already have npm.

You can check if npm is installed by running the following command in your terminal:


npm -v

If npm is not installed, you can install it by following the instructions on the npm website (Getting started | npm Docs). Once npm is installed, you can install Node-RED by running the following command in your terminal:


npm install -g node-red

This will install the latest version of Node-RED and make it available globally on your system.

To start the Node-RED server, run the following command in your terminal:


node-red

This will start the Node-RED server. Usually the webserver can be reached via port 1880.

Running via docker

Make sure docker is installed on your system. You can download Docker from the official website (Docker Desktop: The #1 Containerization Tool for Developers | Docker).

Start the Docker daemon by running the following command:


sudo systemctl start docker

Once the Docker daemon is running, pull the latest Node-RED image from the Docker registry by running the following command:


docker pull nodered/node-red

Run the Node-RED container by executing the following command:


docker run -d -p 1880:1880 --name mynodered nodered/node-red

This command will start the Node-RED container in detached mode (-d), bind the container’s port 1880 to the host’s port 1880 (-p 1880:1880), and give the container the name “mynodered”.

This will start the Node-RED server in a container. Depending on your mapping (-p) the webserver can be reached via port 1880 or any other you configured.

Node-red UI plugin

Refering to the backend/frontend implementation you can find all content, packages and tutorials here:

Node-red devicemanagement plugin

You need to install the plugin for the device management application to your Cumulocity IoT Tenant:

The plugin is provided as binaries in the release section or in the “node-red-devicemanagement-plugin” directory.

To install the plugin go to the Administration App → Ecosystem → Packages and click on “Add Application” on the top right.

NOTE: If you don’t see the Packages Menu you have to add “?beta=true” in your URL.

Example: {{url}}/apps/administration?beta=true

Select the binaries and wait until it is uploaded.

NOTE: We need to clone the Device Management app to add the plugin to it

After successful upload go to “All Applications” and click on “Add Application”. Select “Duplicate existing application”

and afterwards “Device Management”.

Now select the cloned Device Management App and go to the “Plugin” Tab. Click on “Install Plugin” and select “node-red-management plugin”

thin-edge.io

To install thin-edge.io locally on a device just follow the following tutorial:

https://thin-edge.github.io/thin-edge.io/html/tutorials/getting-started.html#Step-1-Install-thin-edge.io

The basic steps are:

  1. Get thin-edge.io installation script

curl -fsSL https://raw.githubusercontent.com/thin-edge/thin-edge.io/main/get-thin-edge_io.sh | sudo sh -s

  1. Config tenant url

sudo tedge config set c8y.url {{YOUR_C8Y_URL}}

  1. Create/Upload Certificate

sudo tedge cert create --device-id {{YOUR_UNIQUE_DEVICE_ID}}

  1. Connect

sudo tedge connect c8y

thin-edge.io plugin

To inject node-red flows via operation from Cumulocity IoT the operation plugin concept is used. The tedge_agent is checking for specific operations and is triggering the particular plugin. Therefore the plugin needs to be proper installed.

Requirements

  • Working thin-edge.io installation

  • Python3 and pip3 installation (will not work on python2)

node-red thin-edge.io plugin

  1. Clone the content of the directory "node-red-devicemanagement-plugin on the thin-edge.io device

  2. run sudo -H pip3 install -r requirements.txt from that directory

  3. Copy c8y_NodeRed to the following directory “/etc/tedge/operations/c8y/”

  4. Copy c8y_NodeRed.py to the following directory “/bin/”

  5. Copy API.py to the following directory “/bin/”

  6. Make sure, that both files do have permissions for beeing executed by tedge_mapper (“chmod 644 c8y_NodeRed and chmod 555 c8y_NodeRed.py and API.py”)

If installation is done properly according to the steps above, you have to disconnect and reconnect thin-edge.io. In that way the suppoerted Operations will be updated.


sudo tedge disconnect c8y

and


sudo tedge connect c8y

However it would also to be sufficient to restart the tedge_mapper service via e.g.:


sudo systemctl tedge_mapper restart

You device within Cumulocity should look similar to this afterwards:


SmartRest template

SmartRest is a csv format that converts RestAPI interactions on Cumulocity IoT to a comma separated payload on mqtt.

Find more to SmartRest in the documentation.

There is also a SmartRest template (node-red.json) in the repository that can easily be imported.


HowTo Use

To use this repo after installation of all components there is the following workflow:


Create flow

First of all a flow needs to be defined within Cumulocity IoT Node-red. Make sure the flow is deployed to the platform side node-red runtime.


Pick Device

A device that has properly installed the thin-edge.io node-red plugin shows the Node-Red tab.

In that tab you can select a flow that should be send to the device.

pick_flow

In case that the flow was already send and was just updated/adjusted on platform side it will already appear in the list and can be updated via the context menu.

The operation that is created contains the flow in base64 encoded. The thin-edge.io plugin handles the data according to the operation type such as e.g. remove, create or update.



Summary & Next Steps

Hopefully this tutorial helped you in understanding how thin-edge.io´s plugin mechanism as well as the new microfrontend concept of Cumulocity IoT can be used to manage node-red flows locally on edge devices. In combination this can be used to widely enable edge computing scenarios for multiple devices and thus efficient usage of the infrastructure.

Currently there is no monitoring of the edge sided events in the Cumulocity IoT platform. In a next steps the repository parts will be extended thus one can monitor what’s happening on the local device side via the debug node within node-red. There is also currently no logic implemented for custom installed nodes. These need to be installed either manually or via configuration management of Cumulocity IoT.

5 Likes