联犀 联犀
首页
使用指南
开发指南
技术分享
  • 中台接口 (opens new window)
  • 物联网接口 (opens new window)
在线体验 (opens new window)
  • gitee (opens new window)
  • github (opens new window)
  • 边缘网关-RHILEX (opens new window)
  • 边缘网关-opengw (opens new window)
首页
使用指南
开发指南
技术分享
  • 中台接口 (opens new window)
  • 物联网接口 (opens new window)
在线体验 (opens new window)
  • gitee (opens new window)
  • github (opens new window)
  • 边缘网关-RHILEX (opens new window)
  • 边缘网关-opengw (opens new window)
  • 应用开发

    • 接口导入
    • websocket开发
      • 连接
      • 请求回复结构体格式
        • 订阅消息
        • 请求
        • 回复
        • 具体的订阅说明
        • 推送消息体说明
    • 数据权限
  • 后端开发

  • 开发指南
  • 应用开发
godLei6
2024-08-29
目录

websocket开发

# websocket开发

# 连接

  • 方法: get
  • url: /api/v1/system/common/websocket/connect
  • header参数或url请求里参数:
参数 是否可选 说明
app-code 是 用户正在访问的app
project-id 否 当前正在访问的项目
token 是 用户的token
tenant-code 否 租户号,默认default

连接成功后,云端会回复以下格式的json:

{
  "code": 200,
  "msg": "成功",
  "handler": {
    "Traceparent": "5a21080b0d1d20a372cb9a1c61e19321",
    "connectID": "29"
  }
}
1
2
3
4
5
6
7
8

connectID 是这个连接的唯一ID,后续排查问题都需要根据这个ID来进行排查

# 请求回复结构体格式

{
    "type": "up.sub",
    "body": {
        "code":"devicePropertyReport",
        "params":{
            "productID":"k0sr6A5BMbN",
            "deviceName":"cB05016F7"
        }
    }
}
1
2
3
4
5
6
7
8
9
10

参数说明:

参数 类型 说明
type String 请求及回复的类型由上下行(up,dowm)+具体的方法组成,如up.sub
body boject 具体消息的参数

# 订阅消息

当应用需要订阅某个消息的时候,可以通过以下命令来进行订阅,订阅成功之后,当产生所订阅的消息会直接推送给客户端

# 请求

{
    "type": "up.sub",
    "body": {
        "code":"devicePropertyReport",
        "params":{
            "productID":"k0sr6A5BMbN",
            "deviceName":"cB05016F7"
        }
    }
}
1
2
3
4
5
6
7
8
9
10

参数说明:

参数 类型 说明
type String 固定为 up.sub
body boject 具体消息的参数
body.code string 订阅的
body.params boject 订阅的参数

# 回复

{
    "code": 200,
    "msg": "成功",
    "type": "down.subRet"
}
1
2
3
4
5

参数说明:

参数 类型 说明
type String 固定为 down.subRet
code int 错误码, 200为成功
msg String 消息

# 具体的订阅说明

  1. 物联网相关上报

code说明:

code 说明
devicePropertyReport 设备上报单属性订阅
devicePropertyReportV2 设备上报属性订阅第二版(最小版本: v1.3.0)
devicePublish 设备发布消息
deviceActionReport 设备行为消息
deviceConn 设备连接消息
deviceOtaReport 设备ota消息推送

params说明:

  • 订阅具体属性
{
  "productID": "xxx",
  "deviceName":"xxx",
  "identifier": "xxx"
}
1
2
3
4
5
参数 类型 说明
productID String 产品名称
deviceName String 设备名称
identifier String 属性的ID
  • 订阅设备所有属性
{
  "productID": "xxx",
  "deviceName":"xxx",
}
1
2
3
4
参数 类型 说明
productID String 产品名称
deviceName String 设备名称
  • 订阅项目下所有设备 如果设备数量过多可能会导致推送消息过多,需要慎用
{
  "projectID": "xxx"
}
1
2
3
参数 类型 说明
projectID String 项目ID
  • 订阅某个区域下所有设备 如果设备数量过多可能会导致推送消息过多,需要慎用
{
  "projectID": "xxx",
  "areaID": "xxx"
}
1
2
3
4
参数 类型 说明
projectID String 项目ID
areaID String 区域ID

# 推送消息体说明

  • 设备上报单属性订阅 - devicePropertyReport
{
  "device": {
    "productID": "产品id",
    "deviceName":"设备名称"
  },
  "timestamp":"毫秒时间戳",
  "identifier": "推送属性的标识符",
  "param":{
    "power_switch":1,
    "color":1,
    "brightness":32
  }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
参数 类型 说明
device JSON 设备信息
device.productID String 产品id
device.deviceName String 设备名称
timestamp String 毫秒时间戳
identifier String 推送属性的标识符
param any 上报的参数,如果是json类型为对象
param.power_switch Boolean 布尔型属性的值一般为0或1
param.color Enum 枚举整型属性的值为整数值,数值类型填写错误或超过枚举项定义范围出现406返回码,表示物模型格式校验错误
param.brightness Integer 整数型属性的值为整数值,数值类型填写错误或超过数值范围会出现406返回码,表示物模型格式校验错误
  • 设备上报属性订阅第二版(最小版本: v1.3.0) - devicePropertyReportV2
{
  "device": {
    "productID": "产品id",
    "deviceName":"设备名称"
  },
  "timestamp":"毫秒时间戳",
  "params":{
    "power_switch":1,
    "color":1,
    "brightness":32
  }
}
1
2
3
4
5
6
7
8
9
10
11
12
参数 类型 说明
device JSON 设备信息
device.productID String 产品id
device.deviceName String 设备名称
timestamp String 毫秒时间戳
identifier String 推送属性的标识符
params Json 上报的参数,key为推送属性的标识符,value为属性的值
  • 设备发布消息 - devicePublish
{
  "productID": "xxx",
  "deviceName":"xxx",
  "content": "xxx",
  "topic":"xxx",
  "action": "xxx",
  "timestamp":"xxx",
  "requestID": "xxx",
  "traceID":"xxx",
  "resultCode": 200,
  "respPayload":"xxx"
}
1
2
3
4
5
6
7
8
9
10
11
12
参数 类型 说明
productID String 产品id
deviceName String 设备名称
content String 具体信息
topic String 主题
action String 操作类型
timestamp String 操作时间,
requestID String 请求ID
traceID String 服务器端事务id
resultCode String 请求结果状态,200为成功
respPayload String 返回的内容
  • 设备行为消息 - deviceActionReport
{
  "device": {
    "productID": "产品id",
    "deviceName":"设备名称"
  },
  "msgToken": "xx",
  "timestamp":"xx",
  "actionID": "xx",
  "params":{
    "power_switch":1,
    "color":1,
    "brightness":32
  },
  "code": 200,
  "msg":"xxx",
  "dir": "up",
  "reqType":"req"
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
参数 类型 说明
device JSON 设备信息
device.productID String 产品id
device.deviceName String 设备名称
timestamp String 毫秒时间戳
actionID String 行为的标识符
params JSON JSON结构内为设备上报的属性值
params.power_switch Boolean 布尔型属性的值一般为0或1
params.color Enum 枚举整型属性的值为整数值,数值类型填写错误或超过枚举项定义范围出现406返回码,表示物模型格式校验错误
params.brightness Integer 整数型属性的值为整数值,数值类型填写错误或超过数值范围会出现406返回码,表示物模型格式校验错误
code String 200为成功
msg String 消息
dir String 请求方向 up:设备请求云端 down:云端请求设备
reqType String 请求类型 req resp
  • 设备连接消息 - deviceConn
{
  "device": {
    "productID": "产品id",
    "deviceName":"设备名称"
  },
  "timestamp":"毫秒时间戳",
  "status": 1
}
1
2
3
4
5
6
7
8
参数 类型 说明
device JSON 设备信息
device.productID String 产品id
device.deviceName String 设备名称
timestamp String 毫秒时间戳
status Integer 1:在线 2:离线
  • 设备ota消息推送 - deviceOtaReport
{
  "device": {
    "productID": "产品id",
    "deviceName":"设备名称"
  },
  "timestamp":"毫秒时间戳",
  "status": 1,
  "detail": "",
  "step":10
}
1
2
3
4
5
6
7
8
9
10
参数 类型 说明
device JSON 设备信息
device.productID String 产品id
device.deviceName String 设备名称
timestamp String 毫秒时间戳
status Integer 1:在线 2:离线
detail String 详情
step Integer 当前的升级进度 0-100% -1:升级失败。-2:下载失败。-3:校验失败。-4:烧写失败。
上次更新: 2025/01/08, 20:17:34
接口导入
数据权限

← 接口导入 数据权限→

Theme by Vdoing | Copyright © 2022-2025 昆明云物通科技有限公司|GNU | 滇ICP备2024043132号-1 |
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式