Skip to main content
Skip table of contents

OPC UA Subscriber Adapter

This adapter establishes a connection to an OPC UA Server and subscribes or cancels data changes or events.

Properties

Operation

Operation executed by the adapter

Possible values:

  • Subscribe: Subscribes to data changes or events according to the input XML document.

  • UnSubscribe: Cancels existing subscriptions for a specific client

Parameters

Adapter

Adapter main class (do not change!)

Possible values: de.softproject.integration.adapter.opcua.OpcUaSubscriberAdapter Main class (default)

clientAlias

Alias to identify the connection settings

Possible values: Any string with the client alias

process

X4DB path to a Technical Process that is executed after each subscriber reception.

Possible values: Any valid X4DB path, e. g. x4db://1/SampleProject/SampleProcess.wrf

url

Server URL

Possible values: Any valid URL, e. g. opc.tcp://SP-WS-204.softproject.local:53530/OPCUA/SimulationServer

user

Username to connect to the server

Possible values: Any string with the user name, e.g.  myUser

password

Password to connect to the server

Possible values: Any string with the password , e. g. myPassword

security mode

Security Mode and Server Policies

Possible values:

  • NONE
  • BASIC256_SIGN
  • BASIC256_SIGN_ENCRYPT
  • BASIC128RSA15_SIGN
  • BASIC128RSA15_SIGN_ENCRYPT
  • BASIC256SHA256_SIGN
  • BASIC256SHA256_SIGN_ENCRYPT
autoReconnect

Specifies whether the client should automatically reconnect to the server or not.

Status values

1

The adapter operation was executed successfully

-1An error occurred while executing the adapter

Input

Operation Subscribe

  • Complete example with different subscription types:

    Input for the Subscribe operation

    XML
    <?xml version="1.0" encoding="UTF-8"?>
    <Subscriptions>
    	<!-- Subscription to a data value change -->
     	<Subscription type="DATA_CHANGE" nodeIndex="3" nodeIdentifier="Counter" nodeIdentifierType="String"></Subscription>
    
    	<!-- Subscription to an event, specifying a condition -->
     	<Subscription type="EVENT" nodeIndex="5" nodeIdentifier="MyLevel.Alarm" nodeIdentifierType="String">
     		<Field name="SourceName">
     			<Literal>LIKE</Literal>
    			<Operand>Server</Operand>
     		</Field>
     	</Subscription>
    
    	<!-- Subscription to an event, specifying more than one condition -->
    	<Subscription type="EVENT" nodeIndex="5" nodeIdentifier="MyLevel.Alarm" nodeIdentifierType="String">
    		<Field name="ActiveState" attributeId="13">
     			<Operand>EQUALS</Operand>
     			<Literal>Active</Literal>
    		</Field>
    		<Field name="AckedState" attributeId="13">
     			<Operand>EQUALS</Operand>
     			<Literal>Unacknowledged</Literal>
    		</Field>
    		<Field name="Comment" attributeId="13"></Field>
    		<Field name="EnabledState" attributeId="13"></Field>
    		<Field name="EventType" attributeId="1">
    			<Operand>EQUALS</Operand>
    			<Literal>i=9482</Literal>
    		</Field>
    		<Field name="Quality">
     			<Operand>EQUALS</Operand>
      			<Literal>GOOD (0x00000000) ""</Literal>
    		</Field>
    		<Field name="Severity">
     			<Operand>LESS_THAN</Operand>
     			<Literal>600</Literal>
    		</Field>
    		<Field name="SourceName"></Field>
    		<Field name="Time"></Field>
    	</Subscription>
    
    	<!-- Configuring  -->
     	<OnAfterCreate>x4db://1/TestingOPCUA/Processes/OnAfterCreate.wrf</OnAfterCreate>
     	<OnAlive>x4db://1/TestingOPCUA/Processes/OnAlive.wrf</OnAlive>
    </Subscriptions>
  • Subscribe to data value change:

    To subscribe to a data value change, a Subscription node must be created with the following mandatory attributes:

    • type to define the type of subscription
    • nodeIndex, nodeIdentifier to identify the OPC UA node from which the changes are subscribed to
    • nodeIdentifierType to specify the data type of the node identifier.

    The Subscription node can contain the following optional attributes:

    • samplingInterval: Value in milliseconds with which the OPC UA server samples the data source (PLC).
    • publishingInterval Value in milliseconds with which the OPC UA server sends the data to the client (e.g. X4).
    XML
    <?xml version="1.0" encoding="UTF-8"?>
    <Subscriptions>
    	<Subscription type="DATA_CHANGE" nodeIndex="3" nodeIdentifier="Counter" nodeIdentifierType="String" samplingInterval="1000" publishingInterval="1000">
    	</Subscription>
    </Subscriptions>
  • Subscribe to events without specifying fields:

    XML
    <?xml version="1.0" encoding="UTF-8"?>
    <Subscriptions>
    	<!-- We will receive an empty event -->
    	<Subscription type="EVENT" nodeIndex="5" nodeIdentifier="MyLevel.Alarm" nodeIdentifierType="String">
    	</Subscription>
    </Subscriptions
  • Subscribe to events and specify fields:

    XML
    <?xml version="1.0" encoding="UTF-8"?>
    <Subscriptions>
    	<!-- In the Field node, we define the field we want to retrieve on each event reception. -->
    	<Subscription type="EVENT" nodeIndex="5" nodeIdentifier="MyLevel.Alarm" nodeIdentifierType="String">
    		<Field name="SourceName"></Field>
    		<Field name="Time"></Field>
    	</Subscription>
    	<!-- Any number of Field nodes possible. -->
    </Subscriptions>
  • Subscribe to events and define filters for the specified fields:
    It is possible to define conditions for the attributes that will be received on each event reception. For this purpose, a corresponding number of Field nodes must be created. Each Field node contains the elements Literal and Operand.

    Subscribe event with filters

    XML
    <?xml version="1.0" encoding="UTF-8"?>
    <Subscriptions>	
    	<!-- In the Field node, we define the field we want to retrieve on each event reception. Inside this node Operand and Literal are defined in order to create the condition over the field. -->
    	<Subscription type="EVENT" nodeIndex="5" nodeIdentifier="MyLevel.Alarm" nodeIdentifierType="String">
    	<!-- Severity less than 600 -->
    	<Field name="Severity"> 
    		<Operand>LESS_THAN</Operand> 
    		<Literal>600</Literal>
    	</Field>
    	</Subscription>
    	<!-- Any number of Field nodes possible. If there is more than one Field node containing conditions, the logical operator applied between fields will be 'OR' -->
    </Subscriptions>

    Note:

    • The name attribute within Field is required.
    • Operand can have the following values:
      • LESS_THAN
      • LESS_THAN_OR_EQUALS
      • GREATER_THAN
      • GREATER_THAN_OR_EQUALS
      • EQUALS
      • NOT
      • LIKE
    • Literal contains the various literal values to be included within the expression.

Operation Unsubscribe

The UnSubscribe operation does not require any input, since a cancellation of the subscription is performed. Therefore, only the alias of the client must be specified in the clientAlias parameter.

Output

Operation Subscribe

The output structure depends on the type of receive message.

  • When an event is received with fields (with or without conditions) configured in the subscription, the response structure resembles the following sample output:

    Output for event responses

    XML
    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <Message type="EVENT">
        <Node description="ns=5;s=MyLevel.Alarm"/>
        <Fields>
            <Field fieldName="ActiveState">Active</Field>
            <Field fieldName="AckedState">Unacknowledged</Field>
            <Field fieldName="Comment">EMPTY</Field>
            <Field fieldName="EnabledState">Enabled</Field>
            <Field fieldName="EventType">i=9482</Field>
            <Field fieldName="Quality">GOOD</Field>
            <Field fieldName="Severity">500</Field>
            <Field fieldName="SourceName">MyLevel</Field>
            <Field fieldName="Time">1576741128000</Field>
        </Fields>
    </Message>

    Specifying conditions results in more or fewer events being received. However, once an event is received, the response contains the fields specified in the subscription.

  • If an event is received without field specifications, the response structure resembles the following sample output:

    Output for event responses

    XML
    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <Message type="EVENT"/>
  • If a data value change is received, the response structure resembles the following sample output:

    Output for data value changes

    XML
    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <Message type="DATA_CHANGE">
        <Node description="ns=3;s=Counter"/>
        <OldValue>
    		<!-- 0 means null timestamp  -->
            <sourceTimestamp>0</sourceTimestamp>
    		<!-- No value and statusCode present in 'OldValue' node happens only just after subscribing on the first reception -->
        </OldValue>
        <NewValue>
            <sourceTimestamp>13221214634996</sourceTimestamp>
            <statusCode>GOOD</statusCode>
            <value>2312.11</value>
        </NewValue>
    </Message>

Operation Unsubscribe

The UnSubscribe operation has no output because the status 1 means that the operation was executed successfully.

Alive Listener Configuration

There is an Alive Listener that allows to configure actions for each live notification of a subscription.

Processes can be defined for the following situations:

  • After create: The subscription has been (re)created on the server. This is the case when the subscription timed out due to a communication interruption and needs to be recreated after reconnection.
  • Alive: The server confirmed that the connection was active, although there were no changes to send.
  • Life timeout: The server has not confirmed that the connection is active and the life timeout has been exceeded.
  • Timeout: The server has not confirmed that the connection is active and the maximum keepalive count has been exceeded.

The actions are defined as part of the input XML document as follows:

Input for Subscribe operation

XML
<?xml version="1.0" encoding="UTF-8"?>
<Subscriptions>
 	<Subscription ...></Subscription>
 	<Subscription ...></Subscription>

	<!-- Alive listener actions  -->
	<!-- We can define some of them or none, they are not required -->

 	<OnAfterCreate>x4db://1/TestingOPCUA/Processes/OnAfterCreate.wrf</OnAfterCreate>
 	<OnAlive>x4db://1/TestingOPCUA/Processes/OnAlive.wrf</OnAlive>
 	<onLifetimeTimeout>x4db://1/TestingOPCUA/Processes/onLifetimeTimeout.wrf</onLifetimeTimeout>
 	<onTimeout>x4db://1/TestingOPCUA/Processes/onTimeout.wrf</onTimeout>
</Subscriptions>
JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.