EdgeX Foundry 基本操作

# EdgeX Foundry

https://iothub.org.cn/docs/edgex/
https://iothub.org.cn/docs/edgex/app/operate/

在这里插入图片描述

一、容器管理

1.容器操作

# 安装并启动EdgeX
sudo docker-compose up -d     # -d 后台运行容器
 
# 查看所有容器运行状况
sudo docker-compose ps
 
# 显示容器日志
docker-compose logs -f [compose-contatainer-name]
 
# 停止容器
sudo docker-compose stop
 
# 启动容器
sudo docker-compose start
 
# 停止和删除所有容器
sudo docker-compose down

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

2.查看容器日志

# docker-compose logs
# docker-compose logs -f [compose-contatainer-name]

在这里插入图片描述

二、EdgeX UI 操作

1.访问 UI

1.1. consul
# 访问地址
http://192.168.202.233:8500

在这里插入图片描述

1.2. EdgeX Console
# 访问地址
http://192.168.202.233:4000/

在这里插入图片描述

2.创建 MQTT 设备

2.1.创建设备配置文件

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

设备配置文件

name: "my-custom-device-profile"
manufacturer: "iot"
model: "MQTT-DEVICE"
description: "Test device profile"
labels:
  - "mqtt"
  - "test"
deviceResources:
  -
    name: randnum
    isHidden: true
    description: "device random number"
    properties:
      valueType: "Float32"
      readWrite: "R"
  -
    name: ping
    isHidden: true
    description: "device awake"
    properties:
      valueType: "String"
      readWrite: "R"
  -
    name: message
    isHidden: false
    description: "device message"
    properties:
      valueType: "String"
      readWrite: "RW"
  -
    name: json
    isHidden: false
    description: "JSON message"
    properties:
      valueType: "Object"
      readWrite: "RW"
      mediaType: "application/json"

deviceCommands:
  -
    name: values
    readWrite: "R"
    isHidden: false
    resourceOperations:
        - { deviceResource: "randnum" }
        - { deviceResource: "ping" }
        - { deviceResource: "message" }
2.2.添加设备

设备配置

使用此配置文件来定义设备和调度作业。device-mqtt 在启动时生成一个相对实例。

# Pre-define Devices
deviceList:
- name: "my-custom-device"
  profileName: "my-custom-device-profile"
  description: "MQTT device is created for test purpose"
  labels: [ "MQTT", "test" ]
  protocols:
    mqtt:
      CommandTopic: "command/my-custom-device"
  autoEvents:
    - interval: "30s"
      onChange: false
      sourceName: "message"

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

3.设备配置文件

3.1.配置文件管理

在这里插入图片描述

3.2.修改配置文件

在这里插入图片描述
在这里插入图片描述

4.设备

4.1.设备管理

在这里插入图片描述

4.2.修改设备信息

在这里插入图片描述

4.3.命令

在这里插入图片描述

4.4.自动采集

在这里插入图片描述

5.设备通信

5.1.设备命令

在这里插入图片描述

5.2.事件

在这里插入图片描述

5.3.读值

在这里插入图片描述

三、REST API

1.查询执行命令

$ curl http://localhost:59882/api/v3/device/all | json_pp

$ curl http://localhost:59882/api/v3/device/name/device-name
[root@edgex compose-builder]# curl http://localhost:59882/api/v3/device/all


{"apiVersion":"v3","statusCode":200,"totalCount":2,"deviceCoreCommands":[{"deviceName":"MQTT-test-device","profileName":"Test-Device-MQTT-Profile","coreCommands":[{"name":"ping","get":true,"path":"/api/v3/device/name/MQTT-test-device/ping","url":"http://edgex-core-command:59882","parameters":[{"resourceName":"ping","valueType":"String"}]},{"name":"message","get":true,"set":true,"path":"/api/v3/device/name/MQTT-test-device/message","url":"http://edgex-core-command:59882","parameters":[{"resourceName":"message","valueType":"String"}]},{"name":"json","get":true,"set":true,"path":"/api/v3/device/name/MQTT-test-device/json","url":"http://edgex-core-command:59882","parameters":[{"resourceName":"json","valueType":"Object"}]},{"name":"allValues","get":true,"set":true,"path":"/api/v3/device/name/MQTT-test-device/allValues","url":"http://edgex-core-command:59882","parameters":[{"resourceName":"randfloat32","valueType":"Float32"},{"resourceName":"randfloat64","valueType":"Float64"},{"resourceName":"message","valueType":"String"}]},{"name":"randfloat32","get":true,"set":true,"path":"/api/v3/device/name/MQTT-test-device/randfloat32","url":"http://edgex-core-command:59882","parameters":[{"resourceName":"randfloat32","valueType":"Float32"}]},{"name":"randfloat64","get":true,"set":true,"path":"/api/v3/device/name/MQTT-test-device/randfloat64","url":"http://edgex-core-command:59882","parameters":[{"resourceName":"randfloat64","valueType":"Float64"}]}]},{"deviceName":"my-custom-device","profileName":"my-custom-device-profile","coreCommands":[{"name":"values","get":true,"path":"/api/v3/device/name/my-custom-device/values","url":"http://edgex-core-command:59882","parameters":[{"resourceName":"randnum","valueType":"Float32"},{"resourceName":"ping","valueType":"String"},{"resourceName":"message","valueType":"String"}]},{"name":"message","get":true,"set":true,"path":"/api/v3/device/name/my-custom-device/message","url":"http://edgex-core-command:59882","parameters":[{"resourceName":"message","valueType":"String"}]},{"name":"json","get":true,"set":true,"path":"/api/v3/device/name/my-custom-device/json","url":"http://edgex-core-command:59882","parameters":[{"resourceName":"json","valueType":"Object"}]}]}]}
[root@edgex compose-builder]# curl http://localhost:59882/api/v3/device/name/my-custom-device


{
	"apiVersion": "v3",
	"statusCode": 200,
	"deviceCoreCommand": {
		"deviceName": "my-custom-device",
		"profileName": "my-custom-device-profile",
		"coreCommands": [{
			"name": "json",
			"get": true,
			"set": true,
			"path": "/api/v3/device/name/my-custom-device/json",
			"url": "http://edgex-core-command:59882",
			"parameters": [{
				"resourceName": "json",
				"valueType": "Object"
			}]
		}, {
			"name": "values",
			"get": true,
			"path": "/api/v3/device/name/my-custom-device/values",
			"url": "http://edgex-core-command:59882",
			"parameters": [{
				"resourceName": "randnum",
				"valueType": "Float32"
			}, {
				"resourceName": "ping",
				"valueType": "String"
			}, {
				"resourceName": "message",
				"valueType": "String"
			}]
		}, {
			"name": "message",
			"get": true,
			"set": true,
			"path": "/api/v3/device/name/my-custom-device/message",
			"url": "http://edgex-core-command:59882",
			"parameters": [{
				"resourceName": "message",
				"valueType": "String"
			}]
		}]
	}
}

在这里插入图片描述

2.SET 命令

$ curl http://localhost:59882/api/v3/device/name/my-custom-device/message \
    -H "Content-Type:application/json" -X PUT  \
    -d '{"message":"Hello!"}'
# curl http://localhost:59882/api/v3/device/name/my-custom-device/message \
    -H "Content-Type:application/json" -X PUT  \
    -d '{"message":"Hello!"}'


[root@edgex compose-builder]# curl http://localhost:59882/api/v3/device/name/my-custom-device/message \
>     -H "Content-Type:application/json" -X PUT  \
>     -d '{"message":"Hello!"}'
{"apiVersion":"v3","statusCode":200}

在这里插入图片描述

3.GET 命令

$ curl http://localhost:59882/api/v3/device/name/my-custom-device/message
# curl http://localhost:59882/api/v3/device/name/my-custom-device/message


[root@edgex compose-builder]# curl http://localhost:59882/api/v3/device/name/my-custom-device/message


{
	"apiVersion": "v3",
	"statusCode": 200,
	"event": {
		"apiVersion": "v3",
		"id": "2bac78a7-b959-44d9-ac9c-c8e39b8f4b56",
		"deviceName": "my-custom-device",
		"profileName": "my-custom-device-profile",
		"sourceName": "message",
		"origin": 1708510731459679263,
		"readings": [{
			"id": "8d14ecae-a1a1-439b-8fe1-f85f50783548",
			"origin": 1708510731459675461,
			"deviceName": "my-custom-device",
			"resourceName": "message",
			"profileName": "my-custom-device-profile",
			"valueType": "String",
			"value": "Hello!"
		}]
	}
}

4.调度作业

autoEvents调度作业在设备定义文件的部分中定义:

    autoEvents:
       Interval: "30s"
       OnChange: false
       SourceName: "message"

服务启动后,查询core-data的读取API。结果显示服务每30秒自动执行一次命令,如下所示:

$ curl http://localhost:59880/api/v3/reading/resourceName/message | json_pp
# curl http://localhost:59880/api/v3/reading/resourceName/message


[root@edgex compose-builder]# curl http://localhost:59880/api/v3/reading/resourceName/message


{
	"apiVersion": "v3",
	"statusCode": 200,
	"totalCount": 840,
	"readings": [{
		"id": "2beff7bf-fe84-4301-9baa-ef283b99c0b3",
		"origin": 1708510957760593943,
		"deviceName": "my-custom-device",
		"resourceName": "message",
		"profileName": "my-custom-device-profile",
		"valueType": "String",
		"value": "Hello!"
	}, 
	
	{
		"id": "e45e0f64-3f28-41a8-91be-0f4c0865a2f7",
		"origin": 1708510950004786813,
		"deviceName": "my-custom-device",
		"resourceName": "message",
		"profileName": "my-custom-device-profile",
		"valueType": "String",
		"value": "Hello World"
	}, 
	
	......
	
	]
}

5.异步设备读值

订阅device-mqtta DataTopic,等待真实设备向 MQTT Broker 发送值,然后device-mqtt解析该值并转发到北向。

数据格式包含以下值:

  • name = device name
  • cmd = deviceResource name
  • method = get or set
  • cmd = device reading

以下结果显示模拟设备每 15 秒发送一次读数:

$ curl http://localhost:59880/api/v3/reading/resourceName/randnum | json_pp
# curl http://localhost:59880/api/v3/reading/resourceName/randnum


[root@edgex compose-builder]# curl http://localhost:59880/api/v3/reading/resourceName/randnum


{
	"apiVersion": "v3",
	"statusCode": 200,
	"totalCount": 824,
	"readings": [{
		"id": "c4acd21d-6ea5-4a29-a865-4d748c7740b6",
		"origin": 1708514190002112819,
		"deviceName": "my-custom-device",
		"resourceName": "randnum",
		"profileName": "my-custom-device-profile",
		"valueType": "Float32",
		"value": "2.510000e+01"
	}, {
		"id": "d23c8625-d5ea-4fb2-ac95-659d533573ae",
		"origin": 1708514115001993970,
		"deviceName": "my-custom-device",
		"resourceName": "randnum",
		"profileName": "my-custom-device-profile",
		"valueType": "Float32",
		"value": "2.810000e+01"
	}, {
		"id": "c71a58ac-9846-43fe-9533-bf378fbee649",
		"origin": 1708514070003642414,
		"deviceName": "my-custom-device",
		"resourceName": "randnum",
		"profileName": "my-custom-device-profile",
		"valueType": "Float32",
		"value": "2.720000e+01"
	},
	
	......
	
	]
}
# EdgeX Foundry

https://iothub.org.cn/docs/edgex/
https://iothub.org.cn/docs/edgex/app/operate/
  • 21
    点赞
  • 21
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

IoTHub - 物联网开源技术社区

支持开源技术! 传播开源文化!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值