Creating an IOT or MQTT Dashboard Using Thingsboard

mqtt-dashboard-iconThingsboard is an open source IOT platform for data visualization.

It is available for download and installation on your own hardware or as an online service for demonstration purposes.

In this tutorial we will configure a simple Dashboard to display data from sensors using MQTT and Python.

There are two sensors, a main door sensor and a main light sensor. Our final demo dashboard will appear like this


The first step is to create your own demo account by signing up here.

Once you have an account and have verified it you can login to thingsboard here.

Process Overview

  • Create device or devices
  • Assign device to Widget
  • Assign Widget to Dashboard
  • Add new widgets and edit as necessary

The diagram below illustrates the process:


The first thing you need to create is a device.

Go to devices and click on the add device circle in the lower right hand corner


You will need to give the device a name and add a description. Leave the is gateway box un-checked.


Click ADD when done.

Now click on the device card to edit the device, and then click the tick icon to display and edit the device properties.


Each device is assigned an access token which is used by the device to identify itself to the thingsboard platform.

You will need to copy this access token for use in your MQTT client. You can do this using the copy access token tab.


Or by clicking on the manage credentials tab


The access token you will use as the username in MQTT. There is no password.

The actual physical device is responsible for sending data to thingsboard.

All data is sent to the following topic id:


Note: A device need not be a single device like a sensor as devices publish data as a JSON object.

The device client attributes can be used to manage the device, but these must first be populated by the client. We will not be using device attributes in this tutorial.

The device is now usable and can receive data.

If you follow the introduction on the thingsboard website they use a Javascript client and Node.js to send data.

In this tutorial we will send data using MQTT and a Python client.

Configuring The Python Client

We need to configure the following:

username= access token
password=”” #not used

We also need to package the data in a dictionary object and then convert it to a JSON encoded string to output

Here is my demo script (partial) that simply simulates a light sensor and a door sensor.


The light is either on or off, and the door is either open or closed.

When I run the script this is what I see on the console.


To view the results on the device in thingsboard go the device telemetry tab.


To visualize data from this device we need to configure a dashboard and a display widget.

We start by adding the device to a widget.

To add this device to a widget click on the check box next to last update time


Now select the widget type (cards) and then use the small circles to select the card type, and then click add to dashboard.


You can now add the widget to an existing dashboard or create a new dashboard.


If you tick the checkbox to open the dashboard, when you click ADD the dashboard will open and display the widget.


Adding A new Widget to the Dashboard

To add a new widget or edit the dashboard click on the edit (pencil) icon in the lower right corner of the dashboard.

When adding a new widget you first need to select the type of widget.


Now you need to select a data source for the Widget.

thingsboard-add-new-widget-datasourceNow configure the datasource. In the example below our datasource is called house which is the name of the device we configured earlier and we select the main-light property. The Main-door property we added to our first widget.


Now you can edit the card settings and change colour and fonts etc.


When finished the new widget appears on the screen.


As long as the edit icons are showing you can rearrange and edit widgets on the dashboard.

When finished click on the tick icon.


Making the Dashboard Public

You can also make the dashboard public which makes it visible to everyone.


Sending Test Data Using Mosquitto_pub Tool

You can send test data using MQTT and the mosquitto_ pub tool.
You need:

  • Your access token for the username -Ahwpx1r8fNNQbr9JILm3
  • Broker name
  • topic -v1/devices/me/telemetry
  • JSON Data -“{\”main-light\”:\”OFF \”,\”main-Door\”:\”CLOSED\”}”

Command shown below:

mosquitto_pub -h -u Ahwpx1r8fNNQbr9JILm3 -t v1/devices/me/telemetry -m "{\"main-light\":\"OFFs \",\"main-Door\":\"CLOSED\"}"

Sending Test Data Using cURL

You can publish data to Thingsboard using http and curl.

The thingsboard website give the various formats supported and example curl commands.

Unfortunately these didn’t work on windows until I escaped the quotes on the data keys and values.

The format I used was the simple format

{"key1":"value1", "key2":"value2"}

The data needs to be JSON encoded .

The ThingsBoard dashboard has two devices a light and door. The JSON data looks like this

“{, \”main-light\”:\”OFF \”,\”main-Door\”:\”OPEN\”}”

Notice I had to escape the quotes around the keys and values.

Here is a command example


Video -Creating an MQTT (IOT) Dashboard Using Thingsboard

Here is my demo test house dashboard that I created in the video tutorial. You can download the python scripts used in the video here.


Related Tutorials:

Please rate? And use Comments to let me know more
[Total: 4    Average: 5/5]


  1. Sir,
    Can you tell me which python script did you use? Because the one I use, thingsboard-1, I get errors:

    Traceback (most recent call last):
    File “”, line 34, in
    File “C:\Users\Korisnik\AppData\Local\Programs\Python\Python36-32\lib\site-packages\paho\mqtt\”, line 839, in connect
    return self.reconnect()
    File “C:\Users\Korisnik\AppData\Local\Programs\Python\Python36-32\lib\site-packages\paho\mqtt\”, line 962, in reconnect
    sock = socket.create_connection((self._host, self._port), source_address=(self._bind_address, 0))
    File “C:\Users\Korisnik\AppData\Local\Programs\Python\Python36-32\lib\”, line 704, in create_connection
    for res in getaddrinfo(host, port, 0, SOCK_STREAM):
    File “C:\Users\Korisnik\AppData\Local\Programs\Python\Python36-32\lib\”, line 745, in getaddrinfo
    for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
    socket.gaierror: [Errno 11001] getaddrinfo failed

    Or is there any previous tutorial about connecting sensor to platform via MQTT? And, do you use sensor for real? Or is this just demo version?

    Best r, Milica

  2. Hi,
    First of all, thanks for this very helpful and clear tutorial. This IOT platform seems really appropriated for what I intend to do. However, I want to use a Pycom device (don’t know if you’ve heard about it) to communicate with Thingsboard through MQTT. I found the following module on Github ( which seemed quite OK. However, I am still confused with all the parameters required, to create a client object with the _init_ function and how to adapt it with the credentials provided by one of the devices I created on Thingsboard. Or maybe, could you please provide me with the module/library and the methods you are using? Not sure if I am being clear, but thanks a lot for helping.

    1. From looking at the code all you need is the client name and broker name/address. What credentials are you referring to?
      On things board each device as an ID which you use for the username password is blank.
      use the form
      client =(name,server,username=xxx)

  3. Hi Steve, thank you for this tutorial, it is very good.
    I have some experience with Thingboard, but I have a problem when I want to set up values from the dashboard with a widget, I use Knob Control from Control Widgets but it is not very useful, because it sends many values before you reach the value that you want.

    Do you have any idea how can I do ?

    1. I know what you mean. There is currently no way that I can see of preventing this unless you change the widget code. I haven’t tried doing that but hopefully will one day.
      You could catch it on the receive side but it depends on what you are sending it to.

  4. So It is already going. The problem was in writing data as a text. When I change in script data from On/Off to 1/0, chart is correct.

  5. Yeah, but when you run your demo script and you want state chart from this script you will nothing. At least I cant display any telemetry data:/

  6. Hello,
    first a I would like to say thank you. Your tutorial is a great.
    But now I have problem with creating chart from this data. When I create state chart I see nothing. So I think the problem will be in saving data to cassandra database, but in Timeseries table is all data.
    Can you help me with this problem?

Leave a Reply

Your email address will not be published. Required fields are marked *