方案架构
边缘端物模型定义
电表
{
"events": [],
"properties": [
{
"id": "ActiveEnergySum",
"name": "有功电能总和",
"valueType": {
"type": "float",
"scale": 2,
"unit": "kWattsHour"
},
"expands": {
"readOnly": "true"
}
},
{
"id": "Vavg",
"name": "电压",
"valueType": {
"type": "float",
"scale": 2,
"unit": "volt"
},
"expands": {
"readOnly": "true"
}
},
{
"id": "Iavg",
"name": "电流",
"valueType": {
"type": "float",
"scale": 3,
"unit": "ampere"
},
"expands": {
"readOnly": "true"
}
},
{
"id": "ActivePowerSum",
"name": "有功功率",
"valueType": {
"type": "float",
"scale": 1,
"unit": "watt"
},
"expands": {
"readOnly": "true"
}
},
{
"id": "ReactivePowerSum",
"name": "无功功率",
"valueType": {
"type": "float",
"scale": 1,
"unit": "乏"
},
"expands": {
"readOnly": "true"
}
},
{
"id": "InspectingPowerSum",
"name": "视在功率",
"valueType": {
"type": "float",
"scale": 1,
"unit": "伏安"
},
"expands": {
"readOnly": "true"
}
},
{
"id": "PFSum",
"name": "功率因数",
"valueType": {
"type": "float",
"scale": 3
},
"expands": {
"readOnly": "true"
}
},
{
"id": "Frequency",
"name": "频率",
"valueType": {
"type": "float",
"scale": 2,
"unit": "hertz"
},
"expands": {
"readOnly": "true"
}
}
],
"functions": [],
"tags": []
}
水表
{
"events": [
{
"id": "ALARM_DATA",
"name": "报警数据",
"expands": {
"eventType": "event",
"level": "warn"
},
"valueType": {
"type": "object",
"properties": [
{
"id": "channel",
"name": "通道号",
"valueType": {
"type": "int",
"min": "0",
"max": "2"
},
"description": "通道号,0表示通道一报警,1表示通道二报警,2表示电池报警"
},
{
"id": "channelName",
"name": "通道名",
"valueType": {
"type": "string"
}
},
{
"id": "alarmType",
"description": "报警类型,1低限报警,2代表高限报警,3传感器故障,4报警恢复",
"name": "报警类型",
"valueType": {
"type": "int",
"min": "1",
"max": "4"
}
},
{
"id": "alarmTypeString",
"name": "报警名称",
"valueType": {
"type": "string"
}
},
{
"id": "realValue",
"name": "报警时的数据",
"valueType": {
"type": "double",
"scale": "2"
},
"description": "压力报警时单位为:kPa,液位报警时压力为:cm。"
},
{
"name": "报警阈值",
"id": "configValue",
"valueType": {
"type": "double",
"scale": "2"
},
"description": "报警阈值时高限还是低限,取决于报警类型。"
}
]
}
}
],
"properties": [
{
"id": "channel1_pressure",
"name": "通道一压力",
"valueType": {
"type": "double",
"min": "0",
"max": "6000",
"scale": "2",
"unit": "kiloPascal"
},
"expands": {
"readOnly": "true"
}
},
{
"id": "channel1_level",
"name": "通道一液位",
"valueType": {
"type": "double",
"min": "0",
"max": "5000",
"scale": "2",
"unit": "centimeter"
},
"expands": {
"readOnly": "true"
}
},
{
"id": "channel2_pressure",
"name": "通道二压力",
"valueType": {
"type": "double",
"min": "0",
"max": "6000",
"scale": "2",
"unit": "kiloPascal"
},
"expands": {
"readOnly": "true"
}
},
{
"id": "channel2_level",
"name": "通道二液位",
"valueType": {
"type": "double",
"min": "0",
"max": "5000",
"scale": "2",
"unit": "centimeter"
},
"expands": {
"readOnly": "true"
}
},
{
"id": "batteryValue",
"name": "电压",
"valueType": {
"type": "double",
"min": "0",
"max": "65535",
"scale": "2",
"unit": "milliVolt"
},
"expands": {
"readOnly": "true"
}
},
{
"id": "signal",
"name": "信号强度",
"valueType": {
"type": "int",
"min": "0",
"max": "100"
},
"expands": {
"readOnly": "true"
}
}
],
"functions": [],
"tags": []
}
云窗摄像头
{
"events": [],
"properties": [
{
"id": "p2plive",
"name": "P2P直播地址",
"valueType": {
"type": "object",
"properties": [
{
"id": "firstStream",
"name": "第一码流",
"valueType": {
"type": "string"
}
},
{
"id": "secondStream",
"name": "第二码流",
"valueType": {
"type": "string"
}
}
]
},
"expands": {
"readOnly": "false"
},
"description": "RTMP播放地址协议,该地址延迟较低,但是比较消耗设备上行带宽和P2P服务器带宽,请谨慎使用,在不要求高清时建议使用第二码流,全屏时切换到第一码流,可以降低播放端的压力和设备的带宽压力"
},
{
"id": "LiveUrl",
"name": "直播地址",
"valueType": {
"type": "object",
"properties": [
{
"id": "RtmpUrl",
"name": "Rtmp地址",
"valueType": {
"type": "string"
}
},
{
"id": "HlsUrl",
"name": "Hls直播地址",
"valueType": {
"type": "string"
},
"description": "兼容苹果和安卓端"
},
{
"id": "FlvUrl",
"name": "Flv播放地址",
"valueType": {
"type": "string"
},
"description": "兼容安卓端"
},
{
"id": "LiveState",
"name": "直播状态",
"valueType": {
"type": "enum",
"min": 0,
"max": 1,
"elements": [
{
"text": "离线",
"value": "0",
"id": 0
},
{
"id": 2,
"value": "1",
"text": "在线"
}
]
},
"description": "0表示离线,1表示在线"
}
]
},
"expands": {
"readOnly": "false"
},
"description": "保存摄像的直播状态和直播地址信息"
},
{
"id": "VideoQuality",
"name": "画质信息",
"valueType": {
"type": "object",
"properties": [
{
"id": "FirstCodeStream",
"name": "第一码流",
"valueType": {
"type": "object",
"parameters": [
{
"id": "CodeRate",
"name": "码率",
"valueType": {
"type": "int",
"min": 32,
"max": 6144
}
},
{
"id": "FrameRate",
"name": "帧率",
"valueType": {
"type": "int",
"min": 1,
"max": 25
}
},
{
"id": "CodeLevel",
"name": "编码等级",
"valueType": {
"type": "int",
"min": 1,
"max": 6
},
"description": ""
}
]
}
},
{
"id": "VideoStandard",
"name": "视频制式",
"valueType": {
"type": "enum",
"elements": [
{
"text": "50赫兹",
"value": "50",
"id": 0
},
{
"id": 2,
"value": "60",
"text": "60赫兹"
}
]
}
}
]
},
"expands": {
"readOnly": "false"
},
"description": "摄像头的画质信息,可以调用功能进行调节"
},
{
"id": "AudioInfo",
"name": "音频信息",
"valueType": {
"type": "object",
"properties": [
{
"id": "AudioType",
"name": "输入类型",
"valueType": {
"type": "enum",
"elements": [
{
"text": "线性输入",
"value": "0",
"id": 0
},
{
"id": 2,
"value": "1",
"text": "麦克输入"
}
]
}
},
{
"id": "InputVolume",
"name": "输入音量",
"valueType": {
"type": "int",
"min": 0,
"max": 100,
"unit": "percent"
},
"description": "摄像头端的输入音量"
},
{
"id": "OutputVolume",
"name": "输出音量",
"valueType": {
"type": "int",
"min": 0,
"max": 100
}
}
]
},
"expands": {
"readOnly": "false"
}
},
{
"id": "RealtimeSnapUrl",
"name": "实时预览图地址",
"valueType": {
"type": "string",
"expands": {}
},
"expands": {
"readOnly": "false"
},
"description": "实时预览图仅设备在线时可用"
},
{
"id": "SnapUrl",
"name": "预览图",
"valueType": {
"type": "string",
"expands": {}
},
"expands": {
"readOnly": "false"
},
"description": "历史预览图,最新的截图"
},
{
"id": "OsdName",
"name": "Osd名称",
"valueType": {
"type": "string",
"expands": {}
},
"expands": {
"readOnly": "false"
},
"description": "摄像头上的Osd名称值"
},
{
"id": "FtpInfo",
"name": "Ftp信息设置",
"valueType": {
"type": "object",
"properties": [
{
"id": "FtpServer",
"name": "Ftp服务器地址",
"valueType": {
"type": "string"
}
},
{
"id": "FtpPort",
"valueType": {
"type": "int"
},
"name": "Ftp服务端口号"
},
{
"id": "FtpUser",
"name": "用户名",
"valueType": {
"type": "string"
}
},
{
"id": "FtpPassword",
"name": "密码",
"valueType": {
"type": "string"
}
},
{
"id": "FtpType",
"name": "是否被动模式",
"valueType": {
"type": "boolean",
"trueText": "1",
"trueValue": "被动模式",
"falseValue": "非被动模式",
"falseText": "0"
}
},
{
"id": "FtpDir",
"name": "Ftp目录",
"valueType": {
"type": "string"
}
},
{
"id": "IsAutoCreateDir",
"name": "是否自动创建目录",
"valueType": {
"type": "boolean",
"trueText": "1",
"trueValue": "自动创建目录",
"falseText": "0",
"falseValue": "不自动创建目录"
}
}
]
},
"expands": {
"readOnly": "false"
}
},
{
"id": "PublishInfo",
"name": "推流信息",
"valueType": {
"type": "object",
"properties": [
{
"id": "PublishSwitch",
"name": "推流开关",
"valueType": {
"type": "enum",
"elements": [
{
"text": "关闭推流",
"value": "0",
"id": 0
},
{
"id": 2,
"value": "1",
"text": "开启推流"
}
]
}
},
{
"id": "PublishState",
"name": "推流状态",
"valueType": {
"type": "string"
}
},
{
"id": "AudioSwitch",
"name": "是否推流音频",
"valueType": {
"type": "enum",
"elements": [
{
"text": "不直播音频",
"value": "0",
"id": 0
},
{
"id": 2,
"value": "1",
"text": "直播音频"
}
]
}
},
{
"id": "PublishUrl",
"name": "推流地址",
"valueType": {
"type": "string"
},
"description": "推流的地址"
},
{
"id": "PublishVideoStream",
"valueType": {
"type": "enum",
"elements": [
{
"text": "第一码流",
"value": "1",
"id": 0
},
{
"id": 2,
"value": "2",
"text": "第二码流"
},
{
"id": 3,
"value": "3",
"text": "第三码流"
}
]
},
"name": "推流码流"
}
]
},
"expands": {
"readOnly": "false"
}
},
{
"id": "DeviceInfo",
"name": "设备信息",
"valueType": {
"type": "object",
"properties": [
{
"id": "DeviceName",
"name": "设备名称",
"valueType": {
"type": "string"
}
},
{
"id": "DeviceType",
"name": "设备型号",
"valueType": {
"type": "string"
}
},
{
"id": "NetworkType",
"name": "网络类型",
"valueType": {
"type": "string"
}
},
{
"id": "UserConnections",
"name": "用户连接数",
"valueType": {
"type": "int"
}
},
{
"id": "IpAddress",
"name": "IP地址",
"valueType": {
"type": "string"
}
},
{
"id": "SubnetMask",
"name": "子网掩码",
"valueType": {
"type": "string"
}
},
{
"id": "Router",
"name": "网关",
"valueType": {
"type": "string"
}
},
{
"id": "DnsServer",
"name": "DNS",
"valueType": {
"type": "array",
"elementType": "string",
"elementNumber": ""
}
},
{
"id": "RomVersion",
"name": "固件版本",
"valueType": {
"type": "string"
}
}
]
},
"expands": {
"readOnly": "false"
}
}
],
"functions": [
{
"id": "Ptzctrl",
"name": "云台控制",
"async": true,
"output": {
"type": "string",
"expands": {}
},
"description": "精准调节建议使用step=1的方式,类似于长按类型的云台控制使用step=0",
"inputs": [
{
"id": "step",
"name": "步进方式",
"valueType": {
"type": "enum",
"elements": [
{
"text": "单步执行,需再次发停止命令才能停止",
"value": "0",
"id": 0
},
{
"id": 2,
"value": "1",
"text": "单步执行后即自动停止"
}
]
},
"description": "0:单步执行后,需再次发停止命令才能停止\n1:单步执行后即自动停止"
},
{
"id": "act",
"name": "控制命令",
"valueType": {
"type": "enum",
"elements": [
{
"text": "向左",
"value": "left",
"id": 0
},
{
"id": 2,
"value": "right",
"text": "向右"
},
{
"id": 3,
"value": "up",
"text": "向上"
},
{
"id": 4,
"value": "down",
"text": "向下"
},
{
"id": 5,
"value": "home",
"text": "回到中心点"
},
{
"id": 6,
"value": "zoomin",
"text": "拉近"
},
{
"id": 7,
"value": "zoomout",
"text": "拉远"
},
{
"id": 8,
"value": "focusout",
"text": "聚焦+"
},
{
"id": 9,
"value": "focusin",
"text": "聚焦-"
},
{
"id": 10,
"value": "hscan",
"text": "水平巡航"
},
{
"id": 11,
"value": "vscan",
"text": "垂直巡航"
},
{
"id": 12,
"value": "stop",
"text": "停止"
}
]
}
},
{
"id": "speed",
"name": "云台速度",
"valueType": {
"type": "int",
"min": 1,
"max": 63
}
}
]
},
{
"id": "preset",
"name": "云台预置位",
"async": true,
"output": {
"type": "string",
"expands": {}
},
"description": "云台预置位操作,保存、清除、调用预置位",
"inputs": [
{
"id": "number",
"name": "预置位序号",
"valueType": {
"type": "int"
},
"description": "预置位序号"
},
{
"id": "act",
"name": "操作命令",
"valueType": {
"type": "enum",
"elements": [
{
"text": "调预置位",
"value": "goto",
"id": 0
},
{
"id": 2,
"value": "set",
"text": "设置预置位"
}
]
},
"description": "goto:调预置位\nset:设置预置位"
},
{
"id": "status",
"name": "预置位操作指令",
"valueType": {
"type": "enum",
"elements": [
{
"text": "清除",
"value": "0",
"id": 0
},
{
"id": 2,
"value": "1",
"text": "保存"
},
{
"id": 3,
"value": "2",
"text": "调用"
}
]
},
"description": "只有set时,需要填入这个参数"
}
]
},
{
"id": "Sysreboot",
"name": "系统重启",
"async": true,
"output": {
"type": "string",
"expands": {}
},
"description": "重启摄像头",
"inputs": []
},
{
"id": "SetAencAttr",
"name": "设置音频编码参数",
"async": false,
"output": {
"type": "string",
"expands": {}
},
"inputs": [
{
"id": "chn",
"name": "通道号",
"valueType": {
"type": "enum",
"elements": [
{
"text": "第一码流",
"value": "11",
"id": 0
},
{
"id": 2,
"value": "12",
"text": "第二码流"
},
{
"id": 3,
"value": "13",
"text": "第三码流"
}
]
}
},
{
"id": "aeswitch",
"name": "是否开启编码",
"valueType": {
"type": "enum",
"elements": [
{
"text": "关闭",
"value": "0",
"id": 0
},
{
"id": 2,
"value": "1",
"text": "开启"
}
]
},
"description": "是否开启音频编码\n0: 关闭\n1: 开启"
},
{
"id": "aeformat",
"name": "音频编码格式",
"valueType": {
"type": "enum",
"elements": [
{
"text": "G711a率 64Kbps",
"value": "g711a",
"id": 0
},
{
"id": 2,
"value": "g726",
"text": "G726 16Kbps"
}
]
}
}
]
},
{
"id": "SetAudioInVolume",
"name": "设置输入音频音量",
"async": false,
"output": {
"type": "string",
"expands": {}
},
"inputs": [
{
"id": "volin_type",
"name": "输入类型",
"valueType": {
"type": "enum",
"elements": [
{
"text": "线性输入",
"value": "0",
"id": 0
},
{
"id": 2,
"value": "1",
"text": "麦克输入"
}
]
},
"description": "非必选项"
},
{
"id": "volume",
"valueType": {
"type": "int",
"min": 0,
"max": 100,
"unit": "percent"
},
"name": "音量大小[1-100]",
"description": "非必选项"
}
]
}
],
"tags": [
{
"id": "panTilt",
"name": "云台操作",
"valueType": {
"type": "boolean",
"trueText": "支持云台操作",
"trueValue": "true",
"falseText": "不支持云台操作",
"falseValue": "false"
},
"expands": {
"readOnly": "false"
},
"description": "用于系统判定是否支持云台操作的一个标识,true:支持,false:不支持"
}
]
}
烟雾感应器
{
"events": [],
"properties": [
{
"id": "signalStrength",
"name": "信号质量百分比",
"valueType": {
"type": "int"
},
"expands": {
"readOnly": "true"
}
},
{
"id": "temperature",
"name": "温度",
"valueType": {
"type": "int",
"min": "-128",
"max": "127",
"unit": "celsiusDegrees"
},
"expands": {
"readOnly": "true"
}
},
{
"id": "tempSensorStatus",
"name": "温度传感器状态",
"valueType": {
"type": "int",
"min": "0",
"max": "2"
},
"expands": {
"readOnly": "true"
}
},
{
"id": "temperatureLimitValue",
"name": "温度报警阈值",
"valueType": {
"type": "int",
"min": "-128",
"max": "127",
"unit": "celsiusDegrees"
},
"expands": {
"readOnly": "true"
}
},
{
"id": "batteryVolt",
"name": "电池电压",
"valueType": {
"type": "int",
"min": "0",
"max": "65535",
"unit": "milliVolt"
},
"expands": {
"readOnly": "true"
}
},
{
"id": "batteryAlarmLimitValue",
"name": "电压报警阈值",
"valueType": {
"type": "int",
"min": "0",
"max": "65535",
"unit": "milliVolt"
},
"expands": {
"readOnly": "true"
}
},
{
"id": "batteryAlarmStatus",
"name": "电池低压状态",
"valueType": {
"type": "int",
"min": "0",
"max": "1"
},
"expands": {
"readOnly": "true"
}
},
{
"id": "uploadCycle",
"name": "上传周期",
"valueType": {
"type": "int",
"min": "1",
"max": "65535",
"unit": "minutes"
},
"expands": {
"readOnly": "true"
}
},
{
"id": "muteStatus",
"name": "报警消音状态",
"valueType": {
"type": "int",
"min": "0",
"max": "1"
},
"expands": {
"readOnly": "true"
}
},
{
"id": "antiButtonStatus",
"name": "防拆按键状态",
"valueType": {
"type": "int",
"min": "0",
"max": "1"
},
"expands": {
"readOnly": "true"
}
},
{
"id": "smokeAlarmStatus",
"name": "烟感报警状态",
"valueType": {
"type": "int",
"min": "0",
"max": "2"
},
"expands": {
"readOnly": "true"
}
}
],
"functions": [],
"tags": []
}
环境监测
{
"events": [],
"properties": [
{
"id": "Temperature",
"name": "温度",
"valueType": {
"type": "float",
"min": "0",
"max": "100",
"step": "0.1",
"unit": "celsiusDegrees"
},
"expands": {
"readOnly": "true"
}
},
{
"id": "Humidity",
"name": "湿度",
"valueType": {
"type": "float",
"unit": "RH%"
},
"expands": {
"readOnly": "true"
}
},
{
"id": "PM25",
"name": "PM2.5浓度",
"valueType": {
"type": "int",
"min": "0",
"max": "500",
"step": "1",
"unit": "μg/m³"
},
"expands": {
"readOnly": "true"
}
},
{
"id": "PM10",
"name": "PM10浓度",
"valueType": {
"type": "int",
"min": "0",
"max": "500",
"step": "1",
"unit": "μg/m³"
},
"expands": {
"readOnly": "true"
}
},
{
"id": "HCHO",
"name": "甲醛浓度",
"valueType": {
"type": "double",
"min": "0",
"max": "1",
"step": "0.01",
"scale": null,
"unit": "ppm"
},
"expands": {
"readOnly": "true"
}
}
],
"functions": [],
"tags": [
{
"id": "Location",
"name": "地理位置",
"valueType": {
"type": "geoPoint"
},
"expands": {
"readOnly": "false"
}
}
]
}
温控面板
{
"events": [],
"properties": [
{
"id": "mode",
"name": "模式",
"valueType": {
"type": "enum",
"elements": [
{
"text": "制冷",
"value": "0",
"id": 0
},
{
"id": 2,
"value": "1",
"text": "制热"
},
{
"id": 3,
"value": "2",
"text": "通风"
}
]
},
"expands": {
"readOnly": "true"
},
"description": "0-制冷 1-制热 2-通风"
},
{
"id": "roomtemperature",
"name": "房间温度",
"valueType": {
"type": "int",
"unit": "celsiusDegrees"
},
"expands": {
"readOnly": "true"
}
},
{
"id": "settemperature",
"name": "设置温度",
"valueType": {
"type": "int",
"unit": "celsiusDegrees"
},
"expands": {
"readOnly": "true"
}
},
{
"id": "speed",
"name": "风速",
"valueType": {
"type": "int",
"unit": ""
},
"expands": {
"readOnly": "true"
}
}
],
"functions": [
{
"id": "device_discovery_rsp",
"name": "确认添加子设备",
"async": true,
"output": {},
"inputs": [
{
"id": "User_ID",
"name": "用户ID",
"valueType": {
"type": "string"
}
},
{
"id": "status",
"name": "cancel-客户取消添加,OK-确认添加",
"valueType": {
"type": "string"
}
}
]
},
{
"id": "remove_device",
"name": "删除子设备",
"async": false,
"output": {
"type": "string",
"expands": {}
},
"inputs": [
{
"id": "User_ID",
"name": "用户ID",
"valueType": {
"type": "string"
}
}
]
},
{
"id": "read",
"name": "读取子设备",
"async": false,
"output": {
"type": "string",
"expands": {}
},
"inputs": [
{
"id": "User_ID",
"name": "用户ID",
"valueType": {
"type": "string"
}
}
]
},
{
"id": "write",
"name": "控制子设备",
"async": false,
"output": {
"type": "string",
"expands": {}
},
"inputs": [
{
"id": "User_ID",
"name": "用户ID",
"valueType": {
"type": "string"
}
},
{
"id": "channel_0",
"name": "channel_0",
"valueType": {
"type": "string"
},
"description": "on:开,off:关"
},
{
"id": "setmode",
"name": "setmode 0-制冷 1-制热 2-通风",
"valueType": {
"type": "int"
},
"description": "0-制冷 1-制热 2-通风"
},
{
"id": "setspeed",
"name": "风速设置 ",
"description": "0-关闭 1-低速 2-中速 3-高速 4-自动",
"valueType": {
"type": "int"
}
},
{
"id": "settemperature",
"name": "设置温度 温度范围:16~32",
"valueType": {
"type": "int"
}
}
]
}
],
"tags": []
}
智能灯带
{
"events": [],
"properties": [
{
"id": "channel_0",
"name": "开关状态",
"valueType": {
"type": "string",
"expands": {}
},
"expands": {
"readOnly": "true"
}
},
{
"id": "hue",
"name": "色调",
"valueType": {
"type": "int",
"unit": "degrees"
},
"expands": {
"readOnly": "true"
}
},
{
"id": "brightness",
"name": "亮度",
"valueType": {
"type": "int",
"unit": "degrees"
},
"expands": {
"readOnly": "true"
}
},
{
"id": "sturation",
"name": "饱和度",
"valueType": {
"type": "int",
"unit": "degrees"
},
"expands": {
"readOnly": "true"
}
}
],
"functions": [
{
"id": "device_discovery_rsp",
"name": "确认添加子设备",
"async": true,
"output": {},
"inputs": [
{
"id": "User_ID",
"name": "用户ID",
"valueType": {
"type": "string"
}
},
{
"id": "status",
"name": "cancel-客户取消添加,OK-确认添加",
"valueType": {
"type": "string"
}
}
]
},
{
"id": "remove_device",
"name": "删除子设备",
"async": false,
"output": {
"type": "string",
"expands": {}
},
"inputs": [
{
"id": "User_ID",
"name": "用户ID",
"valueType": {
"type": "string"
}
}
]
},
{
"id": "read",
"name": "读取子设备",
"async": false,
"output": {
"type": "string",
"expands": {}
},
"inputs": [
{
"id": "User_ID",
"name": "用户ID",
"valueType": {
"type": "string"
}
}
]
},
{
"id": "write",
"name": "led控制",
"async": false,
"output": {
"type": "string",
"expands": {}
},
"inputs": [
{
"id": "User_ID",
"name": "用户ID",
"valueType": {
"type": "string"
}
},
{
"id": "channel_0",
"name": "开关 on:开,off:关",
"valueType": {
"type": "string"
}
},
{
"id": "brightness",
"name": "亮度",
"valueType": {
"type": "string"
}
},
{
"id": "hue",
"name": "色调",
"valueType": {
"type": "string"
}
},
{
"id": "sturation",
"name": "饱和度",
"valueType": {
"type": "string"
}
}
]
}
],
"tags": []
}
音乐主机
{
"events": [],
"properties": [
{
"id": "channel_0",
"name": "开关状态",
"valueType": {
"type": "string",
"expands": {}
},
"expands": {
"readOnly": "true"
}
},
{
"id": "mute",
"name": "静音标志",
"valueType": {
"type": "int"
},
"expands": {
"readOnly": "true"
}
},
{
"id": "vol",
"name": "音量大小",
"valueType": {
"type": "int"
},
"expands": {
"readOnly": "true"
}
}
],
"functions": [
{
"id": "device_discovery_rsp",
"name": "确认添加子设备",
"async": true,
"output": {},
"inputs": [
{
"id": "User_ID",
"name": "用户ID",
"valueType": {
"type": "string"
}
},
{
"id": "status",
"name": "cancel-客户取消添加,OK-确认添加",
"valueType": {
"type": "string"
}
}
]
},
{
"id": "remove_device",
"name": "删除子设备",
"async": false,
"output": {
"type": "string",
"expands": {}
},
"inputs": [
{
"id": "User_ID",
"name": "用户ID",
"valueType": {
"type": "string"
}
}
]
},
{
"id": "read",
"name": "读取子设备",
"async": false,
"output": {
"type": "string",
"expands": {}
},
"inputs": [
{
"id": "User_ID",
"name": "用户ID",
"valueType": {
"type": "string"
}
}
]
},
{
"id": "write",
"name": "控制子设备",
"async": true,
"output": {
"type": "string",
"expands": {}
},
"inputs": [
{
"id": "User_ID",
"name": "用户ID",
"valueType": {
"type": "string"
}
},
{
"id": "channel_0",
"name": "channel_0",
"valueType": {
"type": "string"
},
"description": "on:打开,off:关闭,play:播放,stop:停止,pause:暂停,next:下一曲,prev:上一曲,vol+:音量加,vol-:音量减,muteon:开启静音,muteoff:关闭静音"
}
]
}
],
"tags": []
}
零火单键开关
{
"events": [
{
"id": "report_1",
"name": "子设备状态上报",
"expands": {
"eventType": "reportData",
"level": "ordinary"
},
"valueType": {
"type": "object",
"properties": [
{
"id": "model",
"name": "设备类型",
"valueType": {
"type": "string"
}
},
{
"id": "channel_0",
"name": "开关",
"valueType": {
"type": "string"
}
}
]
}
},
{
"id": "report_2",
"name": "告警上报",
"expands": {
"eventType": "event",
"level": "warn"
},
"valueType": {
"type": "object",
"properties": [
{
"id": "model",
"name": "设备类型",
"valueType": {
"type": "string"
}
},
{
"id": "channel_0",
"name": "开关",
"valueType": {
"type": "string"
}
}
]
}
}
],
"properties": [
{
"id": "channel_0",
"name": "开关状态",
"valueType": {
"type": "string",
"expands": {}
},
"expands": {
"readOnly": "true"
}
}
],
"functions": [
{
"id": "device_discovery_rsp",
"name": "确认添加子设备",
"async": true,
"output": {},
"inputs": [
{
"id": "User_ID",
"name": "用户ID",
"valueType": {
"type": "string"
}
},
{
"id": "status",
"name": "cancel-客户取消添加,OK-确认添加",
"valueType": {
"type": "string"
}
}
]
},
{
"id": "remove_device",
"name": "删除子设备",
"async": false,
"output": {
"type": "string",
"expands": {}
},
"inputs": [
{
"id": "User_ID",
"name": "用户ID",
"valueType": {
"type": "string"
}
}
]
},
{
"id": "read",
"name": "读取子设备",
"async": false,
"output": {
"type": "string",
"expands": {}
},
"inputs": [
{
"id": "User_ID",
"name": "用户ID",
"valueType": {
"type": "string"
}
}
]
},
{
"id": "write",
"name": "开关,on:开,off:关",
"async": true,
"output": {
"type": "string",
"expands": {}
},
"inputs": [
{
"id": "User_ID",
"name": "用户ID",
"valueType": {
"type": "string"
}
},
{
"id": "channel_0",
"name": "channel_0",
"valueType": {
"type": "string"
}
}
]
}
],
"tags": []
}
终端MQTT标准定义
协议标准
读取设备属性
topic: /{productId}/{deviceId}/properties/read
方向: 下行
消息格式:
{
“timestamp”:1601196762389, //毫秒时间戳
“messageId”:”消息ID”,
“deviceId”:”设备ID”,
“properties”:[“sn”,”model”] //要读取到属性列表
}
回复Topic: /{productId}/{deviceId}/properties/read/reply
回复消息格式:
//成功
{
“timestamp”:1601196762389, //毫秒时间戳
“messageId”:”与下行消息中的messageId相同”,
“properties”:{“sn”:”test”,”model”:”test”}, //key与设备模型中定义的属性id一致
“deviceId”:”设备ID”,
“success”:true
}
//失败. 下同
{
“timestamp”:1601196762389, //毫秒时间戳
“messageId”:”与下行消息中的messageId相同”,
“success”:false,
“code”:”error_code”,
“message”:”失败原因”
}
修改设备属性:
topic: /{productId}/{deviceId}/properties/write
方向: 下行
消息格式:
{
“timestamp”:1601196762389, //毫秒时间戳
“messageId”:”消息ID”,
“deviceId”:”设备ID”,
“properties”:{“color”:”red”} //要设置的属性
}
回复Topic: /{productId}/{deviceId}/properties/write/reply
方向: 上行
回复消息格式:
{
“timestamp”:1601196762389, //毫秒时间戳
“messageId”:”与下行消息中的messageId相同”,
“properties”:{“color”:”red”}, //设置成功后的属性,可不返回
“success”:true
}
设备属性上报
topic: /{productId}/{deviceId}/properties/report
方向: 上行
消息格式:
{
“timestamp”:1601196762389, //毫秒时间戳
“messageId”:”随机消息ID”,
“properties”:{“temp”:36.8} //上报数据
}
调用设备功能
topic: /{productId}/{deviceId}/function/invoke
方向: 下行
消息格式:
{
“timestamp”:1601196762389, //毫秒时间戳
“messageId”:”消息ID”,
“deviceId”:”设备ID”,
“function”:”playVoice”,//功能ID
“inputs”:[{“name”:”text”,”value”:”播放声音”}] //参数
}
回复Topic: /{productId}/{deviceId}/function/invoke/reply
方向: 上行
消息格式:
{
“timestamp”:1601196762389, //毫秒时间戳
“messageId”:”与下行消息中的messageId相同”,
“output”:”success”, //返回执行结果,具体类型与物模型中功能输出类型一致
“success”:true,
}
设备事件上报
topic: /{productId}/{deviceId}/event/{eventId}
方向: 上行
消息格式:
{
“timestamp”:1601196762389, //毫秒时间戳
“messageId”:”随机消息ID”,
“data”:100 //上报数据,类型与物模型事件中定义的类型一致
}
子设备注册
与子设备消息配合使用,实现设备与网关设备进行自动绑定.
topic: /{productId}/{deviceId}/child/{childDeviceId}/register
方向: 上行
消息格式:
{
“timestamp”:1601196762389, //毫秒时间戳
“messageId”:”随机消息ID”,
“deviceId”:”子设备ID”
}
子设备注销
与子设备消息配合使用,实现设备与网关设备进行自动解绑.
topic: /{productId}/{deviceId}/child/{childDeviceId}/unregister
方向: 上行
消息格式:
{
“timestamp”:1601196762389, //毫秒时间戳
“messageId”:”随机消息ID”,
“deviceId”:”子设备ID”
}
子设备上线
与子设备消息配合使用,实现关联到网关的子设备上线.(默认情况下,网关上线,子设备也会全部自动上线.)
topic: /{productId}/{deviceId}/child/{childDeviceId}/connected
方向: 上行
消息格式:
{
“deviceId”:”子设备ID”, //毫秒时间戳
“messageId”:”随机消息ID”,
“timestamp”:1584331469964//时间戳
}
子设备离线
与子设备消息配合使用,实现关联到网关的子设备离线.(默认情况下,网关离线,子设备也会全部自动离线.)
topic: /{productId}/{deviceId}/child/{childDeviceId}/disconnect
方向: 上行
消息格式:
{
“timestamp”:1601196762389, //毫秒时间戳
“messageId”:”随机消息ID”,
“timestamp”:1584331469964//时间戳
}
子设备消息
topic: /{productId}/{deviceId}/child/{childDeviceId}/{topic}
方向: 上行或下行, 根据{topic}决定.
TIP
{topic} 以及数据格式与设备topic定义一致. 如: 获取子设备属性: /1/d1/child/c1/properties/read,
自定义协议规范代码:
@Slf4j
public class TopicMessageCodec {
protected DeviceMessage doDecode(String deviceId, String topic, JSONObject payload) {
DeviceMessage message = null;
if (topic.startsWith("/fire_alarm")) {
message = handleFireAlarm(topic, payload);
} else if (topic.startsWith("/fault_alarm")) {
message = handleFaultAlarm(topic, payload);
} else if (topic.startsWith("/register")) {
message = handleRegister(payload);
} else if (topic.startsWith("/unregister")) {
message = handleUnRegister(payload);
} else if (topic.startsWith("/dev_msg")) {
message = handleDeviceMessage(topic, payload);
} else if (topic.startsWith("/device_online_status")) {
message = handleDeviceOnlineStatus(topic, payload);
} else if (topic.startsWith("/read-property")) {
message = handleReadPropertyReply(payload);
} else if (topic.startsWith("/report-property")) { //定时上报属性
message = handleReportProperty(payload);
} else if (topic.startsWith("/write-property")) {
message = handleWritePropertyReply(payload);
} else if (topic.startsWith("/invoke-function")) {
message = handleFunctionInvokeReply(payload);
} else if (topic.startsWith("/open-door")) {
message = handleOpenTheDoor(topic, payload);
} else if (topic.startsWith("/children")) {
ChildDeviceMessage childDeviceMessage = new ChildDeviceMessage();
childDeviceMessage.setDeviceId(deviceId);
DeviceMessage children = doDecode(deviceId, topic.substring(9), payload);
childDeviceMessage.setChildDeviceMessage(children);
childDeviceMessage.setChildDeviceId(children.getDeviceId());
message = childDeviceMessage;
}
// 固件相关1.0.3版本后增加,注意: 专业版中才有固件相关业务功能
else if (topic.startsWith("/firmware/report")) {//上报固件信息
message = payload.toJavaObject(ReportFirmwareMessage.class);
} else if (topic.startsWith("/firmware/progress")) { //上报升级进度
message = payload.toJavaObject(UpgradeFirmwareProgressMessage.class);
} else if (topic.startsWith("/firmware/pull")) { //拉取固件信息
message = payload.toJavaObject(RequestFirmwareMessage.class);
} else if (topic.startsWith("/tags")) { //更新tags
message = payload.toJavaObject(UpdateTagMessage.class);
}
log.info("handle demo message:{}:{}", topic, payload);
return message;
}
protected TopicMessage doEncode(DeviceMessage message) {
if (message instanceof ReadPropertyMessage) {
String topic = "/read-property";
JSONObject data = new JSONObject();
data.put("messageId", message.getMessageId());
data.put("deviceId", message.getDeviceId());
data.put("properties", ((ReadPropertyMessage) message).getProperties());
return new TopicMessage(topic, data);
} else if (message instanceof WritePropertyMessage) {
String topic = "/write-property";
JSONObject data = new JSONObject();
data.put("messageId", message.getMessageId());
data.put("deviceId", message.getDeviceId());
data.put("properties", ((WritePropertyMessage) message).getProperties());
return new TopicMessage(topic, data);
} else if (message instanceof FunctionInvokeMessage) {
String topic = "/invoke-function";
FunctionInvokeMessage invokeMessage = ((FunctionInvokeMessage) message);
JSONObject data = new JSONObject();
data.put("messageId", message.getMessageId());
data.put("deviceId", message.getDeviceId());
data.put("function", invokeMessage.getFunctionId());
data.put("args", invokeMessage.getInputs());
return new TopicMessage(topic, data);
} else if (message instanceof ChildDeviceMessage) {
TopicMessage msg = doEncode((DeviceMessage) ((ChildDeviceMessage) message).getChildDeviceMessage());
if (msg == null) {
return null;
}
String topic = "/children" + msg.getTopic();
return new TopicMessage(topic, msg.getMessage());
}
//平台推送固件更新,设备无需回复此消息.
else if (
message instanceof UpgradeFirmwareMessage ||
message instanceof RequestFirmwareMessageReply
) {
String topic = "/firmware/push";
return new TopicMessage(topic, JSON.toJSON(message));
}
return null;
}
private FunctionInvokeMessageReply handleFunctionInvokeReply(JSONObject json) {
return json.toJavaObject(FunctionInvokeMessageReply.class);
}
private DeviceRegisterMessage handleRegister(JSONObject json) {
DeviceRegisterMessage reply = new DeviceRegisterMessage();
reply.setMessageId(IDGenerator.SNOW_FLAKE_STRING.generate());
reply.setDeviceId(json.getString("deviceId"));
reply.setTimestamp(System.currentTimeMillis());
reply.setHeaders(json.getJSONObject("headers"));
return reply;
}
private DeviceUnRegisterMessage handleUnRegister(JSONObject json) {
DeviceUnRegisterMessage reply = new DeviceUnRegisterMessage();
reply.setMessageId(IDGenerator.SNOW_FLAKE_STRING.generate());
reply.setDeviceId(json.getString("deviceId"));
reply.setTimestamp(System.currentTimeMillis());
return reply;
}
private ReportPropertyMessage handleReportProperty(JSONObject json) {
return json.toJavaObject(ReportPropertyMessage.class);
}
private ReadPropertyMessageReply handleReadPropertyReply(JSONObject json) {
return json.toJavaObject(ReadPropertyMessageReply.class);
}
private WritePropertyMessageReply handleWritePropertyReply(JSONObject json) {
return json.toJavaObject(WritePropertyMessageReply.class);
}
private EventMessage handleFireAlarm(String topic, JSONObject json) {
EventMessage eventMessage = new EventMessage();
eventMessage.setDeviceId(json.getString("deviceId"));
eventMessage.setEvent("fire_alarm");
eventMessage.setMessageId(IDGenerator.SNOW_FLAKE_STRING.generate());
eventMessage.setData(new HashMap<>(json));
return eventMessage;
}
private EventMessage handleOpenTheDoor(String topic, JSONObject json) {
EventMessage eventMessage = new EventMessage();
eventMessage.setDeviceId(json.getString("deviceId"));
eventMessage.setEvent("open-door");
eventMessage.setMessageId(IDGenerator.SNOW_FLAKE_STRING.generate());
eventMessage.setData(new HashMap<>(json));
return eventMessage;
}
private EventMessage handleFaultAlarm(String topic, JSONObject json) {
// String[] topics = topic.split("[/]");
EventMessage eventMessage = new EventMessage();
eventMessage.setDeviceId(json.getString("deviceId"));
eventMessage.setEvent("fault_alarm");
eventMessage.setMessageId(IDGenerator.SNOW_FLAKE_STRING.generate());
eventMessage.setData(new HashMap<>(json));
return eventMessage;
}
private EventMessage handleDeviceMessage(String topic, JSONObject json) {
EventMessage eventMessage = new EventMessage();
eventMessage.setDeviceId(json.getString("deviceId"));
eventMessage.setEvent("dev_msg");
eventMessage.setMessageId(IDGenerator.SNOW_FLAKE_STRING.generate());
eventMessage.setData(new HashMap<>(json));
return eventMessage;
}
private CommonDeviceMessage handleDeviceOnlineStatus(String topic, JSONObject json) {
CommonDeviceMessage deviceMessage;
if ("1".equals(json.getString("status"))) {
deviceMessage = new DeviceOnlineMessage();
} else {
deviceMessage = new DeviceOfflineMessage();
}
deviceMessage.setDeviceId(json.getString("deviceId"));
return deviceMessage;
}
}