edgex启动设备服务,获取设备信息,控制设备等操作

[复制链接]
 楼主| keer_zu 发表于 2020-10-26 10:00 | 显示全部楼层 |阅读模式
开启设备服务
修改docker-compose.yml 文件,打开device-random 设备服务:
  1. #################################################################
  2. # Device Services
  3. #################################################################
  4. ......
  5.   device-random:
  6.     image: edgexfoundry/docker-device-random-go:1.0.0
  7.     ports:
  8.       - "49988:49988"
  9.     container_name: edgex-device-random
  10.     hostname: edgex-device-random
  11.     networks:
  12.       edgex-network:
  13.         aliases:
  14.             - edgex-device-random
  15.     volumes:
  16.       - db-data:/data/db
  17.       - log-data:/edgex/logs
  18.       - consul-config:/consul/config
  19.       - consul-data:/consul/data
  20.     depends_on:
  21.       - data
  22.       - command

重新启动服务:sudo docker-compose up -d



评论

[url=home.php?mod=space&uid=760242]@21ic小管家[/url] 干货,编辑推荐  发表于 2020-10-26 10:06
 楼主| keer_zu 发表于 2020-10-26 10:05 | 显示全部楼层
本帖最后由 keer_zu 于 2020-10-26 10:07 编辑

测试设备服务
device-random这个service包含Random-Boolean-Device、Random-Integer-Device、 Random-Integer-Generator01等多个设备


拿Random-Integer-Generator01为例:
获取该设备信息:

  1. GET http://192.168.138.128:48082/api/v1/device/name/Random-Integer-Generator01


我使用postman,运行在windows,这里的IP192.168.138.128是虚拟机的ip地址。


172985f962ed570fde.png


详细内容如下:

  1. {
  2.     "id": "09d43a05-aca0-42f2-a3e0-76360ae9d573",
  3.     "name": "Random-Integer-Generator01",
  4.     "adminState": "UNLOCKED",
  5.     "operatingState": "ENABLED",
  6.     "lastConnected": 0,
  7.     "lastReported": 0,
  8.     "labels": [
  9.         "device-random-example"
  10.     ],
  11.     "location": null,
  12.     "commands": [
  13.         {
  14.             "created": 1603089038273,
  15.             "modified": 1603089038273,
  16.             "id": "fb00eb8f-faff-4b4f-a65c-0772824c8c28",
  17.             "name": "GenerateRandomValue_Int8",
  18.             "get": {
  19.                 "path": "/api/v1/device/{deviceId}/GenerateRandomValue_Int8",
  20.                 "responses": [
  21.                     {
  22.                         "code": "503",
  23.                         "description": "service unavailable"
  24.                     }
  25.                 ],
  26.                 "url": "http://edgex-core-command:48082/api/v1/device/09d43a05-aca0-42f2-a3e0-76360ae9d573/command/fb00eb8f-faff-4b4f-a65c-0772824c8c28"
  27.             },
  28.             "put": {
  29.                 "path": "/api/v1/device/{deviceId}/GenerateRandomValue_Int8",
  30.                 "parameterNames": [
  31.                     "Min_Int8",
  32.                     "Max_Int8"
  33.                 ],
  34.                 "url": "http://edgex-core-command:48082/api/v1/device/09d43a05-aca0-42f2-a3e0-76360ae9d573/command/fb00eb8f-faff-4b4f-a65c-0772824c8c28"
  35.             }
  36.         },
  37.         {
  38.             "created": 1603089038273,
  39.             "modified": 1603089038273,
  40.             "id": "790ff76e-5481-485c-a7cd-5c79bd7d216e",
  41.             "name": "GenerateRandomValue_Int16",
  42.             "get": {
  43.                 "path": "/api/v1/device/{deviceId}/GenerateRandomValue_Int16",
  44.                 "responses": [
  45.                     {
  46.                         "code": "503",
  47.                         "description": "service unavailable"
  48.                     }
  49.                 ],
  50.                 "url": "http://edgex-core-command:48082/api/v1/device/09d43a05-aca0-42f2-a3e0-76360ae9d573/command/790ff76e-5481-485c-a7cd-5c79bd7d216e"
  51.             },
  52.             "put": {
  53.                 "path": "/api/v1/device/{deviceId}/GenerateRandomValue_Int16",
  54.                 "parameterNames": [
  55.                     "Min_Int16",
  56.                     "Max_Int16"
  57.                 ],
  58.                 "url": "http://edgex-core-command:48082/api/v1/device/09d43a05-aca0-42f2-a3e0-76360ae9d573/command/790ff76e-5481-485c-a7cd-5c79bd7d216e"
  59.             }
  60.         },
  61.         {
  62.             "created": 1603089038273,
  63.             "modified": 1603089038273,
  64.             "id": "35b53068-d0fb-43d3-82d0-00b34de362a8",
  65.             "name": "GenerateRandomValue_Int32",
  66.             "get": {
  67.                 "path": "/api/v1/device/{deviceId}/GenerateRandomValue_Int32",
  68.                 "responses": [
  69.                     {
  70.                         "code": "503",
  71.                         "description": "service unavailable"
  72.                     }
  73.                 ],
  74.                 "url": "http://edgex-core-command:48082/api/v1/device/09d43a05-aca0-42f2-a3e0-76360ae9d573/command/35b53068-d0fb-43d3-82d0-00b34de362a8"
  75.             },
  76.             "put": {
  77.                 "path": "/api/v1/device/{deviceId}/GenerateRandomValue_Int32",
  78.                 "parameterNames": [
  79.                     "Min_Int32",
  80.                     "Max_Int32"
  81.                 ],
  82.                 "url": "http://edgex-core-command:48082/api/v1/device/09d43a05-aca0-42f2-a3e0-76360ae9d573/command/35b53068-d0fb-43d3-82d0-00b34de362a8"
  83.             }
  84.         }
  85.     ]
  86. }



Random-Integer-Generator01设备有 GenerateRandomValue_Int8、GenerateRandomValue_Int16、GenerateRandomValue_Int32这 3 种属性






 楼主| keer_zu 发表于 2020-10-26 10:22 | 显示全部楼层
控制设备


通过命令微服务(Command Service)检查到设备可以调用的设备属性,使用put或get其url值读取或设置设备参数

  1. GET http://192.168.138.128:48082/api/v1/device/09d43a05-aca0-42f2-a3e0-76360ae9d573/command/fb00eb8f-faff-4b4f-a65c-0772824c8c28

521125f96305d0d496.png

获取结果:
  1. {
  2.     "device": "Random-Integer-Generator01",
  3.     "origin": 1603677368224,
  4.     "readings": [
  5.         {
  6.             "origin": 1603677368224,
  7.             "device": "Random-Integer-Generator01",
  8.             "name": "RandomValue_Int8",
  9.             "value": "-21"
  10.         }
  11.     ]
  12. }




 楼主| keer_zu 发表于 2020-10-26 10:23 | 显示全部楼层
device-service数据推送

EdgeX Foundry 除了接受端设备的数据外,还可以将数据推送到各种云服务上,例如将获取到的随机数据推送到 MQTT 服务器上。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

个人签名:qq群:49734243 Email:zukeqiang@gmail.com

1477

主题

12909

帖子

55

粉丝
快速回复 在线客服 返回列表 返回顶部