消息推送
约 980 字大约 3 分钟
2025-03-03
nats默认连接url: nats://127.0.0.1:4222
默认封装结构体
{
"trace":"eyJUcmFjZUlEIjoiMDdjNmY2ZWVlZDM2ODYwNGY5NTdlYmUwZjIzZTY1ZDEiLCJTcGFuSUQiOiJmMTk2ODA4N2Y2NDFhMmQxIiwiVHJhY2VGbGFncyI6IjAxIiwiVHJhY2VTdGF0ZSI6IiIsIlJlbW90ZSI6ZmFsc2V9",
"timestamp":"1670847315923",
"data":"eyJkZXZpY2UiOnsicHJvZHVjdElEIjoiMjU0cHduS1FzdksiLCJkZXZpY2VOYW1lIjoidGVzdDUifSwidGltZXN0YW1wIjoiMTY3MDg0NzMxNTkxOSJ9"
}
字段定义
字段名 | 含义 | 备注 |
---|---|---|
trace | 链路追踪id | base64 |
timestamp | 消息发生时间戳 | 毫秒时间戳(string类型) |
data | 传递的消息内容 | base64 |
设备登录状态推送
topic
application.device.%s.%s.status.connected
设备登录状态推送 中间两个是产品id和设备名称
body
{
"device":{
"productID":"254pwnKQsvK",
"deviceName":"test5"
},
"timestamp":"1670847315919"
}
字段定义
字段名 | 含义 | 备注 |
---|---|---|
device.productID | 产品id | |
device.deviceName | 设备名 | |
timestamp | 设备连接,断连时间 | 毫秒时间戳(string类型) |
设备登出状态推送
topic
application.device.%s.%s.status.disconnected
设备登出状态推送 中间两个是产品id和设备名称
body
{
"device":{
"productID":"254pwnKQsvK",
"deviceName":"test5"
},
"timestamp":"1670847315919"
}
字段定义
字段名 | 含义 | 备注 |
---|---|---|
device.productID | 产品id | |
device.deviceName | 设备名 | |
timestamp | 设备连接,断连时间 | 毫秒时间戳(string类型) |
设备登录状态推送
topic
application.device.%s.%s.status.connected
设备登录状态推送 中间两个是产品id和设备名称
body
{
"device":{
"productID":"254pwnKQsvK",
"deviceName":"test5"
},
"timestamp":"1670847315919"
}
字段定义
字段名 | 含义 | 备注 |
---|---|---|
device.productID | 产品id | |
device.deviceName | 设备名 | |
timestamp | 设备连接,断连时间 | 毫秒时间戳(string类型) |
设备物模型属性多上报通知(v1.3.0+)
topic
application.v2.device.%s.%s.report.thing.property
设备物模型属性上报通知 中间两个是产品id和设备名称
body
{
"device":{
"productID":"254pwnKQsvK",
"deviceName":"test5"
},
"timestamp":"1670850653763",
"identifier":"GPS_Info",
"params":{
"GPS_Info":{
"latitude":0.005,
"longtitude":0.125
},
"swithc": 1
}
}
字段定义
字段名 | 含义 | 备注 |
---|---|---|
device.productID | 产品id | |
device.deviceName | 设备名 | |
timestamp | 设备连接,断连时间 | 毫秒时间戳(string类型) |
params | 推送属性的参数,key为属性标识符 | 和物模型上定义的类型一致 |
设备物模型事件上报通知
topic
application.device.%s.%s.report.thing.event.%s.%s
设备物模型事件上报通知 中间两个是产品id和设备名称,最后两个是事件类型和事件id
body
{
"device":{
"productID":"254pwnKQsvK",
"deviceName":"test5"
},
"timestamp":"1670852257719",
"identifier":"low_power",
"type":"alert",
"params":{
"voltage":2.8
}
}
字段定义
字段名 | 含义 | 备注 |
---|---|---|
device.productID | 产品id | |
device.deviceName | 设备名 | |
timestamp | 设备连接,断连时间 | 毫秒时间戳(string类型) |
identifier | 推送事件的标识符 | |
params | 事件参数 | 和物模型上定义的类型一致 |
type | 事件类型 | 信息:info 告警:alert 故障:fault |
设备物模型属性上报通知
topic
application.device.%s.%s.report.thing.property.%s
设备物模型属性上报通知 中间两个是产品id和设备名称,最后一个是属性id
body
{
"device":{
"productID":"254pwnKQsvK",
"deviceName":"test5"
},
"timestamp":"1670850653763",
"identifier":"GPS_Info",
"param":{
"latitude":0.005,
"longtitude":0.125
}
}
字段定义
字段名 | 含义 | 备注 |
---|---|---|
device.productID | 产品id | |
device.deviceName | 设备名 | |
timestamp | 设备连接,断连时间 | 毫秒时间戳(string类型) |
identifier | 推送属性的标识符 | |
param | 推送属性的参数 | 和物模型上定义的类型一致 |
设备物模型行为上报通知
topic
application.device.%s.%s.report.thing.action.%s.%s.%s
设备物模型行为上报通知 中间两个是产品id和设备名称,最后三个是actionID,请求类型(req resp)和调用方向
body
{
"device":{
"productID":"254pwnKQsvK",
"deviceName":"test5"
},
"msgToken":"1234567890",
"timestamp":"1670852257719",
"actionID":"restart",
"params":{
"delay":5
},
"code":200,
"msg":"success",
"dir":"up",
"reqType":"req"
}
字段定义
字段名 | 含义 | 备注 |
---|---|---|
device.productID | 产品id | |
device.deviceName | 设备名 | |
msgToken | 调用id | 可选字段,用于关联请求和响应 |
timestamp | 行为发生时间 | 毫秒时间戳(string类型) |
actionID | 行为标识符 | 数据模板中的行为标识符,由开发者自行根据设备的应用场景定义 |
params | 参数列表 | 行为参数,和物模型上定义的类型一致 |
code | 请求结果状态 | 200为成功,其他为失败 |
msg | 消息 | 请求结果描述信息 |
dir | 请求方向 | up:设备请求云端 down:云端请求设备 |
reqType | 请求类型 | req:请求 resp:响应 |