This topic describes how to connect an OPC Unified Architecture (OPC UA) sub-device to a gateway and enable the sub-device to interact with IoT Platform.

Prerequisites

  • A Docker runtime environment is built for Link IoT Edge Pro.
  • An edge instance is created and the gateway assigned to the edge instance is brought online. For more information, see Link IoT Edge Pro.

Step 1: Build an OPC UA Server

The following table describes the environment requirements for an OPC UA Server.

Item Version Installation command
Python 3.5.2 or later None
PIP 9.0.1 or later None
OPC UA 0.98.3 or later pip install opcua==0.98.3

To build an OPC UA Server to simulate an LED light that is named demo_led and has the temperature property and high_temperature event, follow these steps:

  1. Run the following command to download the package of the OPC UA Server:
    wget http://iotedge-web.oss-cn-shanghai.aliyuncs.com/public/driverSample/opcua_simulation_server.tar.gz
  2. Run the following commands to start the OPC UA Server:
    tar -zxvf opcua_simulation_server.tar.gz
    cd opcua_simulation_server && ./opcua_simulation_server.sh

Step 2: Install an OPC UA client

Before connecting the simulated LED light to a gateway through an OPC UA driver, you must configure the simulated LED light. When configuring the simulated LED light, you must use an OPC UA client to obtain the information about the simulated LED light from the OPC UA Server. The obtained information is required when you create a product and configure the driver in the IoT Platform console.

In this example, UaExpert is used as an OPC UA client.

  1. Download and install UaExpert.
  2. Start UaExpert.
    UaExpert
  3. Click + in the toolbar.
    Add the OPC UA Server
  4. In the Add Server dialog box that appears, click the Advanced tab and set Endpoint Url to the URL of the OPC UA Server. In the URL, specify the IP address and port number of the host where the OPC UA Server resides in the Host IP address:Port number format.
    Note For example, if the default port number of the OPC UA Server is 4840 and the IP address is 192.168.1.1, set the Endpoint Url parameter to the following value:
    opc.tcp://192.168.1.1:4840
    Set the URL of the OPC UA Server
  5. Click OK. The information about the simulated LED light appears.
    Information about the simulated LED light

Step 3: Add the simulated LED light as an OPC UA sub-device

  1. Create an OPC UA product. For more information, see Create a product.
    Create a product

    The following table describes some required parameters.

    Parameter Description
    Node Type Select Gateway sub-device.
    Gateway Connection Protocol Select OPC UA.
  2. Add custom features for the product. For more information, see Define features.
    • Add a property
      1. Set required parameters for the property, as shown in the following figure.Set property parameters
      2. Click Add Extended Information. In the Add Extended Information dialog box that appears, set Node Name.Add extended information
        To obtain the value of Node Name, find the simulated LED light named demo_led in UaExpert and click temperature under demo_led. Check the value of DisplayName in the Attributes section on the right and use it as the value of Node Name.Variable on the OPC UA Server
    • Add a service
      1. Set required parameters for the service, as shown in the following figure.Set service parameters
      2. Click Add Parameter under Input Parameters to add a parameter for the service.Add a service parameter
      3. Click Add Extended Information. In the Add Extended Information dialog box that appears, set Node Name.Add extended information

        To obtain the value of Node Name, find the simulated LED light named demo_led in UaExpert and click led_method under demo_led. Check the value of DisplayName in the Attributes section on the right and use it as the value of Node Name.

        Variable on the OPC UA Server
    • Add an event
      1. Set required parameters for the event, as shown in the following figure.Set event parameters
      2. Click Add Parameter under Output Parameters to add a parameter for the event.Add an event parameter
      3. Click Add Extended Information. In the Add Extended Information dialog box that appears, set Node Name.Add extended information

        To obtain the value of Node Name, find the high_temperature event of the simulated LED light in UaExpert and click the event name. Check the value of DisplayName in the Attributes section on the right and use it as the value of Node Name.

        Variable on the OPC UA Server
  3. Add the simulated LED light as a sub-device to the OPC UA product. For more information, see Create a device.
    Add a sub-device

Step 4: Configure the edge instance

  1. On the homepage of the IoT Platform console, choose Link IoT Edge > Edge Instances in the left-side navigation pane. On the Edge Instances page, find the target edge instance and click View in the Actions column.
  2. On the Instance Details page that appears, click the Devices & Drivers tab and then click Assign Driver. In the Assign Driver dialog box that appears, select Official Drivers, find the driver named OPCUA, and then click Assign in the Actions column.
    Assign the OPCUA driver to the edge instance
  3. Go back to the Devices & Drivers tab, click OPCUA in the All Drivers section on the left, and then click Driver Configurations next to Devices on the right. In the Driver Configurations dialog box that appears, click Add Channel. In the Add Channel dialog box that appears, set channel parameters and click OK.
    Driver Configurations
    Table 1. Description of channel parameters
    Parameter Description Example
    Channel Name The name of the OPC UA channel. opcua_server
    Channel Address The URL of the OPC UA Server. opc.tcp://192.168.1.1:4840
    Username The username for connecting to the OPC UA Server. demo
    Password The password for connecting to the OPC UA Server. abc123
    Timeout Period for Method Calls The timeout period of a request for calling the OPC UA Server. 10
  4. On the Devices & Drivers tab, click OPCUA in the All Drivers section on the left and click Assign Sub-device under Devices. In the Assign Sub-device dialog box that appears, find the simulated LED light and click Assign in the Actions column.
    Assign a sub-device
  5. Go back to the Devices & Drivers tab, find the simulated LED light you assigned, and then click Device Configurations in the Actions column. The Device Configurations dialog box appears.
    Device Configurations
    Table 2. Description of parameters in the Device Configurations dialog box
    Parameter Description
    Associate Channel Select the channel you added.
    Node Path Set this parameter to the absolute path of the simulated LED light on the OPC UA Server. The path starts with Objects.

    In this example, the absolute path is Objects/demo_led.

  6. On the Instance Details page of the edge instance, click Deploy in the upper-right corner to deploy the edge instance.
  7. On the Instance Details page, click the Devices & Drivers tab. Click OPCUA in the All Drivers section on the left, find the simulated LED light on the right, and then check whether the value of Device Status is Online.
    Online