设备注册
cd /data/gopath/src/github.com/kubeedge/examples/temperature-demo/crds
目录中有deviceinstance.yaml 和 devicemodel.yaml两个文件
apiVersion: devices.kubeedge.io/v1alpha2
kind: DeviceModel
metadata:
name: dht22-model
namespace: default
spec:
properties:
- name: temperature-status
description: Temperature collected from the edge device
type:
string:
accessMode: ReadOnly
defaultValue: ''
- name: humidity
description: humidity collected from the edge device
type:
string:
accessMode: ReadOnly
defaultValue: ''
apiVersion: devices.kubeedge.io/v1alpha2
kind: Device
metadata:
name: dht22
labels:
description: 'temperature'
manufacturer: 'test'
spec:
deviceModelRef:
name: dht22-model
nodeSelector:
nodeSelectorTerms:
- matchExpressions:
- key: ''
operator: In
values:
- edge-node
status:
twins:
- propertyName: temperature-status
desired:
metadata:
type: string
value: ''
- propertyName: humidity
desired:
metadata:
type: string
value: ''
创建设备模型与设备实例注册设备
kubectl create -f devicemodel.yaml
kubectl create -f deviceinstance.yaml
- edge节点上下载sqlite3
sudo apt install sqlite3
- 连接edgecore数据库
sqlite3 /var/lib/kubeedge/edgecore.db
其他语句
.exit //退出sqlite3
.tables
.mode column //数据有标题
.header on
select *from device //注册完设备后,查询设备
select*from device_twin //发布完数据后可查询发布数据
! ----- /var/lib/kubeedge/edgecore.db在edgecore.yaml中可以找到
- 先下载mqttfx,然后输入edge节点ip地址,点击apply。
4. edge节点新开一个终端,进行订阅
//“'$'hw/events/device/temperature/state/update”为主题
//mosquitto_sub -t '$'主题名 -h ip地址
mosquitto_sub -t '$'hw/events/device/temperature/state/update -h 192.168.1.100
- 将主题名(
$hw/events/device/temperature/state/update)复制到mqttfx
6. 输入{ "state": "online" },点击publish
{ "state": "online" }
7.在edge节点数据库中查询状态
select *from device
- 发送mqtt数据格式
mosquitto_sub -t '$'hw/events/device/temperature/twin/update -h 192.168.1.100
将$hw/events/device/temperature/twin/update复制到mqttfx
输入发送数据,点击publish
{ "event_id": "","timestamp": 0,"twin": { "temperature-status":{"actual":{ "value": "28.0"}, "metadata": {"type": "Updated" }}, "humidity":{"actual" : { "value": "38.6" },"metadata": {"type": "Updated" }}}}
9. 在云端k8s-master节点查看资源。
kubectl get device 设备名 -oyaml
kubectl get device temperature -oyaml

watch -n 1 -d 'kubectl get device <devicename> -oyaml'

本文档详述了如何使用KubeEdge进行设备模型和设备实例的注册,通过sqlite3数据库管理edgecore,并利用mqtt工具进行数据发布与订阅。首先,在crds目录下创建设备模型和设备实例的yaml文件,接着使用kubectl命令注册设备。然后在edge节点安装sqlite3并连接edgecore数据库,观察设备状态。同时,通过mqttfx订阅和发布消息来模拟设备数据的在线状态和更新。最后,在云端k8s-master节点查看设备资源的状态。


被折叠的 条评论
为什么被折叠?



