Azure Digital Twins入门 - 创建数字模型
分类: Azure物联网 ◆ 标签: #Azure # #Digitial Twin ◆ 发布于: 2023-06-15 20:17:49

之前的文章已经创建了Azure Digital Twins
的实例,并且也设置好了本地的环境、配置好了我们需要的工具,从现在开始我们需要一个的例子,帮助我们熟悉服务的功能和工具,学习如何将实体资产数字化的基本步骤,计划分成如下的步骤一步一步的深入学习:
- 确定数字化的目标清单
- 制作数字化模型
- 使用
Azure Digital Twins Explorer
工具来创建Digital Twin
、Relatioonship
关系映射,Twin Graph
- 使用
Azure Cli IoT
扩展来创建Digital Twin
,Relationship
关系映射,Twin Graph
- 使用
.Net SDK
来创建Digital Twin
,RelationShip
关系映射,Twin Graph
- 链接
Azure Digital Twins Explorer
到Azure IoT Hub
, 映射实际的IoT
设备 - 结合
Azure IoT Hub Device Provisioning Service
自动管理设备 - 结合
Event hub
和Azure Function
链接输出数据。
以上是我们的清单。
本节主要处理:
- 确定数字化的目标清单
- 制作数字化模型
确定数字化的目标清单
假设我们是一个水产养殖企业,它需要使用我们的服务进行数字化资产管理,该企业实体的资产假设如下:
- 该企业有多个厂区,每个厂区有若干个养殖池
- 每个养殖池里有如下一些探测器:
Ph
值测量器- 水温测量器
根据这个场景,我们需要如下的数字化目标:
- 厂区
- 养殖池
Ph
值测量器- 水温测量器
那么接下来我们需要对这个四个目标进行数字化模型的创建。
是时候启动您的Visual Studio Code
编辑器创建需要的数字模型了。
创建数字模型
我们已经有了需要数字化的清单了,那么我们接下来需要使用DTDL
创建一系列的模型。
厂区模型:
为了演示,我们假设厂区模型有如下的属性:
a. 名称: 例如养殖一厂,养殖二厂等等。
b. 城市: 例如,海南,荆州等等。
c. 编号: 例如: factory_id_1 等等。
d. 养殖种类: 例如龙虾,对虾等等。
e. 拥有几个养殖池等等。
拥有一个映射关系。养殖池模型:
有如下的属性:
a. 名称
b. 编号
c. 养殖种类
d. 养殖数量
一个关系。Ph
值测量器
有如下的属性:
a. 名称
b. 编号
一个遥测数据,Ph
值水温测量器
有如下属性:
a. 名称
b. 编号
一个遥测数据: 水温。
我们接下来启动编辑器,创建如下四个文件:
FactoryModel.json
PoolModel.json
PHValueSensor.json
TemperatorSensor.json
文件内容分别如下:
FactoryModel.json
:
{ "@context": "dtmi:dtdl:context;2", "@id": "dtmi:com:example:FactoryModel;1", "@type": "Interface", "displayName": "The Factory Model", "contents": [ { "@type": "Property", "name": "FactoryName", "schema": "string" }, { "@type": "Property", "name": "CityName", "schema": "string" }, { "@type": "Property", "name": "FactoryCode", "schema": "string" }, { "@type": "Property", "name": "MyCategory", "schema": "string" }, { "@type": "Property", "name": "PoolNumber", "schema": "integer" }, { "@type": "Relationship", "@id": "dtmi:com:example:Factory:rel_has_pools;1", "name": "rel_has_pools", "displayName": "Factory has Pools" } ] }
PoolModel.json
内容如下:
{ "@context": "dtmi:dtdl:context;2", "@id": "dtmi:com:example:PoolModel;1", "@type": "Interface", "displayName": "PoolModel", "contents": [ { "@type": "Property", "name": "PoolName", "schema": "string" }, { "@type": "Property", "name": "PoolCode", "schema": "string" }, { "@type": "Property", "name": "Category", "schema": "string" }, { "@type": "Property", "name": "TheNumber", "schema": "integer" }, { "@type": "Relationship", "@id": "dtmi:com:example:Pool:rel_has_Sensors;1", "name": "rel_has_sensors", "displayName": "Pool Has Sensors" } ] }
PHValueSensor.json
:
{ "@context": "dtmi:dtdl:context;2", "@id": "dtmi:com:example:PHValueSensor;1", "@type": "Interface", "displayName": "PHValueSensor", "contents": [ { "@type": "Telemetry", "name": "PHValue", "schema": "double" }, { "@type": "Property", "name": "PHValueSensorName", "schema": "string" }, { "@type": "Property", "name": "PHValueSensorCode", "schema": "string" } ] }
最后一个了:
TemperatorSensor.json
:
{ "@context": "dtmi:dtdl:context;2", "@id": "dtmi:com:example:TemperatorSensor;1", "@type": "Interface", "displayName": "TemperatorSensor", "contents": [ { "@type": "Telemetry", "name": "temperature", "schema": "double" }, { "@type": "Property", "name": "TemperatorSensorName", "schema": "string" }, { "@type": "Property", "name": "TemperatorSensorCode", "schema": "string" } ] }
请保存好上述四个文件,我们接下来需要使用这四个模型文件来定义我们的Digital Twin
以及关系映射了。