OPC UA client with Node-RED

Node-RED is a programming tool for connecting hardware devices, APIs and online services together in new and interesting ways. Through a browser-based editor it is possible to connect objects (Flows) using the wide range of objects available.

I have already explained in this article how to install Node-RED on our Raspberry-based systems, now we will see how to use Node-RED to communicate with other systems using the Open Platform Communications Unified Architecture (OPC UA) protocol, a unified communication protocol for industrial automation.

OPC UA node installation

In the standard Node-RED installation a base of nodes is installed, the most commonly used ones, but there is a huge library of usable nodes. To use the OPC UA protocol, install the nodes supplied with node-red-contrib-opcua. The installation can be done from the command line with (npm) Node Package Manager, or more simply from a browser.

From the menu choose Manage palette, then look for the form node-red-contrib-opcua and to proceed with the installation, to test the example it is also necessary to install the module node-red-dashboard.

Here is the program

Below you can see the program in Node-RED with the relative dashboard that connects to the program SimpleOPCUA developed with CODESYS, both programs are run from the same module CPU SlimLine Raspberry.

Communication with the CODESYS OPC UA server is performed by the node OpcUa Client in which it is defined as Endpoint the address and port of the OPC UA server (In the example it is opc.tcp: // 192.168.0.180: 4840). Of course turning both programs on the same processor I could define opc.tcp: // localhost: 4840. In reading operations (Variables DIStatus e Counter) will be defined Action READ, in write operations (Variable DOCommand) will be defined Action WRITE.

The object is located at the OpcUa Client OpcUa Item which specifies the NodeId of the variable to be accessed to be reported in the field Item, to identify the value to write use the UaExpert like program shown here. In the example we will have:

DIStatus: ns=4;s=|var|CODESYS Control for Raspberry Pi SL.Application.PLC_PRG.DIStatus
DOCommand: ns=4;s=|var|CODESYS Control for Raspberry Pi SL.Application.PLC_PRG.DOCommand
Counter: ns=4;s=|var|CODESYS Control for Raspberry Pi SL.Application.PLC_PRG.Counter

In the Type field the type of the variable must be defined:

DIStatus: Boolean
DOCommand: Boolean
Counter: UInt32

All other nodes are used to activate the OPC UA nodes at a time and to display data on the dashboard.

Was this article helpful?