#创作者激励# 领航计划(四) 理解 KubeEdge Device twin 原创

Piwriw.
发布于 2023-3-11 19:43
浏览
0收藏

领航计划(四)理解 KubeEdge Device twin

什么是 Device twin

Device twin

  • 设备的动态属性,在 KubeEdge 中的设备孪生 包含了desired value(期望值)reported value(真实值),这对于开放你自己边缘应用的使用是更重要的
  • 在 KubeEdge 利用 Device Model 和 Device Instance 的机制,通过一套 Device Model 生成大量 Device Instance 的机制实现关联管理,模具和事物的关系

Device Commpents in KubeEdge

#创作者激励#  领航计划(四) 理解 KubeEdge Device twin-鸿蒙开发者社区

Membership Module

  • 该模块主要负责绑定新加入的设备与指定的边缘节点(其实就是NodeSelector的体现)

Twin Module

  • 该模块主要负责所有设备孪生相关的操作。比如,设备孪生更新(device twin update)、设备孪生获取(device twin get)和设备孪生同步至云端(device twin sync-to-cloud)

Communication Module

  • 该模块主要负责各个子模块之间的通信

Device Module

  • 该模块主要负责执行设备相关的操作,比如处理设备状态(device status)更新和设备属性(device attribute)更新
  • 此外,DeviceTwin模块会在本地数据库(SQLite)中创建3张表,即Device Table、Device Attribute Table和Device Twin Table,分别记录设备的基本信息、设备的属性信息和设备孪生信息。

MoreInfo Device Model

apiVersion: devices.kubeedge.io/v1alpha2
kind: DeviceModel
metadata:
 name: sensor-tag-model
 namespace: default
spec:
 properties:
  - name: temperature
    description: temperature in degree celsius
    type:
     int:
      accessMode: ReadWrite
      maximum: 100
      unit: degree celsius
  - name: temperature-enable
    description: enable data collection of temperature sensor
    type:
      string:
        accessMode: ReadWrite
        defaultValue: 'OFF'

MoreInfo Device Instance

一个 Device Instance 大概是:

apiVersion: devices.kubeedge.io/v1alpha2
kind: Device
metadata:
  name: sensor-tag-instance-01
  labels:
    description: TISimplelinkSensorTag
    manufacturer: TexasInstruments
    model: CC2650
spec:
  deviceModelRef:
    name: sensor-tag-model
  protocol:
    modbus:
      slaveID: 1
    common:
      com:
        serialPort: '1'
        baudRate: 115200
        dataBits: 8
        parity: even
        stopBits: 1
  nodeSelector:
    nodeSelectorTerms:
    - matchExpressions:
      - key: ''
        operator: In
        values:
        - node1
  propertyVisitors:
    - propertyName: temperature
      modbus:
        register: CoilRegister
        offset: 2
        limit: 1
        scale: 1
        isSwap: true
        isRegisterSwap: true
    - propertyName: temperature-enable
      modbus:
        register: DiscreteInputRegister
        offset: 3
        limit: 1
        scale: 1.0
        isSwap: true
        isRegisterSwap: true
status:
  twins:
    - propertyName: temperature
      reported:
        metadata:
          timestamp: '1550049403598'
          type: int
        value: '10'
      desired:
        metadata:
          timestamp: '1550049403598'
          type: int

Data Topic

  • 在KubeEdge v1.4之后,也添加了可以在边缘端的Data topic模块
apiVersion: devices.kubeedge.io/v1alpha1
kind: Device
metadata:
    ...
spec:
  deviceModelRef:
    ...
  protocol:
    ...
  nodeSelector:
    ...
  propertyVisitors:
    ...
  data:
    dataTopic: "$ke/events/device/+/data/update"
    dataProperties:
      - propertyName: pressure
        metadata:
          type: int
      - propertyName: temperature
        metadata:
          type: int

Topic 汇总

topic 发布者(publish) 订阅者(subscribe) 用途简介 mapper是否必须实现
$hw/events/node/+/membership/updated edgecore mapper 订阅设备列表的变化 建议实现
$hw/events/node/+/membership/get mapper edgecore 查询设备列表 建议实现
$hw/events/node/+/membership/get/result edgecore mapper 获取查询设备列表的结果 建议实现
$hw/events/device/+/updated edgecore mapper 订阅设备属性描述的变化
$hw/events/device/+/twin/update/result edgecore mapper 获取设备属性更新是否成功 建议实现
$hw/events/device/+/twin/update/delta edgecore mapper 获取设备属性更新的值
$hw/events/device/+/twin/update/document edgecore mapper 获取设备属性更新的操作记录
$hw/events/device/+/twin/get/result edgecore mapper、apps 返回获取设备属性的值
$hw/events/device/+/twin/update mapper edgecore 通知设备属性的值更新
$hw/events/device/+/twin/get mapper,apps edgecore 获取设备属性的值
$hw/events/device/+/state/update mapper edgecore 通知设备状态更新 建议实现
$hw/events/device/+/state/update/result edgecore mapper 获取设备状态更新结果
$ke/events/device/+/data/update mapper apps 获取设备属性的时序数据
$hw/events/upload/# x edgecore 转发云端
SYS/dis/upload_records x edgecore 转发云端

©著作权归作者所有,如需转载,请注明出处,否则将追究法律责任
分类
已于2023-3-11 20:13:34修改
1
收藏
回复
举报
回复
    相关推荐