Asset Management Service – 层级 Asset 结构建模¶
以下示例说明了如何为 assets 的层级结构建模。在此示例中,创建了一个用于汽车工厂内的简单机械臂,并对其配备 IoT 2040 盒子。最终模型将包含 5 个层级结构:
- 代表租户的根 asset
- 代表工厂的站点 asset
- 代表装配区域的区域 asset
- 代表简单机械臂的设备 asset
- 代表 IoT 2040 盒子的代理 asset
创建站点 Asset¶
使用以下请求创建工厂 asset:
POST /assets
给出以下 JSON 结构来定义站点 asset:
{
"name":"MindCar",
"externalId":"SN 123456-123-123456",
"description":"Factory of MindCar",
"location": {
"country":"Austria",
"region":"Tyrol",
"locality":"Innsbruck",
"streetAddress":"Industriestraße 21 A/II",
"postalCode":"6020",
"longitude":53.5125546,
"latitude":9.9763411
},
"typeId": "core.basicsite",
"parentId": "{assetId}",
"timezone":"Europe/Berlin"
}
调用的响应结果包含新创建的 asset 实例,因此您可以验证创建是否正确:
{
"assetId": "{assetId}",
"tenantId": "{tenantName}",
"name":"MindCar",
"etag": {etagValue},
"externalId":"SN 123456-123-123456",
"t2Tenant":null,
"subTenant":null,
"description":"Factory of MindCar",
"timezone":"Europe/Berlin",
"parentId": "{parentAssetId}",
"typeId": "core.basicsite",
"location": {
"country":"Austria",
"region":"Tyrol",
"locality":"Innsbruck",
"streetAddress":"Industriestraße 21 A/II",
"postalCode":"6020",
"longitude":53.5125546,
"latitude":9.9763411
},
"fileAssignments": [],
"variables": [],
"aspects": [],
"locks": [],
"hierarchyPath": [
{
"assetId": "{rootAssetId}",
"name": "{tenantName}"
}
],
"deleted":null,
"_links": {
"self": {
"href": "{link}"
},
"aspects": {
"href": "{link}"
},
"variables": {
"href": "{link}"
},
"location": {
"href": "{link}"
},
"parent": {
"href": "{link}"
}
}
}
第 26 行到第 31 行包含直到根 asset 的层级路径,包括父 asset 的 ID 和名称:
"hierarchyPath": [
{
"assetId": "{rootAssetId}",
"name": "{tenantName}"
}
]
说明
返回的层级路径可能有所不同:租户用户可接收到租户根 asset 的完整路径,而子租户用户仅可接收到子租户根 asset 的路径。
创建区域 Asset¶
创建区域 asset 时可使用与之前相同的请求,但定义区域 asset 时应使用以下 JSON 结构:
{
"name":"AssemblyArea",
"externalId":"SN 123456-123-123456",
"description":"Assembly area of MindCar",
"location": {
"country":"Austria",
"region":"Tyrol",
"locality":"Innsbruck",
"streetAddress":"Industriestraße 21 A/II",
"postalCode":"6020",
"longitude":53.5125546,
"latitude":9.9763411
},
"typeId": "core.basicarea",
"parentId": "{assetId}",
"timezone":"Europe/Berlin"
}
调用的响应结果包含新创建的 asset 实例,因此您可以验证创建是否正确:
{
"assetId": "{assetId}",
"tenantId": "{tenantName}",
"name":"AssemblyArea",
"etag": {etagValue},
"externalId":"SN 123456-123-123456",
"t2Tenant":null,
"subTenant":null,
"description":"Assembly area of MindCar",
"timezone":"Europe/Berlin",
"parentId": "{parentId}",
"typeId": "core.basicarea",
"location": {
"country":"Austria",
"region":"Tyrol",
"locality":"Innsbruck",
"streetAddress":"Industriestraße 21 A/II",
"postalCode":"6020",
"longitude":53.5125546,
"latitude":9.9763411
},
"fileAssignments": [],
"variables": [],
"aspects": [],
"locks": [],
"hierarchyPath": [
{
"assetId": "{rootAssetId}",
"name": "{tenantName}"
},
{
"assetId": "{siteAssetId}",
"name":"MindCar"
}
],
"deleted":null,
"_links": {
"self": {
"href": "{link}"
},
"aspects": {
"href": "{link}"
},
"variables": {
"href": "{link}"
},
"location": {
"href": "{link}"
},
"parent": {
"href": "{link}"
}
}
}
第 26 行到第 35 行包含直到根 asset 的层级路径,在本例中,该层级路径由两个级别组成。层级路径始终自根 asset 开始,至直接父 asset 结束:
"hierarchyPath": [
{
"assetId": "{rootAssetId}",
"name": "{tenantName}"
},
{
"assetId": "{siteAssetId}",
"name":"MindCar"
}
]
创建设备 Asset¶
创建新 asset 前,必须首先定义所需的 aspect 类型和 asset type。在本示例中,设备是一个简单的机械臂,而要测量的 variable 是其旋转参数。
创建 Aspect 类型¶
使用以下请求创建用于旋转 variable 的 aspect 类型:
PUT /aspecttype/{id}
id
参数的输入如下:
{tenantName}.rotation
给出以下 JSON 结构来定义 aspect 类型:
{
"name": "rotation",
"category": "dynamic",
"scope": "private",
"description":"Rotation of the robotic arm",
"variables": [
{
"name": "rotation",
"dataType":"DOUBLE",
"unit": "degree",
"searchable":true
}
]
}
调用的响应结果包含新创建的 aspect 类型,因此您可以验证创建是否正确:
{
"id": "{tenantName}.rotation",
"tenantId": "{tenantName}",
"name": "rotation",
"category": "dynamic",
"scope": "private",
"description":"Rotation of the robotic arm",
"variables": [
{
"name": "rotation",
"unit": "degree",
"searchable":true,
"qualityCode":false,
"dataType":"DOUBLE",
"defaultValue":null,
"length":null
}
],
"etag": {etagValue},
"_links": {
"self": {
"href": "{link}"
}
}
}
创建 Asset Type¶
创建所需的 aspect 类型后,可使用以下请求创建机械臂的 asset type:
PUT /assecttype/{id}
id
参数的输入如下:
{tenantName}.roboticarm
给出以下 JSON 结构来定义 asset type:
{
"name": "roboticArm",
"description":"Robotic arm assembling cars",
"parentTypeId": "core.basicdevice",
"instantiable":true,
"scope": "private",
"aspects": [
{
"name": "rotation",
"aspectTypeId": "{tenantName}.rotation"
}
]
}
调用的响应结果包含新创建的 asset type 类型,因此您可以验证创建是否正确:
{
"parentTypeId": "core.basicdevice",
"instantiable":true,
"tenantId": "{tenantName}",
"name": "roboticArm",
"description":"Robotic arm assembling cars",
"scope": "private",
"variables": [],
"aspects": [
{
"name": "rotation",
"aspectType": {
"id": "{tenantName}.rotation",
"tenantId": "{tenantName}",
"name": "rotation",
"category": "dynamic",
"scope": "private",
"description":"Rotation of the robotic arm",
"variables": [
{
"name": "rotation",
"unit": "degree",
"searchable":true,
"qualityCode":false,
"defaultValue":null,
"dataType":"DOUBLE",
"length":null
}
],
"etag": {etagValue},
"_links": {
"self": {
"href": "{link}"
}
}
}
}
],
"fileAssignments": [],
"etag": {etagValue},
"_links": {
"self": {
"href": "{link}"
},
"parent": {
"href": "{link}"
}
},
"id": "{tenantName}.roboticarm"
}
创建 Asset¶
创建所需的 asset type 后,可使用以下请求创建机械臂的设备 asset:
POST /assets
给出以下 JSON 结构来定义设备 asset:
{
"name": "roboticarm",
"externalId":"SN 123456-123-123456",
"description":"Robotic arm assembling cars",
"typeId": "{tenantName}.roboticarm",
"parentId": "{assetId}",
"timezone":"Europe/Berlin"
}
调用的响应结果包含新创建的 asset 实例,因此您可以验证创建是否正确:
{
"assetId": "{assetId}",
"tenantId": "{tenantName}",
"name": "roboticarm",
"etag": {etagValue},
"externalId":"SN 123456-123-123456",
"t2Tenant":null,
"subTenant":null,
"description":"Robotic arm assembling cars",
"timezone":"Europe/Berlin",
"parentId": "{parentId}",
"typeId": "{tenantName}.roboticarm",
"location": {
"country":"Austria",
"region":"Tyrol",
"locality":"Innsbruck",
"streetAddress":"Industriestraße 21 A/II",
"postalCode":"6020",
"longitude":53.5125546,
"latitude":9.9763411
},
"fileAssignments": [],
"variables": [],
"aspects": [],
"locks": [],
"hierarchyPath": [
{
"assetId": "{rootAssetId}",
"name": "{tenantName}"
},
{
"assetId": "{assetId}",
"name":"MindCar"
},
{
"assetId": "{assetId}",
"name":"AssemblyArea"
}
],
"deleted":null,
"_links": {
"self": {
"href": "{link}"
},
"aspects": {
"href": "{link}"
},
"variables": {
"href": "{link}"
},
"location": {
"href": "{link}"
},
"parent": {
"href": "{link}"
}
}
}
第 26 行到第 35 行包含直到根 asset 的层级路径。层级路径显示直到根 asset 的所有父项,包括其 assetId
和 name
,该路径自根开始,至直接父项区域结束。
"hierarchyPath": [
{
"assetId": "{rootAssetId}",
"name": "{tenantName}"
},
{
"assetId": "{assetId}",
"name":"MindCar"
},
{
"assetId": "{assetId}",
"name":"AssemblyArea"
}
]
创建 IoT 2040 代理 Asset¶
最后,使用以下请求创建 IoT 2040 代理 asset:
POST /assets
给出以下 JSON 结构来定义代理 asset:
{
"name":"IoT2040",
"externalId":"SN 123456-123-123456",
"description":"IoT2040",
"typeId": "core.mciot2040",
"parentId": "{assetId}",
"timezone":"Europe/Berlin"
}
调用的响应结果包含新创建的 asset 实例,因此您可以验证创建是否正确:
{
"assetId": "{assetId}",
"tenantId": "{tenantValue}",
"name":"IoT2040",
"etag": {etagValue},
"externalId":"SN 123456-123-123456",
"t2Tenant":null,
"subTenant":null,
"description":"IoT2040",
"timezone":"Europe/Berlin",
"parentId": "{assetId}",
"typeId": "core.mciot2040",
"location": {
"country":"Austria",
"region":"Tyrol",
"locality":"Innsbruck",
"streetAddress":"Industriestraße 21 A/II",
"postalCode":"6020",
"longitude":53.5125546,
"latitude":9.9763411
},
"fileAssignments": [],
"variables": [],
"aspects": [],
"locks": [],
"hierarchyPath": [
{
"assetId": "{rootAssetId}",
"name": "{tenantName}"
},
{
"assetId": "{assetId}",
"name":"MindCar"
},
{
"assetId": "{assetId}",
"name":"AssemblyArea"
},
{
"assetId": "{assetId}",
"name": "roboticarm"
}
],
"deleted":null,
"_links": {
"self": {
"href": "{link}"
},
"aspects": {
"href": "{link}"
},
"variables": {
"href": "{link}"
},
"location": {
"href": "{link}"
},
"parent": {
"href": "{link}"
}
}
}
层级路径显示直到根 asset 的所有父项,包括 assetId 和名称,该路径自根开始,至直接父项机械臂结束。
"hierarchyPath": [
{
"assetId": "{rootAssetId}",
"name": "{tenantName}"
},
{
"assetId": "{assetId}",
"name":"MindCar"
},
{
"assetId": "{assetId}",
"name":"AssemblyArea"
},
{
"assetId": "{assetId}",
"name": "roboticarm"
}
]