OPC UA Data Receiver
    • Dark
      Light

    OPC UA Data Receiver

    • Dark
      Light

    Article summary

    The OPC UA data receiver connects to and reads data from an OPC UA server. The examples below show multiple ways of retrieving data from the OPCUA servers. (The polling method is deprecated and not shown)

    Example #1: Pubsub subscription:

    If we want to retrieve data for SM_AA_Example_1 from an OPC UA server at 192.168.0.144, our configuration will look something like this:

    {
      "data_receiver": [
        {
          "data_receiver_name": "my_opcua_receiver",
          "protocol": "opcua",
          "poll_interval": 10,
          "connections": [
            {
              "host": "192.168.0.144",
              "port": 49320,
              "timeout": 5,
              "subscribe": true,
              "default_namespace_index": 0,
              "max_tags_per_subscription": 100
            }
          ],
          "streams": [
            {
              "asset": "SM_AA_Example_1",
              "stream_type": "cycle",
              "subscription_type": "pubsub",
              "opcua_tags": [
                {
                  "name": "Simulation Examples.Functions.Ramp1",
                  "exportname": "Ramp1",
                  "asset": "SM_LOC_Example_1"
                }
              ]
            }
          ]
        }
      ]
    }

    Example #2: Event subscription:

    Unlike Example #1, events have two parameters that are necessary for subscription: “server_node_id” and “node_id”.

    {
        "data_receiver_name": "my_opcua_receiver",
        "protocol": "opcua",
        "poll_interval": 15,
        "connections": [
            {
                "host": "192.168.0.144",
                "port": 49320,
                "subscribe": true,
                "server_node_id": "0:Objects;0:Server"
            }
        ],
        "streams": [
            {
                "asset": "A1",
                "stream_type": "S1",
                "subscription_type": "event",
                "node_id": "0:Types;0:EventTypes;0:BaseEventType;2:MyEvent",
                "opcua_tags": [
                    {
                        "name": "field1",
                        "exportname": "field1"
                    },
                    {
                        "name": "custom_structure.field1",
                        "exportname": "custom_field1"
                    }
                ]
            }
        ]
    }

    Example #3: Read History:

    Unlike Example #1, events have two parameters that are necessary for subscription: “server_node_id” and “node_id”.

    {
        "data_receiver_name": "my_opcua_receiver",
        "protocol": "opcua",
        "poll_interval": 15,
        "connections": [
            {
                "host": "localhost",
                "port": 51240,
                "use_history": true,
                "default_namespace_index": 0,
                "default_history_params": {
                    "start_datetime": "2022-01-01T00:00:00"
                }
            }
        ],
        "streams": [
            {
                "asset": "A1",
                "stream_type": "S1",
                "opcua_tags": [
                    {
                        "name": "field1",
                        "exportname": "field1"
                    }
                ]
            },
            {
                "asset": "A2",
                "stream_type": "S1",
                "history_params": {
                    "start_datetime": "2021-05-01T05:00:00",
                    "interval_seconds": 3600,
                    "max_request_records": 10000
                },
                "opcua_tags": [
                    {
                        "name": "field1",
                        "exportname": "field1"
                    }
                ]
            }
        ]
    }

    Configuration:

    Required and optional properties that can be configured for an OPC UA receiver:

    • connections: How to connect to an OPC UA server and retrieve tags. An OPC UA connection has the following configurable settings:
      • host: Hostname or IP address of the OPC UA server
      • port: OPC UA port. Usually 4096 for Ignition or 49320 for other software.
      • username: Username used along with a password to access the OPC UA server.
      • password: Password used along with a username to access the OPC UA server.
      • server_name: OPC UA server name (e.g. iaopcua for Ignition)
      • timeout: Maximum number of seconds to wait for a response from an OPC UA server. Default is 10.0.
      • security_mode: Specifies the security mode for client-server messages. Allowed security modes are: None, Sign, and SignAndEncrypt. The default value is None. A certificate and private key is required to enable the Sign and SignAndEncrypt security modes. Please note that a security mode set to None can only be used along with a security policy set to None.
      • security_policy: Specifies the security mechanisms to be used when communicating with the server. A security policy describes algorithms for signing and encryption, and for key derivation. Allowed security policies are: None, Basic128Rsa15, Basic256, and Basic256Sha256. The default setting is None. A certificate and private key is required to enable the Basic128Rsa15, Basic256, and Basic256Sha256 security policies. Please note that a security policy set to None can only be used along with a security mode set to None. For more details about security policies, please refer to section 4.6 in Part 2 (Security Model) of the OPC UA specifications.
      • certificate_file_name: The file name of the X.509 certificate (ending with .der, or .pem) that the client uses to communicate with the server. This file should be saved to the /data/config directory. A private key must also be specified to enable this feature.
      • private_key_file_name: The file name of the private key (ending with .pem) used to sign and decrypt messages. This file should be saved to the /data/config directory. A certificate must also be specified to enable this feature.
      • default_namespace_index: Default namespace index to use when retrieving tags. The namespace index is usually displayed as the first part of a NodeId in your OPC UA browser. For example, if the NodeId is ‘ns=3;s=MyTag’ or ‘3:MyTag’ or ‘Ns3:MyTag’, then the namespace index is 3.
      • default_identifier_type: Default identifier type to use when retrieving tags. Supported types include String, Numeric, Guid, ByteString, ByteStringHex.
        • ByteString are base64 encoded bytes (e.g: AAAAAAEAAADIFwAAAAAYJK4WAAA=)
        • ByteStringHex are bytes represented as hex (e.g: 0000000001000000c817000000001824ae160000)
      • subscribe: Enable use of the publish/subscribe communication model instead of polling. Default is False.
      • server_node_id: Required if subscription_type="event". This supports a Node ID format (“ns=3;i=1000”) or a BrowseName format (“0:Objects;0:Server”) which identifies the node by going through the node hierarchy.
      • subscription_timeout: The amount of time in seconds to wait before values are received via the subscription. If the timeout is reached, the client refreshes the connection and tries again. Default is 60 seconds.
      • max_tags_per_subscription: The maximum number of tags for each subscription connection. Default is 100.
      • use_history: If enabled, reads data from the historian. Defaults to False.
      • default_history_params:
        • start_datetime: The start datetime to read historical data from.
        • interval_seconds: Time range to query for data per API call.
        • max_request_records: Max number of records to be read for the range in “interval_seconds” per API call.
        • guardband_seconds: History data will be read up to current time - guardband_seconds. This option adds a delay to ensure OPC-UA servers will have the data available. Defaults to 3 minutes.
      • max_history_continuation_points: By default, uses the server’s max limit setting. If errors with continuation point occur, use a lower number. (To avoid continuation points, consider increasing the “max_request_records” size)
    • streams: How to associate tags with assets and streams. Each input stream has the following configurable settings:
      • asset: Asset identifier
      • stream_type: Type of data stream
      • subscription_type: Required if subscribe is enabled. Options are pubsub, event. Defaults to pubsub
      • history_params: Overrides the “default_history_params” option.
      • opcua_tags: A list of data fields to fetch from the OPC UA server. Each data field configuration can have the following properties:
        • name: Full name of the tag to retrieve (e.g. Painting.Oven.FanSpeed). If this is for OPC UA events, we can use the dot delimiter to access nested structures.
        • exportname: Name of the field to use in the Sight Machine platform (e.g. Painting_Oven_Fan_Speed). The field name must not contain dots or dollar signs.
        • namespace_index: Namespace index of the tag to retrieve. This is usually displayed as the first part of a NodeId in your OPC UA browser. For example, if the NodeId is “ns=3;s=MyTag” or “3:MyTag” or “Ns3:MyTag”, then the namespace index is 3. If the namespace index is not specified, then it uses the value of default_namespace_index for the connection. (Does not apply to subscription events)
        • identifier_type: Overrides the “default_identifier_type” option.
        • node_id: Required if subscription_type="event" This specifies the event node we’re subscribing to. This supports a Node ID format (“ns=3;i=1000”) or a BrowseName format (“0:Objects;0:Server”) which identifies the node by going through the node hierarchy.
        • load_custom_structures Loads custom structures stored by the OPC UA server. If we run into issues when reading event data, disabling this may allow us to read partial data. Default is true.
    • poll_interval: The number of seconds to wait between attempts to fetch new data from the OPC UA server.