目录:https://my.oschina.net/zgldh/blog/5514606
原文:https://docs.edgexfoundry.org/2.1/walk-through/Ch-WalkthroughProvision/
Provision a device 配置设备
In the last act of setup, a device service often discovers and provisions devices (either statically or dynamically) and that it is going to manage on the part of EdgeX. Note the word "often" in the last sentence. Not all device services will discover new devices or provision them right away. Depending on the type of device and how the devices communicate, it is up to the device service to determine how/when to provision a device. In some cases, the provisioning may be triggered by a human request of the device service once everything is in place and once the human can provide the information the device service needs to physically connected to the device.
在配置的最后步骤,通常是由设备服务(以动态或静态方式)发现和配置设备,并且该过程由 EdgeX 进行管理。注意上面说的是“通常”。并非所有设备服务都会立即发现或配置好新设备。根据设备的类型和通信方式,设备服务会决定如何以及何时配置设备。在某些情况下,只要物理连接和各项所需信息准备就绪,也可以由人工手动的发起请求,执行设备配置。
Device 设备
See core metadata API for more details.
查看 核心元数据API 获得更多信息。
For the sake of this demonstration, the call to core metadata will provision the human/dog counting monitor camera as if the device service discovered it (by some unknown means) and provisioned the device as part of some startup process. To create a Device
, it must be associated to a DeviceProfile
, a DeviceService
, and contain one or more Protocols
that define how and where to communicate with the device (possibly providing its address).
出于演示目的,我们将手工对核心元数据服务发起调用,来配置一个人/狗计数监控摄像头,就好像在系统启动过程中,由设备服务(通过某种未知方式)发现该设备一样。要创建一个设备 Device
,则该设备必须与某个 设备配置档案 DeviceProfile
、设备服务 DeviceService
相关联,并包含一个或多个协议,这些协议定义了与设备通信的方式和位置(游客能是个网络地址)。
When creating a device, you specify both the admin state (just as you did for a device service) and an operating state. The operating state (aka op state) provides an indication on the part of EdgeX about the internal operating status of the device. The operating state is not set externally (as by another system or man), it is a signal from within EdgeX (and potentially the device service itself) about the condition of the device. The operating state of the device may be either UP
or DOWN
(it may alsy be UNKNOWN
if the state cannot be determined). When the operating state of the device is DOWN
, it is either experiencing some difficulty or going through some process (for example an upgrade) which does not allow it to function in its normal capacity.
创建设备时,您需要指定其管理状态(就像您为设备服务所做的那样)和操作状态。操作状态(op state)是该设备内部操作状态在EdgeX体系内的表示。操作状态不是由外部设置的(比如另一个系统或管理员),它是来自 EdgeX 内部(可能是设备服务本身)的关于设备状况的信号。设备的操作状态可以是UP
或DOWN
(如果情况未知,则可能是UNKNOWN
)。当设备的运行状态为 DOWN
时,该设备要么出了问题,要么正处于某种无法正常运行的过程(例如正在升级)。
Walkthrough - Device 演练 - 设备
Use either the Postman or Curl tab below to walkthrough creating the Device.
使用 Postman 或 Curl 来演练创建设备的过程。
Postman
Make a POST request to http://localhost:59881/api/v2/device with the following body:
发起一个POST请求到 http://localhost:59881/api/v2/device 请求体如下:[ { "apiVersion": "v2", "device": { "name": "countcamera1", "description": "human and dog counting camera #1", "adminState": "UNLOCKED", "operatingState": "UP", "labels": [ "camera","counter" ], "location": "{lat:45.45,long:47.80}", "serviceName": "camera-control-device-service", "profileName": "camera-monitor-profile", "protocols": { "camera-protocol": { "camera-address": "localhost", "port": "1234", "unitID": "1" } }, "notify": false } } ]
Be sure that you are POSTing raw data, not form-encoded data. If your API call is successful, you will get a generated ID for your new Device in the response area.
请确保你发送的请求体是 raw 格式,不要用 form-encoded 格式。如果API调用成功,你会看到返回值里有生成的ID。这是你刚创建的设备 Device 的ID。
Curl
Make a curl POST request as shown below.
使用如下命令,发起一个 Curl 的 POST 请求。curl -X 'POST' 'http://localhost:59881/api/v2/device' -d '[{"apiVersion": "v2", "device": {"name": "countcamera1","description": "human and dog counting camera #1","adminState": "UNLOCKED","operatingState": "UP","labels": ["camera","counter"],"location": "{lat:45.45,long:47.80}","serviceName": "camera-control-device-service","profileName": "camera-monitor-profile","protocols": {"camera-protocol": {"camera-address": "localhost","port": "1234","unitID": "1"}},"notify": false}}]'
If your API call is successful, you will get a generated ID (a UUID) for your new Device.
如果API调用成功,你会看到返回值里有生成的ID(一个 UUID)。这是你刚创建的设备 Device 的ID。
Note 提示
Thecamera-monitor-profile
was created by the device profile uploaded in a previous walkthrough step. Thecamera-control-device-service
was created in the last walkthough step. These names must match the previously created EdgeX objects in order to successfully provision your device.
camera-monitor-profile
就是之前我们创建的设备配置档案。camera-control-device-service
就是上一篇里创建的设备服务。这些名称必须与之前创建的 EdgeX 对象匹配,才能成功配置您的设备。
EdgeX 2.0
As of Ireland/V2, device names may only contain unreserved characters which are ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_~
从 Ireland/V2 版本开始,设备的名字不能使用保留字,且只包含如下字符 ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-~
Test the GET API 测试 GET API
Ensure the monitor camera is among the devices known to core metadata. If you make a GET call to the http://localhost:59881/api/v2/device/all
URL (with Postman or curl) you will get a listing (in JSON) of all the devices currently defined in your instance of EdgeX that should include the one you just added.
首先确保已经将摄像机添加进核心元数据服务。如果你用Postman或Curl发起一个 GET 请求到http://localhost:59881/api/v2/device/all
,你会得到一个JSON数组,列出了当前在EdgeX实例中定义的所有设备,应当也包含你刚才创建的那一个。
There are many additional APIs on core metadata to retrieve a DeviceProfile
, Device
, DeviceService
, etc. As an example, here is one to find all devices associated to a given DeviceProfile
.
核心元数据服务提供了很多 API 可用于检索 DeviceProfile
、Device
、DeviceService
的信息。例如,如下 API 是用于查找和某特定 DeviceProfile 关联的所有设备。
curl -X GET http://localhost:59881/api/v2/device/profile/name/camera-monitor-profile | json_pp
上一篇:Register your device service - 注册设备服务
下一篇:Calling commands - 调用设备命令