Skip to main content

边缘驱动介绍

概述

对于一些非标设备,特别是只能通过动态链接库方式进行通信的设备,或者是需要进行边缘计算的场景,我们提供了设备驱动SDK,让用户可以在边缘对接设备并进行相关处理后再上报至平台。

设计思路

边缘侧设备驱动,主要参考了edgexfoundary的实现。

通过物模型配置,进行设备实例的初始化。在功能层面实现了定时上报,主动获取,指令下发等功能。

配置文件说明

配置文件主要有全局配置文件,产品物模型配置文件和设备配置文件

全局配置文件

属性说明

属性说明数据类型
MaxEventSize上报事件体最大数,单位byte,0为不限制int
Deviceobject
Device.ProfilesDirprofiles文件夹位置string
Device.DevicesDirdevices文件夹位置string
MQTTobject
MQTT.ClientIdmqtt clientIdstring
MQTT.Protocolmqtt协议string
MQTT.Hostmqtt hoststring
MQTT.Portmqtt 端口号int
MQTT.QOSint
MQTT.Usernamestring
MQTT.Passwordstring
MQTT.ConnectionTimeoutint
MQTT.TopicPrefixtopic前缀,所有的topic 都会加上string

范例

MaxEventSize: 0 # value 0 unlimit the maximum event size that can be sent to message bus or core-data
Writable:
LogLevel: INFO

Device:
# These have common values (currently), but must be here for service local env overrides to apply when customized
ProfilesDir: "./res/profiles"
DevicesDir: "./res/devices"

MQTT:
ClientId: "device-virtual"
Protocol: "tcp"
Host: "xxx.xxx.xxx.xxx"
Port: 1883
QOS: 0
Username: "xxx"
Password: "xxx"
ConnectionTimeout: 30
TopicPrefix: "phecda-test"

产品物模型配置文件

位置根据全局配置文件确定

物模型配置可直接在平台端生成

属性说明

属性说明数据类型
productKey产品KeyString
name名称String
manufacturerString
model模型名称String
labels标签String[]
description说明String
deviceProperties设备属性Object[]
deviceProperties[].identifier设备属性标识String
deviceProperties[].name设备属性名称String
deviceProperties[].description设备属性描述String
deviceProperties[].properties设备属性的属性Object
deviceProperties[].properties.valueType设备属性的值类型String
deviceProperties[].properties.readWrite设备属性的读写:R(只读),W(只写),RW(读写)String
deviceCommands设备指令Object[]
deviceCommands[].identifier设备指令标识String
deviceCommands[].name设备指令名称String
deviceCommands[].callType设备指令请求类型:Async(异步),Sync(同步)String
deviceCommands[].inputData设备指令入参Object[]
deviceCommands[].inputData[].identifier设备指令入参标识String
deviceCommands[].inputData[].name设备指令入参名称String
deviceCommands[].inputData[].properties设备指令入参属性String
deviceCommands[].inputData[].properties.valueType设备指令入参属性值类型String
deviceCommands[].outputData设备指令出参Object[]
deviceCommands[].outputData[].identifier设备指令出参标识String
deviceCommands[].outputData[].name设备指令出参名称String
deviceCommands[].outputData[].properties设备指令出参属性String
deviceCommands[].outputData[].properties.valueType设备指令出参属性值类型String
deviceEvents设备事件Object[]
deviceEvents[].identifier设备事件标识String
deviceEvents[].name设备事件名称String
deviceEvents[].type设备事件类型String
deviceEvents[].outputData设备事件返回值String
deviceEvents[].outputData[].identifier设备事件返回值标识String
deviceEvents[].outputData[].name设备事件返回值名称String
deviceEvents[].outputData[].properties设备事件返回值属性Object[]
deviceEvents[].outputData[].properties.valueType设备事件返回值属性值类型String

范例

productKey: 'trionesdev-test001'
name: "测试设备-Device"
manufacturer: "IOTech"
model: "Device-Virtual-01"
labels:
- "device-virtual-example"
description: "Example of Device-Virtual"

deviceProperties:
- identifier: "temperature"
name: "温度"
description: "温度"
properties:
valueType: "Int"
readWrite: "R"


deviceCommands:
- identifier: "get_temperature"
name: "获取温度"
callType: "Async"
inputData:
- identifier: "temperature"
name: "温度"
properties:
valueType: "Int"
outputData:
- identifier: "temperature"
name: "温度"
properties:
valueType: "Int"


deviceEvents:
- identifier: "temperature_alarm"
name: "温度报警"
type: 'Warn'
outputData:
- identifier: "temperature"
name: "温度"
properties:
valueType: "Int"

设备配置文件

位置根据全局配置文件确定

属性说明

属性说明数据类型
deviceList设备列表object[]
deviceList[].name设备名称
deviceList[].profileName设备物模型名称,需要存在于之前定义的物模型中
deviceList[].description设备描述
deviceList[].labels设备标签string[]
deviceList[].tags设备标签,该标签会自动添加到事件标签中
deviceList[].protocols协议map<string,map<string,object>>
deviceList[].autoEvents自动事件object[]
deviceList[].autoEvents[].interval自动事件-间隔string
deviceList[].autoEvents[].onChange自动事件-是否变化才上报bool
deviceList[].autoEvents[].sourceName自动事件-源,deviceResource或者deviceCommandstring

范例

deviceList:
- name: device_0001
productKey: trionesdev-test001
description: Example of Device Virtual
labels:
- device-virtual-example
tags:
env: test
protocols: { }
autoEvents:
- interval: 10s
onChange: false
identifier: temperature

数据类型

类型说明
Bool布尔值
String字符串
Int整数型
Long长整数
Float浮点数
Double双精度浮点数
Struct结构体
BoolArray布尔数组
StringArray字符串数组
IntArray整数数组
LongArray长整数数组
FloatArray浮点数数组
DoubleArray双精度数组
StructArray结构体数组