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)