事物类型 - Amazon IoT Core
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)

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

事物类型

通过定义事物类型,您可以存储与同一事物类型相关联的所有事物共有的描述和配置信息,这将简化 Registry 中的事物管理。例如,您可以定义 LightBulb 事物类型。与该 LightBulb 事物类型相关的所有内容都共享一组属性:序列号、制造商和瓦数。在创建类型的事物 LightBulb (或将现有事物的类型更改为 LightBulb)时,可以为该 LightBulb 事物类型中定义的每个属性指定值。

虽然事物类型是可选项,但使用它们可以更容易地搜索事物。

  • 具有事物类型的事物最多可以具有 50 个属性。

  • 未设置事物类型的事物最多可以具有三个属性。

  • 一个事物只能与一种事物类型相关联。

  • 在账户中可以创建的事物类型数量不限。

事物类型是不可变的。事物类型一旦创建,便不可更改。您随时可以弃用某事物类型,以防止新事物与之关联。您也可以删除没有与任何事物关联的事物类型。

创建事物类型

您可以使用 CreateThingType 命令创建事物类型:

$ aws iot create-thing-type --thing-type-name "LightBulb" --thing-type-properties "thingTypeDescription=light bulb type, searchableAttributes=wattage,model"

CreateThingType 命令会返回一个含有事物类型及其 ARN 的响应:

{ "thingTypeName": "LightBulb", "thingTypeId": "df9c2d8c-894d-46a9-8192-9068d01b2886", "thingTypeArn": "arn:aws:iot:us-west-2:123456789012:thingtype/LightBulb" }

列出事物类型

您可以使用 ListThingTypes 命令列出事物类型:

$ aws iot list-thing-types

ListThingTypes命令会返回在您的:中定义的事物类型的列表 Amazon Web Services 账户:

{ "thingTypes": [ { "thingTypeName": "LightBulb", "thingTypeProperties": { "searchableAttributes": [ "wattage", "model" ], "thingTypeDescription": "light bulb type" }, "thingTypeMetadata": { "deprecated": false, "creationDate": 1468423800950 } } ] }

描述事物类型

您可以使用 DescribeThingType 命令获取某事物类型的相关信息:

$ aws iot describe-thing-type --thing-type-name "LightBulb"

DescribeThingType 命令返回有关指定类型的信息:

{ "thingTypeProperties": { "searchableAttributes": [ "model", "wattage" ], "thingTypeDescription": "light bulb type" }, "thingTypeId": "df9c2d8c-894d-46a9-8192-9068d01b2886", "thingTypeArn": "arn:aws:iot:us-west-2:123456789012:thingtype/LightBulb", "thingTypeName": "LightBulb", "thingTypeMetadata": { "deprecated": false, "creationDate": 1544466338.399 } }

将事物类型与事物相关联

创建事物时,可以使用 CreateThing 命令指定事物类型:

$ aws iot create-thing --thing-name "MyLightBulb" --thing-type-name "LightBulb" --attribute-payload "{\"attributes\": {\"wattage\":\"75\", \"model\":\"123\"}}"

您随时可以使用 UpdateThing 命令更改与某个事物关联的事物类型:

$ aws iot update-thing --thing-name "MyLightBulb" --thing-type-name "LightBulb" --attribute-payload "{\"attributes\": {\"wattage\":\"75\", \"model\":\"123\"}}"

您还可以使用 UpdateThing 命令取消事物与事物类型之间的关联。

弃用事物类型

事物类型是不可变的。一旦定义了事务类型,便不可更改。然而,您可以通过弃用某种事物类型来防止用户将新事物与之关联。所有与该事物类型相关联的现有事物将保持不变。

要弃用某事物类型,请使用 DeprecateThingType 命令:

$ aws iot deprecate-thing-type --thing-type-name "myThingType"

您可以使用 DescribeThingType 命令查看结果:

$ aws iot describe-thing-type --thing-type-name "StopLight":
{ "thingTypeName": "StopLight", "thingTypeProperties": { "searchableAttributes": [ "wattage", "numOfLights", "model" ], "thingTypeDescription": "traffic light type", }, "thingTypeMetadata": { "deprecated": true, "creationDate": 1468425854308, "deprecationDate": 1468446026349 } }

弃用事物类型是可逆操作。您可以通过在 --undo-deprecate CLI 命令中使用 DeprecateThingType 标志来撤消弃用:

$ aws iot deprecate-thing-type --thing-type-name "myThingType" --undo-deprecate

您可以使用 DescribeThingType CLI 命令查看结果:

$ aws iot describe-thing-type --thing-type-name "StopLight":
{ "thingTypeName": "StopLight", "thingTypeArn": "arn:aws:iot:us-east-1:123456789012:thingtype/StopLight", "thingTypeId": "12345678abcdefgh12345678ijklmnop12345678" "thingTypeProperties": { "searchableAttributes": [ "wattage", "numOfLights", "model" ], "thingTypeDescription": "traffic light type" }, "thingTypeMetadata": { "deprecated": false, "creationDate": 1468425854308, } }

删除事物类型

只有在弃用事物类型后,才能将其删除。要删除某事物类型,请使用 DeleteThingType 命令:

$ aws iot delete-thing-type --thing-type-name "StopLight"
注意

在删除绑定类型之前,请在弃用该类型后等待五分钟。