Skip to content

OPC-UA General Example

This example usage of the OPC-UA Device Service demonstrates the onboarding of the Prosys OPC-UA Simulation Server to Edge Xpert over an insecure connection. Find an example of using a secure connection under the OPC-UA Security Example page.

A guide on configuring the OPC-UA Device Service to run with the Prosys OPC-UA Simulation Server can be found here.

Start the OPC-UA Device Service

To start the OPC-UA Device Service, enter the following command:

edgexpert up device-opc-ua

Device Onboarding

Once the OPC-UA Device Service has been started, OPC-UA devices can be connected to Edge Xpert using either the Edge Xpert Manager UI or through Edge Xpert REST API commands. Instructions on how to use both methods can be found below.

Please confirm the NodeId and DateType attributes of the resources defined in the example device profile match the NamespaceIndex, NodeId, and IdentifierType values defined for Objects in the Prosys Simulation Server. See Using the Prosys Simulator.

Device Onboarding with the Edge Xpert Manager UI

Note

Please refer to the Edge Xpert Manager UI Device Management capability for full details.

  1. Ensure the Edge Xpert Manager UI is started, for example:

    edgexpert up xpert-manager
    

  2. Open a browser and go to localhost:9090. The default username and password is admin

  3. Using the device profile upload capability, upload the provided OPC-UA example device profile at /usr/share/edgexpert/examples/device-services/opc-ua/prosys-opc-ua-simulation-server-profile.yaml

  4. Onboard the device using the device onboarding capability. The following values can be used to provision the OPC-UA Simulation device:

    Field Example Value Description Required
    Name Prosys-OPC-UA-Simulation-Server The unique name used to identify the device Required
    Description Simulated OPC-UA server Any additional information to help identify the device Optional
    Label OPC-UA Any additional information to help identify the device Optional
    Protocol OPC-UA The name of the protocol Required
    Host 172.17.0.1:53530/OPCUA/SimulationServer The OPC-UA endpoint. The provided example is the address for Prosys OPC-UA Simulation Server Required
    Security Policy None The security policy used to connect to the OPC-UA server Required
    Username The username to use when connecting to an endpoint. Default is an empty string Optional
    Password The base64 encoded password to use when connecting to an endpoint. Default is an empty string Optional
    Browse Depth 0 The maximum depth of the server tree browse for the device. If set to 0, no browse or browsePath translations take place for this device Optional
    Root Node The nodeId representing the starting point for the TranslateBrowsePathsToNodeIds Service and the full server tree browse functionality. If not specified, neither the TranslateBrowsePathsToNodeIds service nor the browse functionality are enabled for the device Optional
    Requested Session Timeout 1200000 The suggested timeout for sessions created between the Device Service and an OPC-UA server endpoint in milliseconds

    Note: Whether this value is accepted is up to the discretion of the server to which the Device Service connects. The actual value used can vary depending on the server vendor and its associated minimum and maximum supported values. Default is 1200000
    Optional
    Device Profile Prosys-OPC-UA-Simulation-Server-Profile The name of the device profile uploaded above Required
    Device Service device-opc-ua The name of the appropriate device service Required
    Auto Events Interval: 5s
    OnChange: false
    ResourceName: Counter1
    Automated events to retrieve the data at specific frequencies

    Note: If OnChange is set to true, values will only be pushed if a change in value has occurred during the specified interval. If set to false, values will be sent on the specified regardless of if there has been a change.
    Optional

Device Onboarding using the Edge Xpert REST API

Info

If Edge Xpert is running in secure mode, you will need to replace localhost in the URL with the IP address for the service. See CLI Service Ports for details.

  1. Upload the provided OPC-UA example device profile:

    curl http://localhost:59881/api/v2/deviceprofile/uploadfile -F "file=@/usr/share/edgexpert/examples/device-services/opc-ua/prosys-opc-ua-simulation-server-profile.yaml"
    

  2. Onboard the device using similar values as with the Edge Xpert Manager UI:

    curl -X 'POST' \
      'http://localhost:59881/api/v2/device' \
      -H 'Content-Type: application/json' \
      -d '[
      {
        "apiVersion": "v2",
        "device": {
          "name": "Prosys-OPC-UA-Simulation-Server",
          "description": "Example OPCUA Server",
          "adminState": "UNLOCKED",
          "operatingState": "UP",
          "labels": [
            "OPCUA"
          ],
          "serviceName": "device-opc-ua",
          "profileName": "Prosys-OPC-UA-Simulation-Server-Profile",
          "protocolName": "opc-ua",
          "autoEvents": [
            {
              "interval": "5s",
              "onChange": false,
              "sourceName": "Counter1"
            }
          ],
          "protocols": {
            "OPC-UA": {
              "Address":"172.17.0.1:53530/OPCUA/SimulationServer",
              "BrowseDepth": "0",
              "RequestedSessionTimeout": "1200000",
              "SecurityPolicy": "None"
            }
          }
        }
      }
    ]'
    

Device Data Flow

Once a device is connected to Edge Xpert, you can view the data flow between the device service and the connected device in a number of ways.

The Edge Xpert Manager UI supports Read and Write functionality for each device. Readings can also be viewed and queried within the Edge Xpert Manager UI Data Center.

Alternatively, you can read and write data with cURL commands or through REST API applications, such as Postman.

Info

If Edge Xpert is running in secure mode, you will need to replace localhost in the URL with the IP address for the service. See CLI Service Ports for details.

Both the GET and PUT commands can be made to the following address:

http://localhost:59882/api/v2/device/name/{deviceName}/{commandName}

Using the example above, a GET request to this device service could be:

curl http://localhost:59882/api/v2/device/name/Prosys-OPC-UA-Simulation-Server/Counter1

For more information on the GET and PUT commands, see the Core Command Microservice.

Any data collected by the device service can be processed like all other Edge Xpert sensor data. Data readings can be exported for data processing in a number of other applications and services. See the Support Services and Application Services for more details.