OPC UA Client
This page describes how Connectware can act as an OPC UA client. Connectware can also act as an OPC UA server.
For more information on OPC UA, see the OPC Foundation Reference.
OPC UA Subscriptions
OPC UA distinguishes between sessions, subscriptions, and monitored items.
Each Connectware connection creates exactly one session in the OPC UA terminology, where Connectware acts as a client towards the server.
Within one session, the set of data endpoints are grouped into subscriptions. A subscription carries parameters like
publishIntervalandmaxNotificationsPerPublishthat control the data flow between server and client.Within each subscription, the actual data endpoints (also called nodes) are subscribed as monitored items. Monitored items are configured by parameters like
nodeId,attributeId, andsamplingInterval, which control how the server collects the data. Each network request for creating these can create one or multiple monitored items per request.
Connectware Subscriptions
Connectware abstracts this complexity by combining as many endpoints as possible into the same subscription and grouping monitored items creation into the same request. This is done according to the following criteria:
Each OPC UA
Cybus::Connectionresource creates exactly one session.Within this session, all OPC UA
Cybus::Endpointresources with the samepublishIntervalproperty are combined into one subscription. This holds even across different service commissioning files using inter-service referencing, see here. Therefore, enabling or disabling additional services with additional endpoints will add or remove those endpoints from the currently available subscription.Every OPC UA
Cybus::Endpointresource corresponds to one monitored itemWithin one subscription and within the same service commissioning file, all endpoints (monitored items) with the same
samplingIntervalproperty are combined into one common creation request calledCreateMonitoredItemsGroupRequest. This request works efficiently even for thousands of monitored items.
Subscription Limitations
Some OPC UA servers are known for imposing certain limits on the number of monitored items, either in total, or per subscription, or per request.
In particular, an embedded OPC UA server on a Siemens S7-1500 or S7-1200 PLC is known for certain restrictions, see System limits of OPC UA Server.
For example, the maximum number of monitored items within one "create monitored items request" might be limited to 1000 nodes. This limit can be looked up in the OPC UA node with
nodeIdns=0;i=11714. On the Connectware side, this limit must be taken into account by setting themaxMonitoredItemsPerCallproperty in theCybus::Connectionresource to the respective value. This ensures that larger requests are split so that all requests stay within this limit.Additionally, a maximum number of monitored items in total might be configured in the TIA Portal project. Unfortunately, there is no known way to look up this value except directly in TIA Portal. If such a value is set, Connectware cannot create more endpoints than this limit.
Regarding the created subscriptions: Currently, subscriptions are combined only by the publishInterval parameter. The remaining properties related to subscriptions are currently taken only from the first endpoint to be subscribed, while differing settings at subsequent endpoints are ignored. This concerns the following endpoint properties: requestedLifetimeCount, requestedMaxKeepAliveCount, maxNotificationsPerPublish, and priority.
Example
This is an example configuration snippet with three endpoints (without the connection configuration):
In the above example, two subscriptions will be created. One with publishInterval set to 1000ms and maxNotificationsPerPublish set to 100, and another with publishInterval set to 15000ms. The sampling of the individual source values will be set as expected by the specified samplingInterval property, but remember that OPC UA does not offer fixed data sampling but rather applies a change-of-value filter to each data point automatically.
Service Commissioning File Example
Basic Example
This is a simple OPC UA connectivity example that only subscribes to the “Server Status” node of an OPC UA server. The proposed node (endpoint) can also be used if the server would otherwise close the connection, which has been observed for some specific versions of OPC UA servers on a S7 PLC.
The example will need some OPC UA server available in your network:
Advanced Example
More complex example including an OPC UA server container from public Docker Hub:
Example with Method Endpoint
Output Format on Reading
When data is read from OPC UA, the output is provided as a JSON object with value and timestamp.
The given timestamp is the OPC UA “Source Timestamp” which was set on the data source side, see https://reference.opcfoundation.org/v104/Core/docs/Part4/7.7.3/
If 64-bit integers are used (which are unsupported in JSON but are supported in JavaScript by the BigInt class), the value is returned as a string containing the decimal number.
Output Format on Writing
Variables
When data is written to an OPC UA endpoint, you will receive the result of the operation on the /res topic like this:
The id field is only included if the original request contained an id. The value is returned unchanged and can be used to correlate request and response. This behavior applies to both read and write operations.
Method Calls
Method calls follow the same pattern as variable operations:
Write the method call data to the
/settopic.Receive the result on the
/restopic.
Example
Input Format
Variables
When writing to an OPC UA variable, format the data as a JSON object.
Method Calls
Calling OPC UA methods follows the same pattern as writing to OPC UA variables.
The value has to include the input arguments like this. You can optionally include an id parameter.
Complex Data Types
OPC UA nodes can hold simple values (Boolean, Int32, String) or structured values (objects with fields, nested objects, arrays). Connectware maps structured OPC UA values to JSON objects, so you can read, subscribe, and write them using standard Cybus::Endpoint resources.
In OPC UA, complex data types are modeled as structured DataTypes and exchanged at runtime as ExtensionObjects. A complex data type is the logical definition of the data structure, while an ExtensionObject is the physical container used to transport that data over the network.
The following operations are supported for complex data types:
Read: Retrieve the current value of a complex variable node.
Write: Update a complex variable node with new structured data.
Subscribe: Receive notifications when a complex variable changes.
Method call: Invoke OPC UA methods with complex data type parameters.
Prerequisites
Before working with complex data types, ensure the following:
Identify the
nodeIdof the variable node that exposes the structured value on the OPC UA server.For method calls, identify the
nodeIdof the corresponding method node.Make sure the OPC UA server already defines the structured DataType for that node.
Know the exact structure of the DataType as defined on the server, including field names, nesting, scalar versus array definitions, and data types. The JSON payload used in Connectware must match this structure exactly.
Case sensitivity is important. Use the exact field name as defined on the OPC UA server. For example, if the field name is
MachineName, thenmachineNamewill not work (OPC UA standard).
Example Structure
In the examples below, the complex value has this JSON structure:
When writing data, the JSON structure must match the data type defined on the OPC UA server for that node.
Service Commissioning File Example
No special configuration is required to work with complex data types. Use standard Cybus::Endpoint resources with the nodeId of the complex variable node:
Subscribing and Receiving Complex Values
Create a
Cybus::Endpointwith thenodeIdof the complex variable node. No special configuration is required for structured data.Subscribe as usual using the
nodeId.The structured object appears inside the
valuefield of each message.
Incoming message format:
Writing a Complex Value to a Variable Node
To write complex data to a variable node, send the JSON object as the payload's value.
Example Topic
services/robot/writeRobotEndpoint/set
Payload
Put the structured object inside value.
Result
You will receive the operation result on the /res topic, same as writing primitives.
Calling a Method with a Complex Input Parameter
Publish the method call payload to the endpoint
/settopic.Read the call result on the
/restopic.
Example Topic
services/robot/setRobotMethod/set
Payload
Include the structured object inside inputArguments. In this example, data is the input argument name as defined in the OPC UA method. Use the actual input argument name defined in your method.
Result
Method calls follow the same /set and /res pattern as variable writes.
Deadband Limitations
The deadbandType and deadbandValue options are generally not applicable to complex data types.
However, if a primitive numeric field inside a complex structure is accessible via its own variable node (i.e., having its own nodeId), you can create a separate endpoint for that specific node and apply deadband settings there.
Reconnection Behavior
In OPC UA connections, as with any network connections, the connection can be lost. When this happens, Connectware's OpcuaConnection will automatically switch into a reconnecting state and repeatedly try to re-establish the connection.
You can control the exact behavior of how often this is attempted by the optional connectionStrategy properties, see Connection Properties. The maxDelay property sets the maximum waiting time (delay) between consecutive retries, in milliseconds. The waiting time starts with the initialDelay value and is then increased step by step until reaching the maxDelay value.
Example with initially 500ms waiting time, increasing up to 10 seconds:
For further details, see the documentation of the internally used package backoff: https://www.npmjs.com/package/backoff
Events for OPC UA
Event subscriptions can be created in Connectware by adding the fields and eventTypes properties to the Cybus::Endpoint resource as shown in the example below.
The names for the fields should be qualified names. Often, this will require the field name to also contain a namespace identifier, for example 4:MyQualifiedName.3:SubitemQualifiedName. Additionally, the field names often need a sub-type, which can be specified using dot notation after the name.
Accessing Status Codes for Values
The quality of a data value in OPC UA is represented by predefined status codes. The statusCode is transferred to the $context object and can be retrieved within the Rule Engine of a Cybus::Endpoint via $context.raw.statusCode as shown in the example below.
Last updated
Was this helpful?

