How to Access MQTT Data with ThingsBoard

Preparation

Since we are using ThingsBoard Cloud, we do not need to download and install it. We just need to register and login at https://thingsboard.cloud/signup to get the service. In addition to the ThingsBoard Cloud service, you can also choose to download and install a private deployment.

Integration

Using EMQX Cloud

1.Get the connection address and port. Wait for the instance status to change to Running on the deployment [Overview] page and find the connection address and connection port corresponding to the MQTT protocol. These are needed later when adding integrations in ThingsBoard.

Configure ThingsBoard

1.Add a new Uplink type data converter in [Data converters]. The role of this uplink data converter is to parse the payload of incoming messages and convert these to the format used by ThingsBoard.

// Decode an uplink message from a buffer
// payload - array of bytes
// metadata - key/value object
// decode payload to json
var payloadJson = decodeToJson(payload);
var result = {
deviceName: payloadJson.deviceName,
attributes: {
model: 'Model A',
serialNumber: 'SN111',
integrationName: metadata['integrationName']
},
telemetry: {
temperature: payloadJson.temperature,
humidity: payloadJson.humidity,
}
};
// Helper functions
function decodeToString(payload) {
return String.fromCharCode.apply(String, payload);
}
function decodeToJson(payload) {
// covert payload to string.
var str = decodeToString(payload);
// parse string to JSON
var data = JSON.parse(str);
return data;
}
return result;

Integration Test

After completing the above integration configuration, use the MQTT 5.0 client tool, MQTT X, to simulate a device, in order to test and verify the effectiveness of the functionality.

  1. Use MQTT X to connect to the EMQX Cloud deployment.
{
"deviceName": "Device Test",
"temperature": 28,
"humidity": 70,
}

Customizing Dashboard to access the MQTT data

1.Click on the [Dashboard groups] menu, select [All] and click [+] to Add a new dashboard. Give it a name and click Add.

Summary

At this point, we have finished integrating the EMQX Cloud deployment in ThingsBoard Cloud, verified the integration functionality using MQTT X tests, and finally configured a simple Dashboard to display the MQTT data. In real projects, more complex Dashboard configurations can be performed after learning more about ThingsBoard. This will allow you to visually monitor device-related data in real-time detail and set alert thresholds to help you resolve issues in a timely manner.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
EMQ Technologies

EMQ Technologies

EMQ is an open-source IoT data infrastructure software provider, delivering the world’s leading open-source MQTT message broker and stream processing database.