gpt4 book ai didi

azure - 如何在 IoT 即插即用 DTDL 模型中设置设备孪生的所需属性和报告属性

转载 作者:行者123 更新时间:2023-12-03 06:34:16 25 4
gpt4 key购买 nike

我将此 dtdl 模型上传到 IoT 即插即用 v0.15.4.0 中的本地文件夹(之前版本的行为相同):

{
"@id": "dtmi:com:sergio:devkit;1",
"@type": "Interface",
"@context": [
"dtmi:dtdl:context;2"
],
"displayName": "Machine Part -v1",
"description": "Machine Part data",
"contents": [
{
"@type": "Property",
"name": "telemetryInterval",
"displayName": "telemetryInterval",
"description": "The time interval of this data",
"schema": "double",
"writable": true
},
{
"@type": "Property",
"name": "PartId",
"displayName": "PartId",
"description": "The unique id of the machine part",
"writable": true,
"schema": "string"
},

{
"@type": "Property",
"name": "Alert",
"displayName": "Alert",
"description": "whether or not this machine part needs maintenance",
"writable": true,
"schema": "boolean"
},
{
"@type": "Property",
"name": "ledState",
"displayName": "LED state",
"description": "Returns the current state of the onboard LED.",
"writable": true,
"schema": "boolean"
},
{
"@type": "Telemetry",
"name": "Description",
"schema": "string"
},
{
"@type": "Telemetry",
"name": "Code",
"schema": "integer"
},
{
"@type": "Telemetry",
"name": "Temperature",
"displayName": "Temperature",
"schema": "double"
},
{
"@type": "Telemetry",
"name": "Humidity",
"displayName": "Humidity",
"schema": "double"
},
{
"@type": "Telemetry",
"name": "pressure",
"displayName": "Pressure",
"schema": "double"
},
{
"@type": "Telemetry",
"name": "magnetometerX",
"displayName": "Magnetometer X / mgauss",
"schema": "double"
},
{
"@type": "Telemetry",
"name": "magnetometerY",
"displayName": "Magnetometer Y / mgauss",
"schema": "double"
},
{
"@type": "Telemetry",
"name": "magnetometerZ",
"displayName": "Magnetometer Z / mgauss",
"schema": "double"
},
{
"@type": "Telemetry",
"name": "accelerometerX",
"displayName": "Accelerometer X",
"schema": "double"
},
{
"@type": "Telemetry",
"name": "accelerometerY",
"displayName": "Accelerometer Y",
"schema": "double"
},
{
"@type": "Telemetry",
"name": "accelerometerZ",
"displayName": "Accelerometer Z",
"schema": "double"
},
{
"@type": "Telemetry",
"name": "gyroscopeX",
"displayName": "Gyroscope X",
"schema": "double"
},
{
"@type": "Telemetry",
"name": "gyroscopeY",
"displayName": "Gyroscope Y",
"schema": "double"
},
{
"@type": "Telemetry",
"name": "gyroscopeZ",
"displayName": "Gyroscope Z",
"schema": "double"
}
]

}

我的期望是,由于属性 ledState 和 Alert 属性是可写的,因此这些属性应该是报告的属性和所需的属性。但是,Azure 门户中的 IoT 中心设备(见下文)以不同方式显示它们,我不知道为什么。如何在上传到 IoT P&P 的 DTDL 模型中设置要报告或需要的属性?

{
"deviceId": "mymxchip",
"etag": "AAAAAAAAAAk=",
"deviceEtag": "NDU1NDk0NDM4",
"status": "enabled",
"statusUpdateTime": "0001-01-01T00:00:00Z",
"connectionState": "Connected",
"lastActivityTime": "2023-01-09T07:26:48.611708Z",
"cloudToDeviceMessageCount": 0,
"authenticationType": "sas",
"x509Thumbprint": {
"primaryThumbprint": null,
"secondaryThumbprint": null
},
"modelId": "dtmi:com:sergio:devkit;1",
"version": 164,
"properties": {
"desired": {
"telemetryInterval": 5,
"Alert": true,
"$metadata": {
"$lastUpdated": "2023-01-08T07:27:01.9659284Z",
"$lastUpdatedVersion": 9,
"telemetryInterval": {
"$lastUpdated": "2023-01-08T06:54:11.9502921Z",
"$lastUpdatedVersion": 8
},
"Alert": {
"$lastUpdated": "2023-01-08T07:27:01.9659284Z",
"$lastUpdatedVersion": 9
}
},
"$version": 9
},
"reported": {
"deviceInformation": {
"__t": "c",
"manufacturer": "MXCHIP",
"model": "AZ3166",
"swVersion": "1.0.0",
"osName": "Azure RTOS",
"processorArchitecture": "Arm Cortex M4",
"processorManufacturer": "STMicroelectronics",
"totalStorage": 1024,
"totalMemory": 128
},
"ledState": false,
"telemetryInterval": {
"ac": 200,
"av": 1,
"value": 5
},
"$metadata": {
"$lastUpdated": "2023-01-09T07:28:26.0068306Z",
"deviceInformation": {
"$lastUpdated": "2023-01-09T07:28:25.4599426Z",
"__t": {
"$lastUpdated": "2023-01-09T07:28:25.4599426Z"
},
"manufacturer": {
"$lastUpdated": "2023-01-09T07:28:25.4599426Z"
},
"model": {
"$lastUpdated": "2023-01-09T07:28:25.4599426Z"
},
"swVersion": {
"$lastUpdated": "2023-01-09T07:28:25.4599426Z"
},
"osName": {
"$lastUpdated": "2023-01-09T07:28:25.4599426Z"
},
"processorArchitecture": {
"$lastUpdated": "2023-01-09T07:28:25.4599426Z"
},
"processorManufacturer": {
"$lastUpdated": "2023-01-09T07:28:25.4599426Z"
},
"totalStorage": {
"$lastUpdated": "2023-01-09T07:28:25.4599426Z"
},
"totalMemory": {
"$lastUpdated": "2023-01-09T07:28:25.4599426Z"
}
},
"ledState": {
"$lastUpdated": "2023-01-09T07:28:25.7411971Z"
},
"telemetryInterval": {
"$lastUpdated": "2023-01-09T07:28:26.0068306Z",
"ac": {
"$lastUpdated": "2023-01-09T07:28:26.0068306Z"
},
"av": {
"$lastUpdated": "2023-01-09T07:28:26.0068306Z"
},
"value": {
"$lastUpdated": "2023-01-09T07:28:26.0068306Z"
}
}
},
"$version": 155
}
},
"capabilities": {
"iotEdge": false
}

}

最佳答案

您说得对,DTDL 可写属性将在设备孪生中同时显示为报告属性和所需属性。但是,这取决于设备的行为。

如果您使用服务 API 设置所需的属性,则会更新设备孪生中的所需属性值。然后,设备应在收到并处理所需属性时发送 Ack - 在上面的示例中,设备看起来好像已针对 telemetryInterval 属性执行了此操作。设备尚未确认警报所需的属性更新。

当设备发送报告的属性时,设备孪生将使用设备发送的值进行更新。在上面的示例中,设备已发送 deviceInformationledStatetelemetryInterval 报告属性。 telemetryInterval 是为了响应所需的属性而发送的。

您可以在此处找到更多详细信息:

以下恒温器设备示例均说明了如何遵循可写属性的 PnP 约定:

关于azure - 如何在 IoT 即插即用 DTDL 模型中设置设备孪生的所需属性和报告属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/75054283/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com