Connecting OPC UA Simulation Server and OPC UA Browser to an OPC UA PubSub Network
20.10.2022
OPC UA traditionally uses a Client-Server communication model. PubSub was first introduced as an alternative communication model in the OPC UA Specification version 1.04 in 2018. The specification is quite technical, but the lightweight testing applications Prosys OPC UA Simulation Server and Prosys OPC UA Browser can now make it easier for you to try it out yourself and learn how it works in practice. Both applications include OPC UA PubSub support starting from their latest releases 5.3.0 and 4.3.0, respectively.
If you want to learn how you can configure and test OPC UA PubSub connections using our applications, keep reading. If you want to learn more about OPC UA PubSub or its differences to the traditional OPC UA Client-Server communication, you can read the previous article, OPC UA PubSub Explained.
In this guide we will:
- Learn some OPC UA PubSub theory to better understand how the complex system works.
- Configure an OPC UA Publisher (Prosys OPC UA Simulation Server) and connect it to an MQTT Broker.
- Connect an OPC UA Subscriber (Prosys OPC UA Browser) to an MQTT Broker and subscribe to a Topic.
- Observe the messages received from the Publisher.
In this article, we will be using an MQTT Broker with JSON messages. Instead of JSON messages, you can also use binary messages with the UADP encoding that is defined in the OPC UA specification. Instead of MQTT, you have also an option to use a local network with UDP as a transport protocol. If you use UDP, you must use UADP messages.
Products
To follow this guide, you will need the following products:
-
Prosys OPC UA Simulation Server
- Prosys OPC UA Simulation Server is an OPC UA Server application, which provides simulated data. You can use it in place of OPC UA Servers that provide online production data. The latest version of Simulation Server includes support for OPC UA PubSub, and it can be used as an OPC UA Publisher. The Publisher can publish the simulated data to an OPC UA PubSub Network.
-
- Prosys OPC UA Browser is a general-purpose OPC UA Client and OPC UA Subscriber. You can test connections and view data from any OPC UA Server. The main functions of the OPC UA Browser include browsing the server Address Space, reading and writing to Variables, monitoring Variables and Events, and reading a history of Variables and Events. Additionally, the latest version includes support for OPC UA PubSub. So, the new OPC UA Browser can be used to connect to an OPC UA PubSub Network and subscribe to messages from OPC UA Publishers.
-
- Eclipse Mosquitto is an open source (EPL/EDL licensed) message broker that implements the MQTT protocol versions 5.0, 3.1.1 and 3.1. Mosquitto is lightweight and suitable for use on all devices from low power single board computers to full servers.
Necessary OPC UA PubSub Theory
OPC UA PubSub Network
In order to use OPC UA PubSub to share messages between OPC UA Publishers and Subscribers, they must connect to the same network. In a local network, you can use either unicast or multicast addresses. If you have several components, you can use the multicast UDP network. You can use an address such as ‘opc.udp://224.0.5.1:4840’.
Another option is to use a broker based connection, which can also work in larger networks. In this article, we will set up an MQTT Broker that both of our applications will connect to. We will use a locally hosted Eclipse Mosquitto for that. Other options for MQTT Broker are HiveMQ and SampleBroker that is included in the PubSub Edition of Prosys OPC UA SDK for Java.
The Broker Connection Address needs to be in format:
mqtt[s]://<address>:<port>
Since we host our broker locally, our connection information will be:
Broker address: localhost
TCP port: 1883
This gives us a Connection Address that we can use in both OPC UA Simulation Server and OPC UA Browser:
mqtt://localhost:1883
OPC UA Queue and MQTT Topic Filter
We need to configure which OPC UA Queues we publish to with Simulation Server and which MQTT Topics we subscribe to with Browser. With Simulation Server we will be using the default QueueName and MetaDataQueueName that are as follows:
prosysopc/json/data/urn:<host>:OPCUA:SimulationServer/<writergroup>/<writer>
prosysopc/json/metadata/urn:<host>:OPCUA:SimulationServer/<writergroup>/<writer>
The OPC UA Subscriber must usually define a specific MQTT Topic that it monitors. With OPC UA Browser, we must define the MQTT Topic Filter, when we subscribe to the broker. You can copy the QueueName defined in Simulation Server to the filter to monitor that topic. For example (replace with the actual values for the host, writergroup and writer):
prosysopc/json/data/urn:<host>:OPCUA:SimulationServer/<writergroup>/<writer>
Alternatively, in OPC UA Browser, we can use wildcard characters to subscribe to bigger parts of Topic Tree. For example:
# Subscribes to all branches. Note that some Brokers may not allow this
prosysopc/# Subscribes to all branches that start with prosysopc/
prosysopc/+/data Subscribes to all branches that have three levels and that start with prosysopc/ and end with /data
OPC UA Browser will prompt you for the filter, when you connect to an MQTT Broker, but we can also directly add the Topic filter to the address in format:
mqtt://localhost:1883/prosysopc/#
If you do not want to publish to the default topics, you can use the following settings, for example:
QueueNames for the Publisher configuration of the Simulation Server:
testopcua/data
testopcua/metadata
MQTT topic filter for OPC UA Browser:
testopcua/#
Downloading and configuring the Mosquitto MQTT Broker
-
Download the correct version of Mosquitto for your system from the Mosquitto download page.
-
Install the broker and find the installation folder. Default folder on the Windows operating system is:
C:\Program Files\mosquitto
. -
Launch the command interpreter (cmd) in this folder. This can be done by typing
cmd
in the navigation bar and pressing enter. -
Launch the Mosquitto MQTT Broker with the following command:
mosquitto -p 1883
There is no confirmation or messages visible in the console but the MQTT Broker should now be running.
Configuring the Publisher in OPC UA Simulation Server
-
To access the PubSub view, first we need to switch to Expert Mode. Click the Options button to do that.
-
Open the PubSub view.
-
Press the Configure button to write your connection information to the opened dialog.
-
Use the default settings for everything and click OK.
Configuring the Subscriber in OPC UA Browser
- Write the full Connection Address to the address bar on top of the page and press the Connect button.
mqtt://localhost:1883/prosysopc/#
-
Use the default values for Client Id, Username and Password and then click OK to start the Subscriber.
-
By default, the Simulation Server is publishing six different Variables and you should see them in the PubSub Data View: Counter, Random, Triangle, Sawtooth, Square and Sinusoid.
- You can also monitor the individual JSON messages with the Log view.
Next steps
This article presents a very basic case of connecting Prosys OPC UA Simulation Server and Prosys OPC UA Browser to an MQTT Broker and monitoring data that is being sent with OPC UA PubSub. You can now start testing different settings in the Simulation Server Publisher Configuration to see how they affect the messages.
You can also connect with different Subscribers and use different Publishers, if you have them available. You should now have a good idea how OPC UA PubSub works in practice.
If you want to do your implementation following this guide, place download requests for the following products:
- Prosys OPC UA Browser
- Prosys OPC UA Simulation Server
- You can use the Free Edition for testing, but to change and add more published Variables, you will need the Professional Edition.
- To receive evaluation or commercial licenses to unlock Professional Edition features, please contact sales@prosysopc.com.
If you want to learn more, you can check our guides and demos at our blog or read the user manuals for OPC UA Simulation Server and OPC UA Browser.
Do you want to know more?
You can email ua at sales@prosysopc.com or use the contact form.
Elias Nykänen
Software Engineer
Email: elias.nykanen@prosysopc.com
Tags: Browser, Simulation Server, Cloud, OPC UA, PubSub, MQTT, Guides
comments powered by DisqusAbout Prosys OPC Ltd
Prosys OPC is a leading provider of professional OPC software and services with over 20 years of experience in the field. OPC and OPC UA (Unified Architecture) are communications standards used especially by industrial and high-tech companies.
Newest blog posts
Why Do Standards Matter in Smart Manufacturing?
The blog post discusses the importance of standards in smart manufacturing, envisioning a future where auto-configurable systems in manufacturing rely on standardized data formats for seamless integration and reduced costs, with a focus on the OPC UA standard family as a key enabler.
OPC UA PubSub to Cloud via MQTT
Detailed overview of the demo presented at the OPC Foundation booth
SimServer How To #3: Simulate data changes on a server using an OPC UA client
A two-part step-by-step tutorial on how to write data changes on an OPC UA server using an OPC UA client.