目录:https://my.oschina.net/zgldh/blog/5514606
原文:https://docs.edgexfoundry.org/2.1/walk-through/Ch-WalkthroughDeviceService/
Register your device service 注册设备服务
Our next task in this walkthrough is to have the device service register or define itself in EdgeX. That is, it can proclaim to EdgeX that "I have arrived and am functional."
在本演练中我们的下一个任务是让设备服务在 EdgeX 中注册或定义自身。也就是说,它(设备服务)可以向 EdgeX 宣布“我已经就位且可以正常工作了”。
Register with Core Configuration and Registration 核心配置和注册表
Part of that registration process of the device service, indeed any EdgeX micro service, is to register itself with the core configuration & registration. In this process, the micro service provides its location to the Config/Reg micro service and picks up any new/latest configuration information from this central service. Since there is no real device service in this walkthrough demonstration, this part of the inter-micro service exchange is not explored here.
设备服务(实际上是任何 EdgeX 微服务)注册的一个环节,需要将自身写入到核心配置和注册表中。在此过程中,微服务需将其访问位置提供给 Config/Reg 微服务,并从该中心服务中获取最新的配置信息。由于本次演练演示中没有真正的设备服务,微服务间信息交换的内容在此不做探讨。
Device Service 设备服务
See core metadata API for more details.
请参阅核心元数据API了解更多细节。
At this point in your walkthrough, the device service must create a representative instance of itself in core metadata. It is in this registration that the device service is given an address that allows core command or any EdgeX service to communicate with it.
在该演练目前阶段,设备服务必须在核心元数据服务中创建一个实例来表示其自身。这就是注册的用处,设备服务被赋予了一个地址,允许核心命令或任何 EdgeX 服务与该地址通信。
The name of the device service must be unique across all of EdgeX. When registering a device service, the initial admin state can be provided. The administrative state (aka admin state) provides control of the device service by man or other systems. It can be set to LOCKED
or UNLOCKED
. When a device service is set to LOCKED
, it is not suppose to respond to any command requests nor send data from the devices. See Admin State documentation for more details.
设备服务的名字必须在整个 EdgeX 是唯一的。当注册设备服务时可以定义初始的管理状态。管理状态(admin state)可以管控人工或其他系统对设备服务的控制能力。它可以被设置为 LOCKED
或 UNLOCKED
。当设备服务设置为 LOCKED
时,它(设备服务)不会响应任何命令请求,也不会从设备发送数据。有关更多详细信息,请参阅管理状态文档。
EdgeX 2.0
As of Ireland/V2, device service names may only contain unreserved characters which are ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-~
从 Ireland/V2 版本开始,设备服务的名字不能使用保留字,且只包含如下字符 ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-~
Walkthrough - Device Service 演练 - 设备服务
Use either the Postman or Curl tab below to walkthrough creating the DeviceService
.
使用 Postman 或 Curl 来尝试创建一个 设备服务 DeviceService
。
Postman
Make a POST request to http://localhost:59881/api/v2/deviceservice with the following body:
发起一个POST请求到 http://localhost:59881/api/v2/deviceservice 请求体如下:BODY: [ { "apiVersion": "v2", "service": { "name": "camera-control-device-service", "description": "Manage human and dog counting cameras", "adminState": "UNLOCKED", "labels": [ "camera", "counter" ], "baseAddress": "camera-device-service:59990" } } ]
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
DeviceService
in the response area.
请确保你发送的请求体是 raw 格式,不要用 form-encoded 格式。如果API调用成功,你会看到返回值里有生成的ID。这是你刚创建的设备服务 DeviceService
的ID。
Curl
Make a curl POST request as shown below.
使用如下命令,发起一个 Curl 的 POST 请求。curl -X 'POST' 'http://localhost:59881/api/v2/deviceservice' -d '[{"apiVersion": "v2","service": {"name": "camera-control-device-service","description": "Manage human and dog counting cameras", "adminState": "UNLOCKED", "labels": ["camera","counter"], "baseAddress": "camera-device-service:59990"}}]'
If your API call is successful, you will get a generated ID for your new
DeviceService
.
如果API调用成功,你会看到返回值里有生成的ID。这是你刚创建的设备服务 DeviceService
的ID。
Test the GET API 测试 GET API
If you make a GET call to the http://localhost:59881/api/v2/deviceservice/all URL (with Postman or curl) you will get a listing (in JSON) of all the device services currently defined in your instance of EdgeX, including the one you just added.
如果你用Postman或Curl发起一个 GET 请求到http://localhost:59881/api/v2/deviceservice/all ,你会得到一个JSON数组,列出了当前在EdgeX实例中定义的所有设备服务,当然也包含你刚才创建的那一个。
上一篇:Defining your device - 定义设备
下一篇:Provision a device - 生成一个设备