一、环境准备
1.测试环境
1
2
3
4
5
6
7
8
9
10
11
12
13
# ThingsBoard
http://192.168.202.188:8080/login
# EMQX
http://192.168.202.189:18083
# Node-RED
http://192.168.202.188:1880
设备名称:Node-RED-mqtt
访问令牌:5eUOggpjfPsvUPUUJ0U5
Nodered流程: TB-mqtt
2.创建设备
3.创建Node-RED流程
4.MQTTX
二、上传遥测
1.配置Node-RED流程
1
2
3
4
5
# 发布主题
v1/devices/me/telemetry
# 访问令牌
8Qgo3kgDRDVTXWtIcnQk
配置上传遥测
配置emqx
2.EMQX发送数据
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
v1/devices/me/telemetry
{
"stringKey": "value1",
"booleanKey": true,
"doubleKey": 42.0,
"longKey": 73,
"jsonKey": {
"someNumber": 42,
"someArray": [1, 2, 3],
"someNestedObject": {
"key": "value"
}
}
}
三、订阅共享属性
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
}