Skip to content

半实物设备通信协议

类型定义

设备类型

设备名称添加版本
所有设备2550
风扇10
喷气20
热感30
音震40
电梯50
60
阀门70
发射器80
手电筒90
按钮100
开关110
喷淋120
气味131
旋钮142

消息类型

消息类型添加版本
获取设备列表10
开启20
关闭30
重置40
移动50
预设60
设备列表1000
开关状态1010
角度状态1020
预设状态1031
数字状态1042

设备-消息映射表

获取设备列表[1]开启[2]关闭[3]重置[4]移动[5]预设[6]设备列表[100]开关状态[101]角度状态[102]预设状态[103]数字状态[104]
所有设备[255]
风扇[1]
喷气[2]
热感[3]
音震[4]
电梯[5]
门[6]
阀门[7]
发射器[8]
手电筒[9]
按钮[10]
开关[11]
喷淋[12]
气味[13]
旋钮[14]

UDP 广播连接

客户端发送广播消息

端口 33666

json
{
  "type": 1,
  "name": "xxx",
  "protocol": "tcp"
}

中控端回应消息

json
{
  "type": 2,
  "ip": "x.x.x.x",
  "tcp_port": 33600,
  "version": 1
}
  • 如果ip0.0.0.0则需要客户端通过解析 UDP 包的源地址来获取中控 IP
  • 如果检测不到version 字段,则默认为 0

TCP 通信

消息结构

字段长度默认值含义
flag4Byte0xCACACACA固定值
length4Byte消息体长度
datalength消息体(Json 格式)

消息类型

获取设备列表【1】

会触发设备列表消息[100]

参数类型添加版本默认值含义
device_typeint0255设备类型
msg_typeint01消息类型

示例

json
{
  "device_type": 255,
  "msg_type": 1
}

开启【2】

可能触发开关状态消息[101]

参数类型添加版本默认值含义
device_typeint0设备类型
msg_typeint02消息类型
snstring0设备 SN 号
indexint1-1子设备索引,-1 代表无效

示例

json
{
  "device_type": 1,
  "msg_type": 2,
  "sn": "xxx",
  "index": -1
}

关闭【3】

可能触发开关状态消息[101]

参数类型添加版本默认值含义
device_typeint0设备类型
msg_typeint03消息类型
snstring0设备 SN 号
indexint1-1子设备索引,-1 代表无效

示例

json
{
  "device_type": 1,
  "msg_type": 3,
  "sn": "xxx",
  "index": -1
}

重置【4】

参数类型添加版本默认值含义
device_typeint0设备类型
msg_typeint04消息类型
snstring0设备 SN 号

示例

json
{
  "device_type": 5,
  "msg_type": 4,
  "sn": "xxx"
}

移动【5】

参数类型添加版本默认值含义
device_typeint0设备类型
msg_typeint05消息类型
snstring0设备 SN 号
dataobject0移动结构体
  • data
参数类型添加版本默认值含义
height_mmint0高度(毫米)
pitch_radianfloat0偏航角(弧度)
roll_radianfloat0翻滚角(弧度)
time_msint0时间(毫秒)

示例

json
{
  "device_type": 5,
  "msg_type": 5,
  "sn": "xxx",
  "data": {
    "height_mm": 1000,
    "pitch_radian": 0.39,
    "roll_radian": 0.39,
    "time_ms": 100
  }
}

预设【6】

参数类型添加版本默认值含义
device_typeint0设备类型
msg_typeint06消息类型
snstring0设备 SN 号
namestring0预设名称
enablebool0开始/停止预设

示例

json
{
  "device_type": 5,
  "msg_type": 6,
  "sn": "xxx",
  "name": "预设名称",
  "enable": true
}

设备列表【100】

TCP 连接成功后,硬件中控会自动发送一次该消息

设备上下线以后,也会触发该消息

参数类型添加版本默认值含义
device_typeint0255设备类型
msg_typeint1100消息类型
devicesarray0设备列表
  • 开关设备(风扇、喷气、热感、音震、发射器、手电筒、按钮、开关、喷淋)
json
{
  "sn": "xxx",
  "device_type": 1,
  "online": true,
  "enabled": true,
  "pressed": true
}
  • 角度设备(门、阀门)
json
{
  "sn": "xxx",
  "device_type": 6,
  "online": false,
  "angle": 45.0
}
  • 电梯设备(电梯)
json
{
  "sn": "xxx",
  "device_type": 5,
  "online": false,
  "min_pitch_radian": -0.39,
  "max_pitch_radian": 0.39,
  "min_roll_radian": -0.39,
  "max_roll_radian": 0.39,
  "min_height_mm": -50,
  "max_height_mm": 50,
  "presets": [
    "高频震动-短促",
    "高频震动-持续",
    "上下晃动-短促",
    "上下晃动-持续",
    "左右晃动-短促",
    "左右晃动-持续",
    "突然下坠",
    "突然上顶"
  ],
  "floor_height_mm": -50
}
  • 气味设备(气味)
json
{
  "sn": "xxx",
  "device_type": 1,
  "online": true,
  "num_port": 12,
  "enabled": [
    false,
    false,
    false,
    false,
    false,
    false,
    false,
    false,
    false,
    false,
    false,
    false
  ]
}
  • 数字设备(旋钮)
json
{
  "sn": "xxx",
  "device_type": 14,
  "online": true,
  "range": [0, 5],
  "step": 1
}

示例

json
{
  "device_type": 255,
  "msg_type": 100,
  "devices": [
    {
      "sn": "开关设备",
      "device_type": 1,
      "online": true,
      "enabled": true,
      "pressed": true
    }
  ]
}

开关状态【101】

参数类型添加版本默认值含义
device_typeint0设备类型
msg_typeint1101消息类型
snstring0设备 SN 号
onlinebool0是否在线
pressedbool0与`enabled`保持一致开关状态
indexint1-1子设备索引
enabledbool1开关状态

示例

json
{
  "device_type": 1,
  "msg_type": 101,
  "sn": "xxx",
  "online": true,
  "pressed": true,
  "index": -1,
  "enabled": true
}

角度状态【102】

参数类型添加版本默认值含义
device_typeint0设备类型
msg_typeint1102消息类型
snstring0设备 SN 号
onlinebool0是否在线
anglefloat0角度(角度)

示例

json
{
  "device_type": 6,
  "msg_type": 102,
  "sn": "xxx",
  "online": true,
  "angle": 45.0
}

预设状态【103】

参数类型添加版本默认值含义
device_typeint1设备类型
msg_typeint1103消息类型
snstring1设备 SN 号
stateint1状态
presetstring1预设名称
  • state
    • 1 预设开始
    • 2 预设结束

示例

json
{
  "device_type": 5,
  "msg_type": 103,
  "sn": "xxx",
  "state": 1,
  "preset": "高频震动"
}

数字状态【104】

参数类型添加版本默认值含义
device_typeint2设备类型
msg_typeint2104消息类型
snstring2设备 SN 号
stateint2数字状态

示例

json
{
  "device_type": 14,
  "msg_type": 104,
  "sn": "xxx",
  "state": 1,
}