安装指南:
https://thingsboard.io/docs/user-guide/install/installation-options/
1.初识
thingsboard安装在服务器中后,已经自带了mqtt服务器,不要在安装mqtt服务器
设备:设备凭证中使用access token
真实设备采集数据后,可以通过mqtt上传至此设备,通过access token识别。例如我们通过Mqtt fx客户端发送数据模拟的时候user name就是这个access token,密码不需要。
2.测试
thingsboard一般需要配合thingsboard-gateway网关
安装:https://github.com/thingsboard/thingsboard-gateway/releases/tag/2.7
网关中MQTT配置,broker代表自己部署的MQTT服务器,不是thingsboard中的MQTT
{
"broker": {
"name":"MQTT Broker Connector",
"host":"192.168.1.99",
"port":1883,
"clientId": "ThingsBoard_gateway",
"security": {
"type": "basic",
"username": "flight",
"password": "flight"
}
},
"mapping": [
{
"topicFilter": "/sensor/data",
"converter": {
"type": "json",
"deviceNameJsonExpression": "${serialNumber}",
"deviceTypeJsonExpression": "${sensorType}",
"timeout": 60000,
"attributes": [
{
"type": "string",
"key": "model",
"value": "${sensorModel}"
},
{
"type": "string",
"key": "${sensorModel}",
"value": "on"
}
],
"timeseries": [
{
"type": "double",
"key": "temperature",
"value": "${temp}"
},
{
"type": "double",
"key": "humidity",
"value": "${hum}"
}
]
}
},
{
"topicFilter": "/sensor/+/data",
"converter": {
"type": "json",
"deviceNameTopicExpression": "(?<=sensor\/)(.*?)(?=\/data)",
"deviceTypeTopicExpression": "Thermometer",
"timeout": 60000,
"attributes": [
{
"type": "string",
"key": "model",
"value": "${sensorModel}"
}
],
"timeseries": [
{
"type": "double",
"key": "temperature",
"value": "${temp}"
},
{
"type": "double",
"key": "humidity",
"value": "${hum}"
}
]
}
},
{
"topicFilter": "/custom/sensors/+",
"converter": {
"type": "custom",
"extension": "CustomMqttUplinkConverter",
"extension-config": {
"temperatureBytes" : 2,
"humidityBytes" : 2,
"batteryLevelBytes" : 1
}
}
}
],
"connectRequests": [
{
"topicFilter": "sensor/connect",
"deviceNameJsonExpression": "${SerialNumber}"
},
{
"topicFilter": "sensor/+/connect",
"deviceNameTopicExpression": "(?<=sensor\/)(.*?)(?=\/connect)"
}
],
"disconnectRequests": [
{
"topicFilter": "sensor/disconnect",
"deviceNameJsonExpression": "${SerialNumber}"
},
{
"topicFilter": "sensor/+/disconnect",
"deviceNameTopicExpression": "(?<=sensor\/)(.*?)(?=\/disconnect)"
}
],
"attributeUpdates": [
{
"deviceNameFilter": "SmartMeter.*",
"attributeFilter": "uploadFrequency",
"topicExpression": "sensor/${deviceName}/${attributeKey}",
"valueExpression": "{\"${attributeKey}\":\"${attributeValue}\"}"
}
],
"serverSideRpc": [
{
"deviceNameFilter": ".*",
"methodFilter": "echo",
"requestTopicExpression": "sensor/${deviceName}/request/${methodName}/${requestId}",
"responseTopicExpression": "sensor/${deviceName}/response/${methodName}/${requestId}",
"responseTimeout": 10000,
"valueExpression": "${params}"
},
{
"deviceNameFilter": ".*",
"methodFilter": "no-reply",
"requestTopicExpression": "sensor/${deviceName}/request/${methodName}/${requestId}",
"valueExpression": "${params}"
}
]
}
3.Topic主题映射过滤器
例如:主题为/sensor/TestDevice/data,实际在java中测试发送的主题(.替换/)Topic:.sensor.TestDevice.data
发送数据
{ “sensorType”: “Thermometer”,“sensorModel”:“T1000”, “temp”:75256,“hum”:75257}
设备发送数据到MQTT服务器后,在仪表板可以看到数据如下