Industrial network communications
Node-RED with OPC UA Server
For the final example, I use the Python OPC UA server from the first example. The Temperature
and Windspeed
tags from the Python example use the same simulation code, but an added Wave Height
tag will be a manually entered value from Node-RED.
Figure 10 shows a Node-RED application that connects to the Python OPC UA server and presents the data in a Node-RED dashboard. This example subscribes to two real-time inputs (Temperature
and Wind Speed
) and presents the values in gauges. The OpcUA Item nodes define the OPC UA NodeIDs to be used.
All the OpcUa Client nodes need their endpoints defined to the Python OPC UA server's address.
The subscribed data values are returned as a two-item array (because the data type is an Int64). The Gauge node only reads the first payload array item (which is 0), so a small Function node copies the second payload item (msg.payload[1]
) to the payload message:
// Copy second payload array item to be the payload // Note: msg.payload[0] = 0, the value is in payload[1] msg.payload = msg.payload[1] return msg;
For this example, a manual input for the Wave Height
tag is subscribed to like the other tags, and the slider position is updated to its value. The slider can also be used to set the value manually by having the slider output passed to an OpcUa Client node with a WRITE
action.
After the logic is complete, the Deploy button makes the application live. The Node-RED dashboard can be viewed at http://node-red-ip:1880/ui.
Summary
Learning OPC UA can be quite intimidating because of all the features; however, if you start small with Python and Node-RED, it's possible to put together a usable test system with a minimal amount of code and setup.
In this article, I only touched on data access, with no security settings. The next steps would be to look at more advanced features like alarms and events, historical data access, and user security.
Also, you should note that most high-end OPC UA servers support access to OPC UA items with their browser names, so instead of accessing a point with the NodeID ns=5;i=6
, a browser name string can be used (e.g., ns=5;s=MYTAGNAME
).
Infos
- OPC Foundation: https://opcfoundation.org/
- OPC Unified Architecture: https://opcfoundation.org/about/opc-technologies/opc-ua/
- open62541 Project: https://open62541.org/
- Free OPC-UA Library project: https://github.com/FreeOpcUa
- Code for this article: ftp://ftp.linux-magazine.com/pub/listings/linux-magazine.com/258/
- Python tk_tools library: https://tk-tools.readthedocs.io/
- Node-RED OPC UA docs: https://flows.nodered.org/node/node-red-contrib-opcua
« Previous 1 2 3
Buy this article as PDF
(incl. VAT)
Buy Linux Magazine
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters
Support Our Work
Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.
News
-
Ubuntu 24.04 Comes with a “Flaw"
If you're thinking you might want to upgrade from your current Ubuntu release to the latest, there's something you might want to consider before doing so.
-
Canonical Releases Ubuntu 24.04
After a brief pause because of the XZ vulnerability, Ubuntu 24.04 is now available for install.
-
Linux Servers Targeted by Akira Ransomware
A group of bad actors who have already extorted $42 million have their sights set on the Linux platform.
-
TUXEDO Computers Unveils Linux Laptop Featuring AMD Ryzen CPU
This latest release is the first laptop to include the new CPU from Ryzen and Linux preinstalled.
-
XZ Gets the All-Clear
The back door xz vulnerability has been officially reverted for Fedora 40 and versions 38 and 39 were never affected.
-
Canonical Collaborates with Qualcomm on New Venture
This new joint effort is geared toward bringing Ubuntu and Ubuntu Core to Qualcomm-powered devices.
-
Kodi 21.0 Open-Source Entertainment Hub Released
After a year of development, the award-winning Kodi cross-platform, media center software is now available with many new additions and improvements.
-
Linux Usage Increases in Two Key Areas
If market share is your thing, you'll be happy to know that Linux is on the rise in two areas that, if they keep climbing, could have serious meaning for Linux's future.
-
Vulnerability Discovered in xz Libraries
An urgent alert for Fedora 40 has been posted and users should pay attention.
-
Canonical Bumps LTS Support to 12 years
If you're worried that your Ubuntu LTS release won't be supported long enough to last, Canonical has a surprise for you in the form of 12 years of security coverage.