|
| 1 | +--- |
| 2 | +title: Discover OPC UA data sources using the Akri services |
| 3 | +description: How to discover and configure OPC UA data sources at the edge automatically by using the Akri services |
| 4 | +author: dominicbetts |
| 5 | +ms.author: dobett |
| 6 | +ms.subservice: azure-akri |
| 7 | +ms.topic: how-to |
| 8 | +ms.date: 05/15/2024 |
| 9 | + |
| 10 | +# CustomerIntent: As an industrial edge IT or operations user, I want to discover and create OPC UA data sources in my industrial edge environment so that I can reduce manual configuration overhead. |
| 11 | +--- |
| 12 | + |
| 13 | +# Discover OPC UA data sources using the Akri services |
| 14 | + |
| 15 | +In this article, you learn how to discover OPC UA data sources automatically. After you deploy Azure IoT Operations Preview, you configure the Akri services to discover OPC UA data sources at the edge. The Akri services create custom resources in your Kubernetes cluster that represent the data sources it discovers. The ability to discover OPC UA data sources removes the need to [manually configure them by using the operations experience web UI](howto-manage-assets-remotely.md). |
| 16 | + |
| 17 | +> [!IMPORTANT] |
| 18 | +> Currently, you can't use Azure Device Registry to manage the assets that the Akri services discover and create. |
| 19 | +
|
| 20 | +The Akri services enable you to detect and create assets in the address space of an OPC UA server. The OPC UA asset detection generates `AssetType` and `Asset` custom resources for [OPC UA Device Integration (DI) specification](https://reference.opcfoundation.org/DI/v104/docs/) compliant assets. |
| 21 | + |
| 22 | +## Prerequisites |
| 23 | + |
| 24 | +- Install Azure IoT Operations Preview. To install Azure IoT Operations for demonstration and exploration purposes, see [Quickstart: Run Azure IoT Operations Preview in Github Codespaces with K3s](../get-started-end-to-end-sample/quickstart-deploy.md). |
| 25 | +- Verify that the Akri services pods are properly configured by running the following command: |
| 26 | + |
| 27 | + ```bash |
| 28 | + kubectl get pods -n azure-iot-operations |
| 29 | + ``` |
| 30 | + |
| 31 | + The output includes a line that shows the Akri agent and discovery pods are running: |
| 32 | + |
| 33 | + ```output |
| 34 | + NAME READY STATUS RESTARTS AGE |
| 35 | + aio-akri-agent-daemonset-hwpc7 1/1 Running 0 17mk0s |
| 36 | + aio-opc-asset-discovery-wzlnj 1/1 Running 0 8m28s |
| 37 | + ``` |
| 38 | + |
| 39 | +## Configure the OPC UA discovery handler |
| 40 | + |
| 41 | +To configure the OPC UA discovery handler for asset detection, create a YAML configuration file that contains the values described in this section: |
| 42 | + |
| 43 | +| Name | Mandatory | Datatype | Default | Comment | |
| 44 | +| ---- | --------- | -------- | ------- | ------- | |
| 45 | +| `EndpointUrl` | true | String | null | The OPC UA endpoint URL to use for asset discovery | |
| 46 | +| `AutoAcceptUntrustedCertificates` | true ¹ | Boolean | false | Should the client autoaccept untrusted certificates? A certificate can only be autoaccepted as trusted if no nonsuppressible errors occurred during chain validation. For example, a certificate with incomplete chain isn't accepted. | |
| 47 | +| `UseSecurity` | true ¹ | Boolean | true | Should the client use a secure connection? | |
| 48 | +| `UserName` | false | String | null | The username for user authentication. ² | |
| 49 | +| `Password` | false | String | null | The password for user authentication. ² | |
| 50 | +
|
| 51 | +¹ The current version of the discovery handler only supports `UseSecurity=false` and requires `autoAcceptUntrustedCertificates=true`. |
| 52 | +² A temporary implementation until the Akri services can pass Kubernetes secrets. |
| 53 | +
|
| 54 | +The following example demonstrates discovery of an OPC PLC server. You can add the asset parameters for multiple OPC PLC servers. |
| 55 | +
|
| 56 | +1. To create the YAML configuration file, copy and paste the following content into a new file, and save it as `opcua-configuration.yaml`: |
| 57 | +
|
| 58 | + If you're using the simulated PLC server that was deployed with the Azure IoT Operations Quickstart, you don't need to change the `endpointUrl`. If you have your own OPC UA servers running or are using the simulated PLC servers deployed on Azure, add in your endpoint URL accordingly. Discovery endpoint URLs look like `opc.tcp://<FQDN>:50000/`. To find the FQDNs of your OPC PLC servers, go to your deployment in the Azure portal. For each server, copy and paste the **FQDN** value into your endpoint URLs. |
| 59 | +
|
| 60 | + ```yaml |
| 61 | + apiVersion: akri.sh/v0 |
| 62 | + kind: Configuration |
| 63 | + metadata: |
| 64 | + name: aio-akri-opcua-asset |
| 65 | + spec: |
| 66 | + discoveryHandler: |
| 67 | + name: opcua-asset |
| 68 | + discoveryDetails: "opcuaDiscoveryMethod:\n - asset:\n endpointUrl: \" opc.tcp://opcplc-000000:50000\"\n useSecurity: false\n autoAcceptUntrustedCertificates: true\n" |
| 69 | + brokerProperties: {} |
| 70 | + capacity: 1 |
| 71 | + ``` |
| 72 | +
|
| 73 | +1. To apply the configuration, run the following command: |
| 74 | +
|
| 75 | + ```bash |
| 76 | + kubectl apply -f opcua-configuration.yaml -n azure-iot-operations |
| 77 | + ``` |
| 78 | +
|
| 79 | +> [!TIP] |
| 80 | +> In a default Azure IoT Operations deployment, the OPC UA discovery handler is already configured to discover the simulated PLC server. If you want to discover assets connected to additional OPC UA servers, you can add them to the configuration file. |
| 81 | +
|
| 82 | +## Verify the configuration |
| 83 | +
|
| 84 | +To confirm that the asset discovery container is configured and running: |
| 85 | +
|
| 86 | +1. Use the following command to check the pod logs: |
| 87 | +
|
| 88 | + ```bash |
| 89 | + kubectl logs <insert aio-opc-asset-discovery pod name> -n azure-iot-operations |
| 90 | + ``` |
| 91 | +
|
| 92 | + A log from the `aio-opc-asset-discovery` pod indicates after a few seconds that the discovery handler registered itself with the Akri services: |
| 93 | +
|
| 94 | + ```2024-08-01T15:04:12.874Z aio-opc-asset-discovery-4nsgs - Akri OPC UA Asset Discovery (1.0.0-preview-20240708+702c5cafeca2ea49fec3fb4dc6645dd0d89016ee) is starting with the process id: 1 |
| 95 | + 2024-08-01T15:04:12.948Z aio-opc-asset-discovery-4nsgs - OPC UA SDK 1.5.374.70 from 07/20/2024 07:37:16 |
| 96 | + 2024-08-01T15:04:12.973Z aio-opc-asset-discovery-4nsgs - OPC UA SDK informational version: 1.5.374.70+1ee3beb87993019de4968597d17cb54d5a4dc3c8 |
| 97 | + 2024-08-01T15:04:12.976Z aio-opc-asset-discovery-4nsgs - Akri agent registration enabled: True |
| 98 | + 2024-08-01T15:04:13.475Z aio-opc-asset-discovery-4nsgs - Hosting starting |
| 99 | + 2024-08-01T15:04:13.547Z aio-opc-asset-discovery-4nsgs - Overriding HTTP_PORTS '8080' and HTTPS_PORTS ''. Binding to values defined by URLS instead 'http://+:8080'. |
| 100 | + 2024-08-01T15:04:13.774Z aio-opc-asset-discovery-4nsgs - Now listening on: http://:8080 |
| 101 | + 2024-08-01T15:04:13.774Z aio-opc-asset-discovery-4nsgs - Application started. Press Ctrl+C to shut down. |
| 102 | + 2024-08-01T15:04:13.774Z aio-opc-asset-discovery-4nsgs - Hosting environment: Production |
| 103 | + 2024-08-01T15:04:13.774Z aio-opc-asset-discovery-4nsgs - Content root path: /app |
| 104 | + 2024-08-01T15:04:13.774Z aio-opc-asset-discovery-4nsgs - Hosting started |
| 105 | + 2024-08-01T15:04:13.881Z aio-opc-asset-discovery-4nsgs - Registering with Agent as HTTP endpoint using own IP from the environment variable POD_IP: 10.42.0.245 |
| 106 | + 2024-08-01T15:04:14.875Z aio-opc-asset-discovery-4nsgs - Registered with the Akri agent with name opcua-asset for http://10.42.0.245:8080 with type Network and shared True |
| 107 | + 2024-08-01T15:04:14.877Z aio-opc-asset-discovery-4nsgs - Successfully re-registered OPC UA Asset Discovery Handler with the Akri agent |
| 108 | + 2024-08-01T15:04:14.877Z aio-opc-asset-discovery-4nsgs - Press CTRL+C to exit |
| 109 | + ``` |
| 110 | +
|
| 111 | + After about a minute, the Akri services issue the first discovery request based on the configuration: |
| 112 | +
|
| 113 | + ```output |
| 114 | + 2024-08-01T15:04:15.280Z aio-opc-asset-discovery-4nsgs [opcuabroker@311 SpanId:6d3db9751eebfadc, TraceId:e5594cbaf3993749e92b45c88c493377, ParentId:0000000000000000 ConnectionId:0HN5I7CQJPJL0 RequestPath:/v0.DiscoveryHandler/Discover RequestId:0HN5I7CQJPJL0:00000001] - Reading message. |
| 115 | + 2024-08-01T15:04:15.477Z aio-opc-asset-discovery-4nsgs [opcuabroker@311 SpanId:6d3db9751eebfadc, TraceId:e5594cbaf3993749e92b45c88c493377, ParentId:0000000000000000 ConnectionId:0HN5I7CQJPJL0 RequestPath:/v0.DiscoveryHandler/Discover RequestId:0HN5I7CQJPJL0:00000001] - Received discovery request from ipv6:[::ffff:10.42.0.241]:48638 |
| 116 | + 2024-08-01T15:04:15.875Z aio-opc-asset-discovery-4nsgs [opcuabroker@311 SpanId:6d3db9751eebfadc, TraceId:e5594cbaf3993749e92b45c88c493377, ParentId:0000000000000000 ConnectionId:0HN5I7CQJPJL0 RequestPath:/v0.DiscoveryHandler/Discover RequestId:0HN5I7CQJPJL0:00000001] - Start asset discovery |
| 117 | + 2024-08-01T15:04:15.882Z aio-opc-asset-discovery-4nsgs [opcuabroker@311 SpanId:6d3db9751eebfadc, TraceId:e5594cbaf3993749e92b45c88c493377, ParentId:0000000000000000 ConnectionId:0HN5I7CQJPJL0 RequestPath:/v0.DiscoveryHandler/Discover RequestId:0HN5I7CQJPJL0:00000001] - Discovering OPC UA opc.tcp://opcplc-000000:50000 using Asset Discovery |
| 118 | + 2024-08-01T15:04:15.882Z aio-opc-asset-discovery-4nsgs [opcuabroker@311 SpanId:6d3db9751eebfadc, TraceId:e5594cbaf3993749e92b45c88c493377, ParentId:0000000000000000 ConnectionId:0HN5I7CQJPJL0 RequestPath:/v0.DiscoveryHandler/Discover RequestId:0HN5I7CQJPJL0:00000001] - Selected AutoAcceptUntrustedCertificates mode: False |
| 119 | + ``` |
| 120 | +
|
| 121 | + After the discovery is complete, the discovery handler sends the result back to the Akri services to create an Akri instance custom resource with asset information and observable variables. The discovery handler repeats the discovery every 10 minutes to detect any changes on the server. |
| 122 | +
|
| 123 | +1. To view the discovered Akri instances, run the following command: |
| 124 | +
|
| 125 | + ```bash |
| 126 | + kubectl get akrii -n azure-iot-operations |
| 127 | + ``` |
| 128 | +
|
| 129 | + The output from the previous command looks like the following example. You might need to wait for a few seconds for the Akri instance to be created: |
| 130 | +
|
| 131 | + ```output |
| 132 | + NAME CONFIG SHARED NODES AGE |
| 133 | + akri-opcua-asset-dbdef0 akri-opcua-asset true ["k3d-k3s-default-server-0"] 24h |
| 134 | + ``` |
| 135 | +
|
| 136 | + The connector for OPC UA supervisor watches for new Akri instance custom resources of type `opc-ua-asset`, and generates the initial asset types and asset custom resources for them. You can modify asset custom resources by adding settings such as extended publishing for more data points, or connector for OPC UA observability settings. |
| 137 | +
|
| 138 | +1. To confirm that the Akri instance properly connected to the connector for OPC UA, run the following command. Replace the placeholder with the name of the Akri instance that was included in the output of the previous command: |
| 139 | +
|
| 140 | + ```bash |
| 141 | + kubectl get akrii <AKRI_INSTANCE_NAME> -n azure-iot-operations -o json |
| 142 | + ``` |
| 143 | +
|
| 144 | + The command output includes a section that looks like the following example. The snippet shows the Akri instance `brokerProperties` values and confirms that the connector for OPC UA is connected. |
| 145 | +
|
| 146 | + ```json |
| 147 | + "spec": { |
| 148 | + |
| 149 | + "brokerProperties": { |
| 150 | + "ApplicationUri": "Boiler #2", |
| 151 | + "AssetEndpointProfile": "{\"spec\":{\"uuid\":\"opc-ua-broker-opcplc-000000-azure-iot-operation\"…… |
| 152 | + ``` |
0 commit comments