Defining your device - 定义设备

原创
2022/04/16 14:56
阅读数 127

目录:https://my.oschina.net/zgldh/blog/5514606
原文:https://docs.edgexfoundry.org/2.1/walk-through/Ch-WalkthroughDeviceProfile/

Defining your device - 定义设备

A device profile can be thought of as a template or as a type or classification of device. General characteristics about the type of device, the data theses devices provide, and how to command them is all provided in a device profile. Other pages within this document set provide more details about a device profile and its purpose (see core metadata to start). It is typical that as part of the reference information setup sequence, the device service provides the device profiles for the types of devices it manages.
设备配置档案可以被看作一个模板,一种关于设备的类型或分类。设备基本的定义如类型、能提供的数据、能接受的命令都会描述在设备配置档案中。想查看关于设备配置档案的细节和用途请参考 core metadata。设备服务会为其管理的各个设备准备好设备配置档案,这个步骤通常作为引用信息配置序列的一部分。

Device Profile 设备配置档案

See core metadata API for more details.
详情请看 core metadata API

Our fictitious device service will manage only the human/dog counting camera, so it only needs to make one POST request to create the monitoring camera device profile. Since device profiles are often represented in YAML, you make a multi-part form-data POST with the device profile file (find the example profile here) to create the Camera Monitor profile.
我们的虚拟设备服务只需管理人和狗的计数摄像机,所以只需要调用一个POST请求来创建摄像机的设备配置档案。由于设备配置档案通常以 YAML 格式编写,这个创建摄像机设备配置档案的POST请求需要以 multi-part form-data 的格式传输。

If you explore the sample profile, you will see that the profile begins with some general information.
看了这个样例文件,你会发现配置文件通常以如下信息开头。

  name: "camera-monitor-profile"
  manufacturer: "IOTech"
  model: "Cam12345"
  labels: 
  - "camera"
  description: "Human and canine camera monitor profile"

Each profile has a unique name along with a description, manufacturer, model and collection of labels to assist in queries for particular profiles. These are relatively straightforward attributes of a profile.
每个设备配置档案都有个独一无二的名字,此外还有描述、制造商、型号以及用于辅助查询的标签列表。以上是设备配置档案里相对直白易懂的属性。

EdgeX 2.0
As of Ireland/V2, device profile names may only contain unreserved characters which are ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_~

在 Ireland/V2 版本,设备配置档案的名字name不能使用保留字,且只包含如下字符 ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_~

Resources and Commands 资源和命令

The device profile defines how to communicate with any device that abides by the profile. In particular, it defines the deviceResources and deviceCommands used to send requests to the device (via the device service). See the Device Profile documentation for more background on each of these.
在设备配置档案里,定义了如何与符合该配置档案的任何设备进行通信的方式。具体来说,它定义了用于向设备发送请求的设备资源 deviceResources设备命令 deviceCommands(通过设备服务进行发送)。关于上述两点的背景细节请参看设备配置档案文档。

Understanding Device Resources 理解设备资源

The device profile describes the elements of data that can be obtained from the device or sensor and how to change a setting on a device or sensor. The data that can be obtained or the setting that can be changed are called resources or more precisely they are referred to as device resources in Edgex. Learn more about deviceReources in the Device Profile documentation.
在设备配置档案里,描述了可以从设备获取的数据元素,以及如何修改设备的配置项。这些可以获取的数据以及可以修改的配置称之为资源 resources,在 EdgeX 体系中更准确的说是设备资源。查看设备配置档案文档来学习更多关于设备资源 deviceResources的知识。

In this walkthrough example, there are two pieces of data we want to be able to get or read from the camera: dog and human counts. Therefore, both are represented as device resources in the device profile. Additionally, we want to be able to set two settings on the camera: the scan depth and snapshot duration. These are also represented as device resources in the device profile.
在这个演练示例中,我们希望能够从摄像机中获取两条数据:狗的数量、人的数量。因此,两者都表示为设备配置文件中的设备资源。此外,我们希望能够在相机上做两个设置:扫描深度和拍照间隔时间。它们也会表示为设备配置档案中的设备资源。

  deviceResources:
  -
    name: "HumanCount"
    isHidden: false  #is hidden is false by default so this is just making it explicit for purpose of the walkthrough demonstration
    description: "Number of people on camera"
    properties:
      valueType:  "Int16"
      readWrite: "R"  #designates that this property can only be read and not set
      defaultValue: "0"
  -
    name: "CanineCount"
    isHidden: false
    description: "Number of dogs on camera"
    properties:
      valueType:  "Int16"
      readWrite: "R"  #designates that this property can only be read and not set
      defaultValue: "0"
  -
    name: "ScanDepth"
    isHidden: false
    description: "Get/set the scan depth"
    properties:
      valueType:  "Int16"
      readWrite: "RW"  #designates that this property can be read or set
      defaultValue: "0"

  -
    name: "SnapshotDuration"
    isHidden: false
    description: "Get the snaphot duration"
    properties:
      valueType:  "Int16"
      readWrite: "RW"  #designates that this property can be read or set
      defaultValue: "0"

Understanding Device Commands 理解设备命令

Command or more precisely device commands specify access to reads and writes for multiple simultaneous device resources. In other words, device commands allow you to ask for multiple pieces of data from a sensor at one time (or set multiple settings at one time). In this example, we can request both human and dog counts in one request by establishing a device command that specifies the request for both. Get more details on deviceCommands in the Device Profile documentation.
命令,更准确来说是设备命令,用于同时对多个设备资源进行读取和写入。换句话说,设备命令允许你从一个设备同时获取多种数据(或者同时设置多种配置)。在此示例中,我们建立了请求来执行设备命令,从而实现在一个请求中同时得到人类和狗的数量。请参考设备配置档案文档以获取有关 设备命令 deviceCommands 的更多详细信息。

  deviceCommands:
  -
    name: "Counts"
    readWrite: "R"
    isHidden: false
    resourceOperations:
    - { deviceResource: "HumanCount" }
    - { deviceResource: "CanineCount" }

EdgeX 2.0
As of the Ireland release, device commands are automatically created by EdgeX for any device resource that are not specified as hidden (that is where isHidden is set to false or is simply left off the device resource) in the profile. Therefore, you would not define a device command to provide access to a single device resource unless you need to restrict the read/write access to that device resource.
从 Ireland 版本开始,EdgeX会自动的为非隐藏的设备资源创建对应的设备命令(即 isHidden 为 false 或没有定义)。因此,您不必专门定义一个设备命令来提供对单个设备资源的访问,除非您需要限制对该设备资源的读/写访问。

Walkthrough - Device Profile 演练 - 设备配置档案

Use either the Postman or Curl tab below to walkthrough uploading the device profile.
使用 Postman 或者 Curl 来演练上传一个设备配置档案。

Download the Device Profile 下载设备配置档案

Click on the link below to download and save the device profile (YAML) to your system.
点击下方链接来下载要用到的设备配置档案。(译者注:真正做项目时就得自己写配置档案了)

EdgeX_CameraMonitorProfile.yml

Note 注意
Device profiles are stored in core metadata. Therefore, note that the calls in the walkthrough are to the metadata service, which defaults to port 59881.
设备配置档案存储在核心元数据中。因此在演练中都是对元数据服务发起调用,默认端口是 59881。

Upload the Device Profile to EdgeX 上传设备配置档案到 EdgeX

Postman
Make a POST request to http://localhost:59881/api/v2/deviceprofile/uploadfile. The request should not include any additional headers (leave the defaults). In the Body, make sure "form-data" is selected and set the Key to file and then select the device profile file where you saved it (as shown below).
发起一个POST请求到 http://localhost:59881/api/v2/deviceprofile/uploadfile。该请求不应包含任何额外的headers(保持默认)。Body使用“form-data”格式,key设置为file然后选择刚才下载的设备配置档案文件(如下图)。

If your API call is successful, you will get a generated id for your new DeviceProfile in the response area.
如果API调用成功,你会看到返回值里有生成的ID。这是你刚创建的设备配置档案的ID。

Curl
Make a curl POST request as shown below.
使用如下命令,发起一个 Curl 的 POST 请求。

url -X POST -F 'file=@/path/to/your/profile/here/EdgeX_CameraMonitorProfile.yml' http://localhost:59881/api/v2/deviceprofile/uploadfile

If your API call is successful, you will get a generated id for your new DeviceProfile in the response area.
如果API调用成功,你会看到返回值里有生成的ID。这是你刚创建的设备配置档案的ID。

! Warning 警告
Note that the file location in the curl command above needs to be replaced with your actual file location path. Also, if you do not save the device profile file to EdgeX_CameraMonitorProfile.yml, then you will need to replace the file name as well.
请注意将上面 Curl 样例的文件位置修改为你真实的本地文件路径。如果文件名不是EdgeX_CameraMonitorProfile.yml,也请修改为你本地的文件名。

Test the GET API 测试 GET API

If you make a GET call to the http://localhost:59881/api/v2/deviceprofile/all URL (with Postman or curl) you will get a listing (in JSON) of all the device profiles (and all of its associated deviceResource and deviceCommand) currently defined in your instance of EdgeX, including the one you just added.
如果你用Postman或Curl发起一个 GET 请求到http://localhost:59881/api/v2/deviceprofile/all,你会得到一个JSON数组,列出了当前在EdgeX实例中定义的所有设备配置档案(和其关联的设备资源 deviceResource设备命令 deviceCommand),当然也包含你刚才创建的那一个。

上一篇:Example Use Case - 案例
下一篇:Register your device service - 注册设备服务

展开阅读全文
加载中
点击引领话题📣 发布并加入讨论🔥
0 评论
0 收藏
0
分享
返回顶部
顶部