Objective: Process and visualize process data from a CODESYS controller on a RevPi in Node-RED.

The RevPi performs two functions:

  • Soft PLC with CODESYS for deterministic control

  • Linux-based edge gateway with Node-RED for IT integration

A simple example project is used to demonstrate how data can be exchanged bidirectionally between CODESYS and Node-RED via the RevPi process image.

The following steps are shown:

  1. Access to the process image of the RevPi

  2. Data exchange between PLC logic (CODESYS) and IT/application level (Node-RED)

  3. Visualization of I/O data

This principle can be used for e.g.:

  • Web dashboards and visualization

  • Cloud connection

  • Edge computing applications

The tutorial can be applied to all RevPi Base Modules.

The already programmed example project with RevPi Connect//S as the base module is available in a GitLab Repository. It can be adapted to all basic modules.

Prerequisites #

Devices #

✓ RevPi base module

Hardware Installation #

✓ RevPi is connected to the network.

✓ RevPi is connected to the power supply.

Software Installation #

RevPi Bookworm or higher is installed on the RevPi.

✓ Web browser is installed on your PC (e.g. Google Chrome or Mozilla Firefox).

✓ There is a network connection between the RevPi and your PC.

✓ CODESYS Development System (CODESYS) is installed on your PC.

✓ CODESYS runtime is installed in the CODESYS Development System.

✓ RevPi I/O driver is installed in the CODESYS Development System.

✓ CODESYS is connected to the RevPi.

✓ CODESYS runtime is installed on the RevPi.

See CODESYS documentation about Setting up the System.

1. Setting up Node-RED on the RevPi #

Start Cockpit on the RevPi via the web browser.

▷ Add the service revpi-codesys to the firewall settings in Cockpit.

2. Importing Node-RED flow #

▷ Download the file RevPi CODESYS Node-RED.json from the GitLab Repository.

▷ Adapt the variable names of the inputs and outputs in the file to your CODESYS project if it differs from the example project.

▷ In Node-RED, select _Import_from the menu.

❯ The Import nodes window opens.

▷ Select select a file to import and open the file RevPi CODESYS Node-RED.json.

▷ To create the project as a new flow, select the option New Flow under Import to.

▷ Select Import.

❯ The flow opens in a new tab.

▷ Select Deploy to start the application on the Node-RED server.

Deploy
How the Flow Works

The flow cyclically reads 32 bytes (inputs) from the process image of the RevPi. This data is available in Node-RED for further processing steps, e.g. visualization, logging or forwarding to external systems. In the example, the values are written directly back to the corresponding outputs to demonstrate bidirectional data exchange.

Each of the 32 parallel flow branches has an identical structure and works as follows:

Node Function

Get Input

Inject node (timer): is triggered automatically every 0.5 seconds and sends the name of the respective input as msg.payload, e.g. Input_11_1.

revpi-getpin node

Reading input: reads the current value from the process image of the RevPi.

Pin Output

Writing output: writes the read value directly to the corresponding output without further processing.

3. Setting up the CODESYS Project #

▷ Download the example project RevPi CODESYS Node-RED from the GitLab Repository.

▷ Open the example project in CODESYS.

If you are using a different base module than RevPi Connect/+/S as in the example project, adapt the project as follows:

▷ Update the RevPi base module in the device tree.

▷ Add the Virtual I/O Device to the piBridge Virtual device.

▷ Open the device RevPi_Virtual.

▷ Assign the variables in the Mapping tab:

  • Inputs: I_Virtual

  • Outputs: Q_Virtual.

How the Application Works
Note
  • Values in the input section of the RevPi device are written by external applications and read by the PLC.

  • Values in the output section of the RevPi device are written by the PLC and read by external applications.

The CODESYS application consists of a Virtual I/O Device with 32 byte inputs and outputs that exchange data with a Node-RED application using the Node‑RED RevPi Nodes Server. It simulates a PLC logic that cyclically writes values to the output area of the Virtual I/O Device. In practice, this could be sensor data, status information or production parameters, for example.

  • Data flow from CODESYS to Node-RED: The CODESYS application writes the values [1…​32] to the 32 output bytes Q_Virtual of the Virtual I/O Device.

  • Data flow from Node-RED to CODESYS: The Node-RED application reads the 32 output bytes from the address range of the Virtual I/O Device and writes them back to the input range of the Virtual I/O Device.

4. Running the CODESYS Application #

▷ Select Generate Code (F11) in the menu bar to translate the project.

▷ Open the root device.

▷ Select Scan Network in the Communication Settings , select the RevPi and establish the connection to the device using OK.

▷ Select Login (AltF8) in the menu bar to log in to the RevPi.

▷ When you log in for the first time, create a user by following the wizard and entering your login details.

▷ In the Device User Logon window, log in to the RevPi.

▷ The first time, confirm the download of the application to the RevPi by Yes .

▷ Select ⯈ (F5) in the menu bar to start the application.

5. Checking Result #

In Node-RED

▷ Go to the Node-RED UI in the browser.

❯ Next to each revpi-getpin node is displayed:

  • Connection status

  • Current values of the 32 bytes

Application Logic
In CODESYS

▷ Switch to online mode.

▷ Open the device RevPi_Virtual in the device tree.

❯ The values </i>[1…​32]_ should be visible in the Revolution PI Virtual Device I/O Mapping tab under _I_Virtual<i> .

Run Application

6. Optional: Visualizing Values in the Node-RED Dashboard #

In addition to displaying the current values directly in the flow, the exchanged process data can also be visualized in a web dashboard.

Installing the Dashboard Package

▷ Go to the Node-RED UI in the browser.

▷ Select Manage palette from the menu.

❯ The Palette window opens.

▷ Switch to the _Install_tab.

▷ Search for the package node-red-dashboard.

▷ Select Install if the package is not yet installed.

❯ Additional dashboard nodes are available in the palette.

Extending the Dashboard Flow

▷ Open the previously imported flow.

▷ Drag a node of type Gauge into the workspace.

▷ Connect the output of a revpi-getpin node to the gauge node.

❯ The current byte value is thus transferred directly to the dashboard element.

Configuring the Dashboard

▷ Open the gauge node.

▷ Select the pencil icon next to the Group field.

❯ The Add new ui_group window opens.

▷ Create a new group, e.g:

  • Tab: RevPi

  • Group: Process data

▷ Confirm with Add.

▷ Configure the gauge node:

  • Label: e.g. byte 1

  • Value format: {{value}}

  • Range: 0 to 255 (corresponds to one byte)

▷ Confirm with Done.

▷ Select Deploy.

Calling up the Dashboard

▷ Open the address http://<IP-address-of-RevPi>:1880/ui in the browser.

❯ The dashboard is displayed.

The configured gauge visualizes the current value of the selected byte in real time. As the CODESYS application writes the values [1…​32] cyclically, the display changes according to the transmitted process data.

Further Resources #