目录:https://my.oschina.net/zgldh/blog/5514606
原文:https://docs.edgexfoundry.org/2.1/walk-through/Ch-WalkthroughReading/
Sending events and reading data 发送事件然后读取数据
In the real world, the human/dog counting camera would start to take pictures, count beings, and send that data to EdgeX. To simulate this activity in this section of the walkthrough, you will make core data API calls as if you were the camera's device and device service. That is, you will report human and dog counts to core data in the form of event/reading objects.
在真是世界里,人狗计数摄像机开机后就会拍照、计数然后发送数据到 EdgeX。在此次的演练环节,你需要手工向核心数据 API 发送请求,来模拟摄像机和设备服务。也就是说,您将发送事件/读数的形式向核心数据服务报告人和狗的数量。
Send an Event/Reading 发送事件/读数
See core data API for more details.
参考 核心数据 API 来了解更多细节。
Data is submitted to core data as an Event
object. An event is a collection of sensor readings from a device (associated to a device by its name) at a particular point in time. A Reading
object in an Event
object is a particular value sensed by the device and associated to a Device Resource (by name) to provide context to the reading.
要发送给核心数据服务的设备数据叫做 事件 Event
对象。事件是在某一时间点从特定设备(可以通过设备名称指定)的传感器得到的读数的集合。事件 Event
对象中的 读数 Reading
对象是设备感知到的某个特定值,并与设备资源(可以通过资源的名称指定)相关联,以提供该读数的上下文(译者注:如单位等等)。
So, the human/dog counting camera might determine that there are 5 people and 3 dogs in the space it is monitoring. In the EdgeX vernacular, the device service upon receiving these sensed values from the camera device would create an Event
with two Reading
s - one Reading
would contain the key/value pair of HumanCount:5 and the other Reading
would contain the key/value pair of CanineCount:3.
所以,这个人狗计数摄像机可能识别到了该区域有五个人和三只狗。按 EdgeX 的体系来说,该设备服务从摄像头设备接收到这些感测值后,将创建一个包含了两个读数 Reading
的事件 Event
-一个读数 Reading
是键值对 HumanCount:5 另一个读数 Reading
是 CanineCount:3。
The device service, on creating the Event
and associated Reading
objects would transmit this information to core data via REST call.
设备服务创建的 事件 Event
和其关联的 读数 Reading
对象,会通过 REST 调用传输到核心数据服务里。
Walkthrough - Send Event 演练 - 发送事件 Event
Use either the Postman or Curl tab below to walkthrough sending an Event with Readings to core data.
使用 Postman 或 Curl 来演练向核心数据服务发送事件和读数。
Postman
Make a POST request tohttp://localhost:59880/api/v2/event/camera-monitor-profile/countcamera1/HumanCount
with the body below.
发起一个POST请求到http://localhost:59880/api/v2/event/camera-monitor-profile/countcamera1/HumanCount
请求体如下。{ "apiVersion": "v2", "event": { "apiVersion": "v2", "deviceName": "countcamera1", "profileName": "camera-monitor-profile", "sourceName": "HumanCount", "id": "d5471d59-2810-419a-8744-18eb8fa03465", "origin": 1602168089665565200, "readings": [ { "id": "7003cacc-0e00-4676-977c-4e58b9612abd", "origin": 1602168089665565200, "deviceName": "countcamera1", "resourceName": "HumanCount", "profileName": "camera-monitor-profile", "valueType": "Int16", "value": "5" }, { "id": "7003cacc-0e00-4676-977c-4e58b9612abe", "origin": 1602168089665565200, "deviceName": "countcamera1", "resourceName": "CanineCount", "profileName": "camera-monitor-profile", "valueType": "Int16", "value": "3" } ] } }
If your API call is successful, you will get a generated ID for your new Event as shown in the image below.
如果API调用成功,你会看到返回值里有生成的ID。这是你刚发送的事件的ID。
Curl
Make a curl POST request as shown below.
使用如下 Curl 命令,发起一个 POST 请求。```curl -X POST -d '{"apiVersion": "v2","event": {"apiVersion": "v2","deviceName": "countcamera1","profileName": "camera-monitor-profile","sourceName": "HumanCount","id":"d5471d59-2810-419a-8744-18eb8fa03464","origin": 1602168089665565200,"readings": [{"id": "7003cacc-0e00-4676-977c-4e58b9612abc","origin": 1602168089665565200,"deviceName": "countcamera1","resourceName": "HumanCount","profileName": "camera-monitor-profile","valueType": "Int16","value": "5"},{"id": "7003cacc-0e00-4676-977c-4e58b9612abf","origin":1602168089665565200,"deviceName": "countcamera1","resourceName": "CanineCount","profileName": "camera-monitor-profile","valueType": "Int16","value": "3"}]}}' localhost:59880/api/v2/event/camera-monitor-profile/countcamera1/HumanCount
Note 提示
Notice that the POST request URL contains the device profile name, the device name and the device resource (or device command) associated with the device that is providing the event.
请注意上方 POST 请求的 URL 。里面包含了与提供事件的设备关联的设备配置档案 Device Profile
的名称、设备名称 Device
和设备资源 Device Resource
(或设备命令)的名称。
Origin Timestamp 原始时间戳
The device service will supply an origin property in the Event
and Reading
object to suggest the time (in Epoch timestamp/milliseconds format) at which the data was sensed/collected.
设备服务将在 Event
和 Reading
对象中自动添加一个原始时间戳属性,作为本次感知/收集数据的时间戳(以 Epoch 时间戳/毫秒格式)。
Note 提示
Smart devices will often timestamp sensor data and this timestamp can be used as the origin timestamp. In cases where the sensor/device is unable to provide a timestamp ("dumb" or brownfield sensors), it is the device service that creates a timestamp for the sensor data that it be applied as the origin timestamp for the device.
智能设备通常都会对传感器数据加上时间戳,这可以作为原始时间戳。当某种设备无法提供时间戳时(比如老型号非智能设备),设备服务就可以生成一个原始时间戳作为传感器数据的时间戳。
Exploring Events/Readings 探索事件和读数
Now that an Event
and associated Readings
have been sent to core data, you can use the core data API to explore that data that is now stored in the database.
现在一个事件 Event
和关联的 读数 Readings
已经发送到核心数据服务了,你可以使用核心数据 API 来探索这些已经出存在数据库中的数据。
Recall from a previous walkthrough step, you checked that no data was yet stored in core data. Make a similar call to see event records have now been sent into core data..
回忆一下之前的步骤,您调用了核心数据服务,发现空空如也没有数据。现在再来试试类似的调用,看看事件记录有没有发送到核心数据服务里。
Walkthrough - Query Events/Readings 演练 - 查询事件和读数
Use either the Postman or Curl tab below to walkthrough getting the list of events.
使用 Postman 或 Curl 来演练得到事件列表。
Postman
Make a GET request to retrieve the Events associated to the countcamera1 device:http://localhost:59880/api/v2/event/device/name/countcamera1
.
发起一个GET请求到http://localhost:59880/api/v2/event/device/name/countcamera1
来获取 countcamera1 设备的事件。
Make a GET request to retrieve the Readings associated to the countcamera1 device:http://localhost:59880/api/v2/reading/device/name/countcamera1
.
发起一个GET请求到http://localhost:59880/api/v2/reading/device/name/countcamera1
来获取 countcamera1 设备的读数。
Curl
Make a curl GET requests to retrieve 10 of the lastEvents
associated to thecountcamera1
device and to retrieve 10 of the human count readings associated tocountcamera1
使用如下 Curl 命令,发起一个 GET 请求来获取设备countcamera1
的最后十条事件 Events
,然后获取该设备最后十条探测到多少人的读数。curl -X GET localhost:59880/api/v2/event/device/name/countcamera1 | json_pp curl -X GET localhost:59880/api/v2/reading/device/name/countcamera1 | json_pp
There are many additional APIs on core data to retrieve Event
and Reading
data. As an example, here is one to find all events inside of a start and end time range.
核心数据服务还提供了很多别的API来获取事件 Event
和读数 Reading
。举一个例子,如下请求可以查询到包含在开始和结束时间之内的所有事件。
curl -X GET localhost:59880/api/v2/event/start/1602168089665560000/end/1602168089665570000 | json_pp
上一篇:Calling commands - 调用设备命令
下一篇:Exporting your device data - 导出设备数据