Thingsboard Gateway
一、 Topic
网关设备注册
- topic
v1/gateway/connect
- 说明:设备上线通知(如果云平台没有对应设备会根据device自动注册一个)
- 参数说明:
device: 为设备名称 type: 设备类型
{
"device": "SN-001",
"type": "default"
}
网关设备下线
- Topic
v1/gateway/disconnect
- 说明:设备下线通知通知(一旦收到,ThingsBoard 将不再向此网关发布该特定设备的更新)
- 参数说明:
device: 为设备名称 type: 设备类型
{
"device": "SN-001"
}
更新网关设备属性
更新属性
- topic
v1/gateway/attributes
- 说明:
允许设备将客户端设备属性上传到服务器。
从服务器请求客户端和共享设备属性。
从服务器订阅共享设备属性。
将属性更新发布到服务器
为了将客户端设备属性发布到 ThingsBoard 服务器节点,请向以下主题发送 PUBLISH 消息 - 参数说明:
SN-001、SN-002: 为设备名称
{
"SN-001": {
"attribute1": "value1",
"attribute2": 42
},
"SN-002": {
"attribute1": "value1",
"attribute2": 42
}
}
从服务器请求属性值
- topic
v1/gateway/attributes/request
- 说明:
允许设备将客户端设备属性上传到服务器。
从服务器请求客户端和共享设备属性。
从服务器订阅共享设备属性。
将属性更新发布到服务器
为了将客户端设备属性发布到 ThingsBoard 服务器节点,请向以下主题发送 PUBLISH 消息 - 参数说明:
SN-001、SN-002: 为设备名称
{
"id": $request_id,
"device": "SN-001",
"client": true,
"key": "attribute1"
}
其中$request_id是整数请求标识符,SN-001是设备名称,client标识客户端或共享属性范围,key是属性键。
在发送 PUBLISH 消息之前,客户端需要订阅v1/gateway/attributes/response
{
"id": $request_id,
"device": "SN-001",
"value": "value1"
}
遥测上传
- Topic
v1/gateway/telemetry
- 说明:将设备遥测数据发布到 ThingsBoard 服务器节点
允许设备将客户端设备属性上传到服务器。
从服务器请求客户端和共享设备属性。
从服务器订阅共享设备属性。
将属性更新发布到服务器
为了将客户端设备属性发布到 ThingsBoard 服务器节点,请向以下主题发送 PUBLISH 消息 - 参数说明:
其中设备SN-001、SN-002 为设备名称,温度和湿度是遥测数据,ts是以毫秒为单位的 unix 时间戳。
{
"SN-001": [
{
"ts": 1483228800000,
"values": {
"temperature": 42,
"humidity": 80
}
},
{
"ts": 1483228801000,
"values": {
"temperature": 43,
"humidity": 82
}
}
],
"SN-002": [
{
"ts": 1483228800000,
"values": {
"temperature": 42,
"humidity": 80
}
}
]
}
RPC服务接口
订阅来自服务器的 RPC 命令:v1/gateway/rpc
云平台RPC参数:
{
"device": "SN-001",
"data": {
"id": $request_id,
"method": "toggle_gpio",
"params": {
"pin": 1
}
}
}
一旦设备处理了命令,网关需要使用以下格式发回命令
{
"device": "SN-001",
"id": $request_id,
"data": {
"success": true
}
}
官方文档:https://thingsboard.io/docs/reference/gateway-mqtt-api/
联系我,微信:122811041