OPC UA 服务器是与资产通信的软件应用程序。 OPC UA 服务器公开表示数据点的 OPC UA 数据点。 OPC UA 数据点提供有关资产状态、性能、质量或条件的实时或历史数据。
Azure IoT Operations 中的 资产 是用于表示物理资产或设备的逻辑实体。 Azure IoT Operations 资产可以具有描述其行为和特征的自定义属性、数据点、流和事件。 资产与一个或多个设备相关联。 Azure IoT Operations 将资产定义存储在 Azure 设备注册表中。
Azure IoT作中的 设备 是一个逻辑实体,用于定义与物理资产或设备的连接。 如果没有设备,数据无法从物理设备或资产流向 MQTT 中转站。 配置设备和资产时,将建立与物理资产或设备的连接,而数据点值、事件和流将到达 Azure IoT 操作实例。 设备具有一个或多个入站终结点。 Azure IoT作将设备定义存储在 Azure 设备注册表中。
本文介绍如何使用操作体验 Web UI 和 Azure CLI 执行以下操作:
- 定义将 OPC UA 服务器连接到你的 Azure IoT 操作实例的设备。
- 添加资产,并定义其数据点和事件,以启用从 OPC UA 服务器到 MQTT 代理的数据流。
这些资产、数据点和事件将入站数据从 OPC UA 服务器映射到可在 MQTT 代理和数据流中使用的易记名称。
连接器连接到 OPC UA 服务器时可以使用 anonymous 或 username password 身份验证。
先决条件
若要配置设备和资产,需要一个 Azure IoT 操作实例。
要登录到操作体验 Web UI,则需要至少具有包含 Kubernetes - Azure Arc 实例的资源组参与者权限的 Microsoft Entra ID 帐户。 无法使用 Microsoft 帐户 (MSA) 登录。 有关详细信息,请参阅 排查对操作 Web UI 界面的访问问题。
IT 管理员必须在 Azure 门户中为 Azure IoT作实例配置 OPC UA 连接器模板。
你可以从你的 Azure IoT 操作群集访问的一台 OPC UA 服务器。 如果没有 OPC UA 服务器,请使用 Azure IoT作示例存储库中的 OPC PLC 模拟器。
创建设备
Azure IoT 运营的部署可以包含一个示例 OPC PLC 模拟器。 若要创建使用 OPC PLC 模拟器的设备,请执行以下作:
选择“设备”,然后选择“创建设备”:
在“基本信息”页上,输入设备名称,然后在“Microsoft.OpcUa”磁贴上选择“新建”来为该设备添加终结点:
输入你的终结点信息。 例如,若要使用 OPC PLC 模拟器,请输入以下值:
| 字段 |
价值 |
| 名称 |
opc-ua-connector-0 |
| OPC UA 连接器 URL |
opc.tcp://opcplc-000000:50000 |
| 用户身份验证 |
Anonymous |
选择“下一步”,然后在“其他信息”页上输入设备的任何自定义属性。
选择“下一步”以查看设备详细信息。 然后选择 创建。
运行以下命令:
az iot ops ns device create -n opc-ua-connector-cli -g {your resource group name} --instance {your instance name}
az iot ops ns device endpoint inbound add opcua --device opc-ua-connector-cli -g {your resource group name} -i {your instance name} --name opc-ua-connector-0 --endpoint-address "opc.tcp://opcplc-000000:50000"
若要了解详细信息,请参阅 az iot ops ns device。
部署以下 Bicep 模板,为 OPC UA 连接器创建具有入口端点的设备。 分别将占位符 <AIO_NAMESPACE_NAME> 和 <CUSTOM_LOCATION_NAME> 替换为 Azure IoT 操作命名空间名称和自定义位置名称:
param aioNamespaceName string = '<AIO_NAMESPACE_NAME>'
param customLocationName string = '<CUSTOM_LOCATION_NAME>'
resource namespace 'Microsoft.DeviceRegistry/namespaces@2025-10-01' existing = {
name: aioNamespaceName
}
resource customLocation 'Microsoft.ExtendedLocation/customLocations@2021-08-31-preview' existing = {
name: customLocationName
}
resource device 'Microsoft.DeviceRegistry/namespaces/devices@2025-10-01' = {
name: 'opc-ua-connector'
parent: namespace
location: resourceGroup().location
extendedLocation: {
type: 'CustomLocation'
name: customLocation.id
}
properties: {
endpoints: {
outbound: {
assigned: {}
}
inbound: {
'opc-ua-connector-0': {
endpointType: 'Microsoft.OpcUa'
address: 'opc.tcp://opcplc-000000:50000'
authentication: {
method: 'Anonymous'
}
}
}
}
}
}
此配置将一个名为 device 的新 opc-ua-connector 资源部署到群集,并使用名为 opc-ua-connector-0 的入站终结点。
OPC PLC 模拟器运行时,数据从模拟器流向连接器,接着流向 OPC UA 连接器,然后流向 MQTT 代理。
上述示例使用了 Anonymous 身份验证模式。 此模式不需要用户名或密码。
若要使用 UsernamePassword 身份验证模式,请完成以下步骤:
按照 Azure IoT作部署的“管理机密 ”中的步骤,在 Azure Key Vault 中添加用户名和密码的机密,并将其投影到 Kubernetes 群集中。
使用带有 和 --user-ref 参数的 --pass-ref 命令,将引用添加到你创建的 Azure Key Vault 机密中。
按照 Azure IoT作部署的“管理机密 ”中的步骤,在 Azure Key Vault 中添加用户名和密码的机密,并将其投影到 Kubernetes 群集中。
修改连接器的 Bicep 配置块来引用用户名和密码的这些同步秘密,如以下示例所示:
authentication: {
method: 'UsernamePassword'
usernamePasswordCredentials: {
passwordSecretName: '<reference to synced password secret>'
usernameSecretName: '<reference to synced username secret>'
}
}
其他安全选项
若要管理 OPC UA 连接器的受信任证书列表,请参阅 管理用于外部通信的证书。
创建入站终结点时,还可以选择:
| 选项 |
类型 |
DESCRIPTION |
|
自动接受不受信任的服务器证书 |
Yes/No |
自动接受不受信任的服务器证书 |
|
安全策略 |
下拉列表 |
用于与 OPC UA 服务器建立安全通道的安全策略 |
|
安全模式 |
下拉列表 |
用于在安全通道中与 OPC UA 服务器通信的安全模式 |
添加资产、数据点和事件
若要在操作体验中添加资产,请执行以下步骤:
选择“资产”选项卡。在创建任何资产之前,会看到以下屏幕:
选择“ 创建资产”。
在资产详细信息屏幕上,输入以下资产信息:
- 入站终结点。 从列表中选择你的设备入站终结点。
- 资产名称
- DESCRIPTION
配置要与资产关联的自定义属性集。 可以接受默认的属性列表或添加自己的属性。 默认提供以下属性:
- 制造者
- 制造商 URI
- 型号
- 产品代码
- 硬件版本
- 软件版本
- 序列号
- 文档 URI
选择 “下一步 ”转到 “数据集 ”页。
将数据集添加到资产
数据集定义连接器将从数据点集合中收集的数据发送到的目的地。 OPC UA 资产可以有多个数据集。 创建数据集:
选择“ 创建数据集”。
输入数据集的详细信息,例如其名称和目标。 对于 OPC UA 资产,目标是 MQTT 主题。 例如:
使用 “开始”实例 字段指定用于解析数据集中数据点的相对浏览路径的起始节点。 有关详细信息,请参阅 使用浏览路径动态解析节点。
选择创建和下一步 创建数据集。
小窍门
使用 “管理默认设置” 选项配置默认数据集设置,例如发布间隔、采样间隔和队列大小。
向数据集添加单个数据点
重要
数据点名称 _ErrorMessage 是保留的,不应使用。
现在可以定义与数据集关联的数据点。 要添加 OPC UA 数据点,请执行以下步骤:
选择 “添加数据点”。
输入数据点详细信息:
- 数据源。 此值是 OPC UA 服务器中的节点 ID。
- 数据点名称(可选)。 此值是要用于该数据点的易记名称。 如果未指定数据点名称,则节点 ID 将用作数据点名称。
- 采样间隔(毫秒)。 可以替代此数据点的默认值。
- 队列大小。 可以替代此数据点的默认值。
下表显示了可用于内置 OPC PLC 模拟器的一些示例数据点值:
| 数据源 |
数据点名称 |
| ns=3;s=FastUInt10 |
温度 |
| ns=3;s=FastUInt100 |
湿度 |
注释
如果使用相对浏览路径解析动态节点, 则数据源 字段包含相对浏览路径。 有关详细信息,请参阅 使用浏览路径动态解析节点。
在 数据点 页上,选择 “下一步 ”转到 “添加事件 ”页。
使用以下命令使用 Azure CLI 将恒温器资产添加到设备。 这些命令使用 point add 命令向资产添加数据集和两个数据点:
# Create the asset
az iot ops ns asset opcua create --name thermostat --instance {your instance name} -g {your resource group name} --device opc-ua-connector --endpoint opc-ua-connector-0 --description 'A simulated thermostat asset'
# Add the dataset
az iot ops ns asset opcua dataset add --asset thermostat --instance {your instance name} -g {your resource group name} --name oven --data-source "ns=3;s=FastUInt10" --dest topic="azure-iot-operations/data/thermostat" retain=Keep qos=Qos1 ttl=3600
# Add the data points
az iot ops ns asset opcua datapoint add --asset thermostat --instance {your instance name} -g {your resource group name} --dataset oven --name temperature --data-source "ns=3;s=FastUInt10"
az iot ops ns asset opcua datapoint add --asset thermostat --instance {your instance name} -g {your resource group name} --dataset oven --name humidity --data-source "ns=3;s=FastUInt100"
# Show the dataset and datapoints
az iot ops ns asset opcua dataset show --asset thermostat -n default -g {your resource group name} --instance {your instance name}
使用 Azure CLI 创建资产时,可以定义:
- 多次使用
point add 命令创建多个数据点。
- 通过多次使用
--event 参数定义多个事件。
- 资产的可选信息,例如:
- 制造者
- 制造商 URI
- 型号
- 产品代码
- 硬件版本
- 软件版本
- 序列号
- 文档 URI
- 采样间隔、发布间隔和队列大小的默认值。
- 采样间隔、发布间隔和队列大小的数据点特定值。
- 采样发布间隔和队列大小的事件特定值。
- 每个数据点和事件的可观测性模式
部署以下 Bicep 模板,以创建一个资源,用于将前面显示的设备的消息发布到 MQTT 主题。 分别将占位符 <AIO_NAMESPACE_NAME> 和 <CUSTOM_LOCATION_NAME> 替换为 Azure IoT 操作命名空间名称和自定义位置名称:
param aioNamespaceName string = '<AIO_NAMESPACE_NAME>'
param customLocationName string = '<CUSTOM_LOCATION_NAME>'
resource namespace 'Microsoft.DeviceRegistry/namespaces@2025-10-01' existing = {
name: aioNamespaceName
}
resource customLocation 'Microsoft.ExtendedLocation/customLocations@2021-08-31-preview' existing = {
name: customLocationName
}
resource asset 'Microsoft.DeviceRegistry/namespaces/assets@2025-10-01' = {
name: 'thermostat'
parent: namespace
location: resourceGroup().location
extendedLocation: {
type: 'CustomLocation'
name: customLocation.id
}
properties: {
displayName: 'thermostat'
description: 'A simulated thermostat asset'
enabled: true
deviceRef: {
deviceName: 'opc-ua-connector'
endpointName: 'opc-ua-connector-0'
}
defaultDatasetsConfiguration: '{}'
defaultEventsConfiguration: '{}'
datasets: [
{
name: 'oven'
dataSource: 'ns=3;s=FastUInt10'
datasetConfiguration: '{}'
dataPoints: [
{
name: 'temperature'
dataSource: 'ns=3;s=FastUInt10'
dataPointConfiguration: '{}'
}
{
name: 'humidity'
dataSource: 'ns=3;s=FastUInt100'
dataPointConfiguration: '{}'
}
]
destinations: [
{
target: 'Mqtt'
configuration: {
topic: 'azure-iot-operations/data/thermostat'
qos: 'Qos1'
retain: 'Keep'
ttl: 3600
}
}
]
}
]
}
}
将单个事件添加到资产
现在可以定义与资产关联的事件。 若要在操作体验中添加 OPC UA 事件,请执行以下操作:
通过选择创建事件组来创建事件组。
选择“添加事件”。
输入事件详细信息:
- 事件通知器。 此值是 OPC UA 服务器中的事件通知程序。
- 事件名称(可选)。 此值是要用于该事件的易记名称。 如果不指定事件名称,事件通知程序将用作事件名称。
- 发布间隔(毫秒)。 可以替代此数据点的默认值。
- 采样间隔(毫秒)。 可以替代此数据点的默认值。
- 队列大小。 可以替代此数据点的默认值。
- 关键帧计数。 可以替代此数据点的默认值。
注释
若要动态解析节点 ID,请使用 “开始”实例 字段指定起始节点 ID,使用 数据源 字段指定相对浏览路径。 有关详细信息,请参阅 使用浏览路径动态解析节点。
选择“管理默认设置”以配置资产的默认事件设置。 这些设置适用于属于资产的所有 OPC UA 事件。 可以替代你添加的每个事件的这些设置。 默认事件设置包括:
-
发布间隔(毫秒):OPC UA 服务器发布数据时应采用的速率。
-
队列大小:在发布采样数据之前保留它们的队列深度。
事件筛选器
定义事件筛选器以自定义服务器事件通知中包含的信息。 默认情况下,服务器会在事件通知中发送一系列标准字段。 服务器确定每个事件类型的确切选择。 例如:
{
"EventId":"OkaXYhfr20yUoj1QBbzcIg==",
"EventType":"i=2130",
"SourceNode":"i=2253",
"SourceName":"WestTank",
"Time":"2025-10-10T15:09:13.3946878Z",
"ReceiveTime":"2025-10-10T15:09:13.3946881Z",
"Message":"Raising Events",
"Severity":500
}
使用事件筛选器可以:
- 在事件通知中包含其他字段。
- 从事件通知中排除字段。
- 修改事件通知中的字段名称。
以下屏幕截图显示了示例事件筛选器:
上一屏幕截图中显示的完整事件筛选器定义了四个输出字段:
| 浏览路径 |
类型定义 ID |
字段 ID |
EventId |
ns=0;i=2041 |
myEventId |
EventType |
ns=0;i=2041 |
空白 |
SourceName |
空白 |
mySourceName |
Severity |
空白 |
空白 |
筛选器行的三个属性为:
-
浏览路径。 必需值用于标识要在转发的事件通知中包含的源字段。
-
类型定义 ID。 指定源字段的 OPC UA 类型定义的可选值。
-
字段 ID。 可选值,该值指定要用于转发事件通知中的字段的名称。 如果未指定字段 ID,则使用原始字段名称。
连接器转发的结果消息现在如下所示:
{
"myEventId":"OkaXYhfr20yUoj1QBbzcIg==",
"EventType":"i=2130",
"mySourceName":"WestTank",
"Severity":500
}
查看所作更改
查看资产和 OPC UA 数据点和事件详细信息。 进行所需的任何调整:
更新资产
查找并选择之前创建的资产。 使用 “资产详细信息”、“ 数据点”和“ 事件 ”选项卡进行任何更改:
在数据集的 “视图数据点 ”选项卡上,可以添加数据点、更新现有数据点或删除数据点。
若要更新数据点,请选择现有数据点并更新数据点信息。 然后选择“更新”:
若要删除数据点,请选择一个或多个数据点,然后选择 “删除数据点”
此外,还可以通过相同的方式添加、更新和删除事件和属性。
完成更改后,选择“保存”以保存所做的更改。
若要列出与特定终结点关联的资产,请使用以下命令:
az iot ops ns asset query --device {your device name} --endpoint-name {your endpoint name}
小窍门
可优化查询命令来搜索符合特定条件的资产。 例如,可以按制造商搜索资产。
若要查看恒温器资产的详细信息,请使用以下命令:
az iot ops ns asset show --name thermostat --instance {your instance name} -g {your resource group}
若要更新资产,请使用 az iot ops ns asset opcua update 命令。 例如,若要更新资产的说明,请使用如下例所示的命令:
az iot ops ns asset opcua update --name thermostat --instance {your instance name} -g {your resource group} --description "Updated factory PLC"
若要列出数据集中的恒温器资产的数据点,请使用以下命令:
az iot ops ns asset opcua dataset show --asset thermostat --name default -g {your resource group} --instance {your instance name}
若要列出恒温器资产的事件,请使用以下命令:
az iot ops ns asset opcua event list --asset thermostat -g {your resource group} --instance {your instance name}
若要向恒温器资产添加新数据点,请使用如下例所示的命令:
az iot ops ns asset opcua dataset point add --asset thermostat --instance {your instance name} -g {your resource group name} --dataset default --name humidity --data-source "ns=3;s=FastUInt100"
若要删除数据点,请使用 az iot ops ns asset opcua dataset point remove 命令。
可以使用 az iot ops ns asset opcua event 命令管理资产的事件。
若要使用 Bicep 检索资产,请使用类似于以下示例的模板:
param aioNamespaceName string = '<AIO_NAMESPACE_NAME>'
resource namespace 'Microsoft.DeviceRegistry/namespaces@2025-10-01' existing = {
name: aioNamespaceName
}
resource asset 'Microsoft.DeviceRegistry/namespaces/assets@2025-10-01' existing = {
name: 'thermostat'
parent: aioNamespaceName
}
output asset object = asset
若要更新现有资产,例如修改说明并添加数据点,请使用如下所示的模板:
param aioNamespaceName string = '<AIO_NAMESPACE_NAME>'
param customLocationName string = '<CUSTOM_LOCATION_NAME>'
resource namespace 'Microsoft.DeviceRegistry/namespaces@2025-10-01' existing = {
name: aioNamespaceName
}
resource customLocation 'Microsoft.ExtendedLocation/customLocations@2021-08-31-preview' existing = {
name: customLocationName
}
resource asset 'Microsoft.DeviceRegistry/namespaces/assets@2025-10-01' = {
name: 'thermostat'
parent: namespace
location: resourceGroup().location
extendedLocation: {
type: 'CustomLocation'
name: customLocation.id
}
properties: {
displayName: 'thermostat'
description: 'Updated thermostat asset with voltage data point'
enabled: true
deviceRef: {
deviceName: 'opc-ua-connector'
endpointName: 'opc-ua-connector-0'
}
defaultDatasetsConfiguration: '{}'
defaultEventsConfiguration: '{}'
datasets: [
{
name: 'oven'
dataSource: 'ns=3;s=FastUInt10'
datasetConfiguration: '{}'
dataPoints: [
{
name: 'temperature'
dataSource: 'ns=3;s=FastUInt10'
dataPointConfiguration: '{}'
}
{
name: 'humidity'
dataSource: 'ns=3;s=FastUInt100'
dataPointConfiguration: '{}'
}
{
name: 'voltage'
dataSource: 'ns=3;s=FastUInt101'
dataPointConfiguration: '{}'
}
]
destinations: [
{
target: 'Mqtt'
configuration: {
topic: 'azure-iot-operations/data/thermostat'
qos: 'Qos1'
retain: 'Keep'
ttl: 3600
}
}
]
}
]
}
}
删除资产
若要删除资产,请选择要删除的资产。 在“资产”详细信息页上,选择“删除”。 确认所做的更改以删除资产:
若要删除资产,请使用如下例所示的命令:
az iot ops ns asset delete --name thermostat -g {your resource group name} --instance {your instance name}
若要使用 Bicep 删除单个资源,请参阅 部署堆栈。
相关内容