示例组件类型 - AWS IoT TwinMaker

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

示例组件类型

此主题包含的示例说明了如何实现组件类型的关键概念。

警报(抽象)

以下示例是 AWS IoT TwinMaker 控制台中显示的抽象警报组件类型。它包含一个由没有 implementedBy 值的 dataReader 组成的 functions 列表。

{ "componentTypeId": "com.example.alarm.basic:1", "workspaceId": "MyWorkspace", "description": "Abstract alarm component type", "functions": { "dataReader": { "isInherited": false } }, "isSingleton": false, "propertyDefinitions": { "alarm_key": { "dataType": { "type": "STRING" }, "isExternalId": true, "isRequiredInEntity": true, "isStoredExternally": false, "isTimeSeries": false }, "alarm_status": { "dataType": { "allowedValues": [ { "stringValue": "ACTIVE" }, { "stringValue": "SNOOZE_DISABLED" }, { "stringValue": "ACKNOWLEDGED" }, { "stringValue": "NORMAL" } ], "type": "STRING" }, "isRequiredInEntity": false, "isStoredExternally": true, "isTimeSeries": true } } }

备注:

componentTypeIdworkspaceID 的值为必需值。componentTypeId 的值对工作区必须是唯一性的。alarm_key 的值是函数可用于从外部来源检索警报数据的唯一标识符。密钥的值是必需的,并存储在中 AWS IoT TwinMaker。alarm_status 时间序列值存储在外部来源中。

更多示例参见 AWS IoT TwinMaker 示例

时间流遥测

以下示例是一个简单的组件类型,它从外部来源检索有关特定类型组件(例如警报或 Cookie 混合器)的遥测数据。它指定了组件类型继承的 Lambda 函数。

{ "componentTypeId": "com.example.timestream-telemetry", "workspaceId": "MyWorkspace", "functions": { "dataReader": { "implementedBy": { "lambda": { "arn": "lambdaArn" } } } }, "propertyDefinitions": { "telemetryType": { "dataType": { "type": "STRING" }, "isExternalId": false, "isStoredExternally": false, "isTimeSeries": false, "isRequiredInEntity": true }, "telemetryId": { "dataType": { "type": "STRING" }, "isExternalId": false, "isStoredExternally": false, "isTimeSeries": false, "isRequiredInEntity": true } } }

警报(继承自抽象警报)

以下示例继承自抽象警报和时间流遥测组件类型。它指定了自己的 Lambda 函数,用于检索警报数据。

{ "componentTypeId": "com.example.cookiefactory.alarm", "workspaceId": "MyWorkspace", "extendsFrom": [ "com.example.timestream-telemetry", "com.amazon.iottwinmaker.alarm.basic" ], "propertyDefinitions": { "telemetryType": { "defaultValue": { "stringValue": "Alarm" } } }, "functions": { "dataReader": { "implementedBy": { "lambda": { "arn": "lambdaArn" } } } } }
注意

由于警报连接器继承自抽象警报组件类型,因此 Lambda 函数必须返回 alarm_key 值。如果没有返回此值,Grafana 将无法将其识别为警报。这对于所有返回警报的组件都是必需的。

设备示例

本部分的示例说明如何对潜在的设备进行建模。可以使用这些示例来了解如何在自己的流程中对设备进行建模。

饼干搅拌机

以下示例继承自时间流遥测组件类型。它为饼干搅拌机的旋转速度和温度指定了额外的时间序列属性。

{ "componentTypeId": "com.example.cookiefactory.mixer", "workspaceId": "MyWorkspace", "extendsFrom": [ "com.example.timestream-telemetry" ], "propertyDefinitions": { "telemetryType": { "defaultValue" : { "stringValue": "Mixer" } }, "RPM": { "dataType": { "type": "DOUBLE" }, "isTimeSeries": true, "isStoredExternally": true }, "Temperature": { "dataType": { "type": "DOUBLE" }, "isTimeSeries": true, "isStoredExternally": true } } }

水箱

以下示例继承自时间流遥测组件类型。它为水箱的体积和流速指定了额外的时间序列属性。

{ "componentTypeId": "com.example.cookiefactory.watertank", "workspaceId": "MyWorkspace", "extendsFrom": [ "com.example.timestream-telemetry" ], "propertyDefinitions": { "telemetryType": { "defaultValue" : { "stringValue": "WaterTank" } }, "tankVolume1": { "dataType": { "type": "DOUBLE" }, "isTimeSeries": true, "isStoredExternally": true }, "tankVolume2": { "dataType": { "type": "DOUBLE" }, "isTimeSeries": true, "isStoredExternally": true }, "flowRate1": { "dataType": { "type": "DOUBLE" }, "isTimeSeries": true, "isStoredExternally": true }, "flowrate2": { "dataType": { "type": "DOUBLE" }, "isTimeSeries": true, "isStoredExternally": true } } }

空间位置

以下示例包含属性,其值存储在中 AWS IoT TwinMaker。由于这些值由用户指定并存储在内部,因此无需任何函数即可检索它们。该示例还使用 RELATIONSHIP 数据类型来指定与另一组件类型的关系。

该组件提供了一种用于向数字孪生添加上下文的轻量级机制。可以用它来添加指出某物所在位置的元数据。还可以在逻辑中使用这些信息,用于确定哪些摄像头可以看到设备或空间,或者用于知道如何派人到某个地点。

{ "componentTypeId": "com.example.cookiefactory.space", "workspaceId": "MyWorkspace", "propertyDefinitions": { "position": {"dataType": {"nestedType": {"type": "DOUBLE"},"type": "LIST"}}, "rotation": {"dataType": {"nestedType": {"type": "DOUBLE"},"type": "LIST"}}, "bounds": {"dataType": {"nestedType": {"type": "DOUBLE"},"type": "LIST"}}, "parent_space" : { "dataType": {"type": "RELATIONSHIP"}} } }