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.

Figure 10: Node-RED logic to show OPC UA data on a dashboard.

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.

Figure 11: Node-Red OPC UA dashboard.

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).

The Author

You can investigate more neat projects by Pete Metcalfe and his daughters at https://funprojects.blog.

Buy this article as PDF

Express-Checkout as PDF
Price $2.95
(incl. VAT)

Buy Linux Magazine

SINGLE ISSUES
 
SUBSCRIPTIONS
 
TABLET & SMARTPHONE APPS
Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content

  • Monitoring Old Devices

    Create monitoring dashboards with SSH, command-line tools, and Node-RED.

  • IoT with RabbitMQ

    Connect multiple protocols and servers together on your IoT projects.

  • Node-RED

    Node-RED lets you connect ready-made code building blocks to create event-driven applications with little or no code writing.

  • Web Scraping with Bash

    You can use one line of Bash code to scrape a web page and show the data you're tracking in Home Assistant or Node-RED.

  • WiFi Thermo-Hygrometer

    A WiFi sensor monitors indoor humidity and temperature and a Node-RED dashboard reports the results, helping you to maintain a pleasant environment.

comments powered by Disqus
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.

Learn More

News