« All blog posts

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:

  1. Learn some OPC UA PubSub theory to better understand how the complex system works.
  2. Configure an OPC UA Publisher (Prosys OPC UA Simulation Server) and connect it to an MQTT Broker.
  3. Connect an OPC UA Subscriber (Prosys OPC UA Browser) to an MQTT Broker and subscribe to a Topic.
  4. 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.

Graph of the PubSub-network

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

    • 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 MQTT Broker

    • 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

  1. Download the correct version of Mosquitto for your system from the Mosquitto download page.

  2. Install the broker and find the installation folder. Default folder on the Windows operating system is: C:\Program Files\mosquitto.

  3. Launch the command interpreter (cmd) in this folder. This can be done by typing cmd in the navigation bar and pressing enter. Launching cmd

  4. Launch the Mosquitto MQTT Broker with the following command:

      mosquitto -p 1883
    

    Launching broker

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

  1. To access the PubSub view, first we need to switch to Expert Mode. Click the Options button to do that.

  2. Open the PubSub view.

  3. Press the Configure button to write your connection information to the opened dialog. PubSub view on startup.

  4. Use the default settings for everything and click OK. The dialog for configuring the connection settings for the Publisher

Configuring the Subscriber in OPC UA Browser

  1. Write the full Connection Address to the address bar on top of the page and press the Connect button.
      mqtt://localhost:1883/prosysopc/#
    

    Default view when launching Browser.

  2. Use the default values for Client Id, Username and Password and then click OK to start the Subscriber. MQTT settings window

  3. 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. Default view after starting the subscriber

  4. You can also monitor the individual JSON messages with the Log view. LogView

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:

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

Elias Nykänen

Software Engineer

Email: elias.nykanen@prosysopc.com

Tags: Browser, Simulation Server, Cloud, OPC UA, PubSub, MQTT, Guides

comments powered by Disqus

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

Read more about us »

Newest blog posts

Open Industry 4.0 Simulation

Prosys OPC UA Simulation Server enables Open Industry 4.0 Simulation.

OPC UA PubSub to Cloud via MQTT at SPS 2022

Detailed overview of the demo presented at the SPS 2022

Open Industry 4.0 Alliance & Prosys OPC

Open Industry 4.0 Alliance aims to unite vendors to support a common communication architecture and Prosys OPC provides the tools.

View all blog posts »

-->