C++ Based OPC UA Client/Server/PubSub SDK  1.7.6.537
Getting Started

The getting started describes the creation of a PubSub configuration for initial PubSub testing using the C++ SDK Demo Server and the PubSubImporter demo application.

Demo Server

The C++ SDK Demo Server has the PubSub capabilities included and can be configured to publish data from the variables in the demo server address space. The sample configuration explained in the getting started will use variables with simulated data out of the demo address space (Demo/001_Dynamic and Demo/007_Massfolder_Dynamic)

The demo server can also be configured to subscribe for PubSub messages. The received data can be written to variables in the demo server address space. The address space contains variables for this purpose in the folder PubSubTargetVariables.

The PubSub configuration is stored by the C++ SDK Demo Server in the file bin/pubsubconfig.uabinary.

The PubSub configuration can be created off-line with the PubSubImporter. One option is to copy the resulting file into the demo server location and to restart the server with the new configuration. Another option is the download of the configuration to the demo server by the PubSubImporter using a FileType object in the demo server.

PubSub Configuration with UaExpert

The UaExpert with version 1.6 contains a PubSub configuration plug-in that allows the creation of PubSub configurations and the download of the configurations to the involved OPC UA servers.

In UaExpert the PubSub configuration can be opened with Document > Add > Select Document Type “PubSub Config View” > Add.

Existing configurations can be loaded from a server or new configurations can be created. A new configuration can be downloaded to a server.

In a configuration, a PubSubConnection must be created. Make sure the Publisher ID is unique in your network for the address (multi-cast). The PubSubConnection is needed to send and receive messages from a network address e.g. UDP multi-cast address or message broker for MQTT. The PublisherId of the connection is only relevant for the Publisher part (sending of messages). For UDP multi-cast, it is necessary to configure the used network interface by entering the IP-address of the adapter in the configuration option 'Address Network Interface'.

To send data, it is necessary to create a WriterGroup and a DataSetWriter. If UaExpert is connected to the OPC UA server of the Publisher, the Variables can be selected in the Address Space view and can be added to Published DataSet with drag&drop. For first tests with the C++ SDK Demo Server the simulated variables in Objects > Demo > 001_Dynamic > Scalar can be used as source variables with different data types. A larger number of simulated variables can be found in Objects > Demo > 007_Massfolder_Dynamic.

To receive data in the Subscriber, it is necessary to create a ReaderGroup and a DataSetReader. To create a DataSetReader, it is necessary to have the corresponding configuration of the related DataSetWriter available in the UaExpert PubSub configuration. The configuration of a Publisher can be loaded as a standard PubSub binary configuration file.

If UaExpert is connected to the OPC UA server of the Subscriber, the target variables can be selected with drag&drop from the Address Space view to the Target Variable list of the DataSetReader. For first tests with the C++ SDK Demo Server the variables in Objects > Demo > 000_Static > Scalar can be used as target variables with different data types.

See the documentation of UaExpert for more details.

PubSubImporter

The PubSubImporter provides an example for the use of the UA PubSub Base Library for the off-line creation of a PubSub configuration. The UA PubSub Base Library can also be used to create the PubSub configuration inside the OPC UA server based on product specific configuration options.

The PubSubImporter can also be used as simple configuration tool.

The PubSubImporter creates the standardized OPC UA binary encoded PubSub configuration files from an INI text file and is able to download the file to the C++ SDK Demo Server using OPC UA client/server.

The tool is working with the following input files in the working directory of the tool

  • PubSubClientConfig.ini contains the basic client configuration necessary to to connect to a server
  • PubSubConfigImport.ini contains the PubSub configuration in a simplified text form

Sample files can be found in the SDK setup directory in examples/config. The files must be copied to the working directory of the PubSubImporter (e.g. sdk/bin)

The following actions are possible with the PubSubImporter console application

Create configuration from INI file

This option reads the configuration from the file PubSubConfigImport.ini and prints the read configuration objects to the console output. The file must be located in the working directory of the PubSubImporter.

Save configuration to PubSub binary file

This option creates an OPC UA binary encoded PubSub configuration file from the imported configuration.

The output file name is pubsubconfig_out.uabinary. The file is stored in the working directory of the PubSubImporter.

The file can be used to replace the demo server configuration. This requires to stop the demo server, to replace the file and to start the server with the new file.

Load DataSetWriters from PubSub binary file

The configuration of a subscriber requires knowledge about the configuration of the WriterGroups and DataSetWriters of interest. This option allows the import of a Publisher configuration that contains the WriterGroups and DataSetWriters referenced in the Subscriber configuration.

The import file name is pubsubconfig_in.uabinary. The file is stored in the working directory of the PubSubImporter.

If a Publisher configuration is necessary, this option must be used before the Subscriber configuration is imported with the INI file.

Transfer configuration to server

The option allows the transfer of the imported configuration to the server.

It is necessary to create a connection to the server using the option "Connect to server".

Changes to the configuration require a user with the role ConfigureAdmin.

Working with PubSub

The import file PubSubConfigImport.ini provided with the SDK contains a Publisher and Subscriber configuration. If this configuration is imported and loaded to the demo server, the Subscriber receives the messages produced by its own Publisher.

The following steps describe how a configuration can be created with two demo servers on different network nodes.

Example:
In this example, we use two Demo servers and two PCs.
The first Demo server, which is running on PC1 consider it as a Publisher
The second Demo server, which is running on PC2 consider it as a Subscriber

PC1-Publisher

The following configuration options must be provided in the file PubSubConfigImport.ini for the publisher configuration. The file contained in the SDK setup can be used as example.

PubSubConnection

  • Create a PubSubConnection with required parameters: TransportFacet, Address Url (e.g: opc.udp://239.0.0.1:4840), AddressNetworkInterface (IP address of the Publisher) and PublisherId
  • Both Publisher and Subscriber must have a same Address Url if UDP multicast is used.

WriterGroups

  • Create WriterGroups with required parameters: PublisherId, PublishingInterval, KeepAliveTime, WriterGroupId, MaxNetworkMessageSize and UadpHeaderConfiguration

DataSetWriters

  • Each WriterGroup can have different DataSetWriters such as Simple, AllTypes and MassData (use UA variables to fill these DataSets)
  • All the DataSetWriters must have a unique DataSetWriterId

PublishedDataSets

  • A single Publisher may support multiple PublishedDataSets and multiple DataSetWriters
  • Creation of this information depends on the product configuration

PC2-Subscriber

As first step, the Publisher binary configuration file must be imported.

The following configuration options must be provided in the file PubSubConfigImport.ini for the subscriber configuration. The file contained in the SDK setup can be used as example.

PubSubConnection

  • Create a PubSubConnection with required parameters: TransportFacet, Address Url (e.g : opc.udp://239.0.0.1:4840), AddressNetworkInterface (IP address of the Subscriber) and PublisherId
  • Both Publisher and Subscriber must have a same Address Url if UDP multicast is used.
  • The PublisherId is not relevant for the Subscriber functionality but a unique PublisherId should be configured for each PubSub application

ReaderGroups

  • Create ReaderGroups with DataSetReaders. ReaderGroups must have a MaxNetworkMessageSize parameter

DataSetReaders

  • Configure PublisherId, DataSetWriterId of each DataSetReader. It must match the Publisher setting and the parameter MessegeReceiveTimeout value is required for all the DataSets.
  • The Subscriber must have configured filters (like a PublisherId, DataSetWriterId) so that it can drop all messages that do not match the filter

SubscribedDataSets

  • SubscribedDataSet is a list of targetVariables (use either PubSubTargetVariables or static UA variables)
  • A single Subscriber may support multiple SubscribedDataSets and multiple DataSetReaders
  • Creation of this information depends on the product configuration

The following pages provide further information on the PubSub functionality in the SDK: