On this page
设备连接
一、环境准备
1.测试环境
1
2
3
4
5
6
7
8
9
10
| # ThingsBoard
http://192.168.202.188:8080/login
# Node-RED
http://192.168.202.188:1880
设备名称:Node-RED
访问令牌:8Qgo3kgDRDVTXWtIcnQk
Nodered流程: TB-device
|
2.创建设备

3.创建Node-RED流程

二、上传遥测
1
2
3
4
5
| # 发布主题
v1/devices/me/telemetry
# 访问令牌
8Qgo3kgDRDVTXWtIcnQk
|
1.配置MQTT






2.配置流程


三、属性
1.上传客户端属性
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
| v1/devices/me/attributes
{
"attribute1": "value1",
"attribute2": true,
"attribute3": 42.0,
"attribute4": 73,
"attribute5": {
"someNumber": 42,
"someArray": [1, 2, 3],
"someNestedObject": {
"key": "value"
}
}
}
|





2.下载服务端属性
1
2
3
4
5
6
7
8
9
10
11
| # 订阅一个主题
emqClient.subscribe("v1/devices/me/attributes/response/+", QosEnum.QoS1);
# 发布消息
emqClient.publish("v1/devices/me/attributes/request/1",data, QosEnum.QoS1,false);
# 发布消息请求的属性
{
"clientKeys": "attribute1,attribute2",
"sharedKeys": "shared1,shared2"
}
|
2.1.订阅服务端属性



2.2.发布请求属性




3.订阅共享属性
1
2
3
4
5
6
7
8
9
| //订阅一个主题
emqClient.subscribe("v1/devices/me/attributes", QosEnum.QoS1);
订阅者订阅到了消息,topic=v1/devices/me/attributes,messageid=1,qos=1,
payload=
{
"shared2": 10001
}
|




四、服务端RPC
客户端订阅服务端RPC命令必须SUBSCRIBE消息发送下面主题:
1
| v1/devices/me/rpc/request/+
|
订阅后客户端会收到一条命令作为对相应主题的PUBLISH命令:
1
| v1/devices/me/rpc/request/$request_id
|
$request_id表示请求的整型标识符。
客户端PUBLISH下面主题进行响应:
1
| v1/devices/me/rpc/response/$request_id
|
1.订阅服务端RPC


2.创建仪表板



五、总结
