1 | How to setup an IoT system using ThingsBoard

Francesco Colasante
4 min readMar 25, 2020

In this tutorial you will be able create a cloud-based IoT system which collects information from a set of virtual environmental sensors using the MQTT protocol. You will also create a simple dashboard to display the telemetry-data collected from the sensors.

Everything will be done using Thingsboard, an open-source IoT Platform for Device management, data collection, processing and visualization for your IoT solution.

Setup Thingsboard on-premise with Docker

First of all, you need to install Docker. You can follow this complete guide. After this step you have just to run this command

docker run -it -p 9090:9090 -p 1883:1883 -p 5683:5683/udp -v ~/.mytb-data:/data -v ~/.mytb-logs:/var/log/thingsboard --name mytb --restart always thingsboard/tb-postgres

As a result, now Thingsboard is running exposing 3 different ports on your OS:

  • 1883: used to connect to MQTT broker
  • 9090: used to connect to Web Admin Panel
  • 5683: to connect with CoAP gateway

Ensure that this 3 ports is not busy, otherwise the container cannot start. You can use sudo netstat -tulpn | grep <port> to check it. To check whether the container is working with docker ps .

Thingsboard monolithic architecture

Run the virtual IoT device

In order to emulate an IoT sensor device that collect data, you will create a simple Python script which uses MQTT to exchange data with Thingsboard.

The complete code is available on GitHub at this link. Just clone it and continue the tutorial.

You can use virtualenv (see guide) and install requirements through

pip install -r requirements.txt
fake-iot-device.py

Consequently, rename secrets.example.py into secrets.py and fill it as below.

OpenWeather

In order to have real data, you can use OpenWeather API but you need to sign-up in order to acquire OPEN_WEATHER_TOKEN and change it into fake-iot-dev.py

Open Weather API Key

Thingsboard configuration

Thingsboard can be easily configured with the admin panel available at 127.0.0.1:9090 if your run on Docker, otherwise <YOUR_PUBLIC_IP:8080> .

It is very simple, I created a short video to show you how to configure and how to visualize data.

  1. Create a device
  2. Set rule chain: Input -> Message Type Switch -> Post Telemetry -> Save Timeseries
  3. Create an asset, and set-up outbound relations
  4. Create 2 different aliases
  5. Create 2 dashboards, and setting dashboard handler
  6. Create a Javascript post-processing function to have a user-friendly timestamp visualization.
Setting data post-processing function
How to copy Device Access Token

Once that you have create your first device, copy the ACCESS TOKEN and insert it on secrets.py .
It is important that you do not share this token.

In the figure below you can see the complete dashboard working,

Multi-sensor Thingsboard Dashboard
Dashboard to select a device and aggregated temperature data

Setup Thingsboard on cloud

You can deploy your Thingsboard solution online using Digital Ocean. If you are a student you can acquire your 50$ bonus to Digital Ocean thanks to GitHub Student Dev Pack. Then, you need to follow this guides:

  1. Installing Thingsboard on Digital Ocean: after that you will have configured a Digital Ocean Droplet, an Ubuntu Server machine available on cloud. N.B. Keep note of your public IP to complete to the following steps.
  2. How to Connect your Droplet with OpenSSH: you will access to your new remote machine via SSH.
  3. Installing ThingsBoard CE on Ubuntu Server
  4. Access to your admin panel at <YOUR_PUBLIC_IP>:8080 using default credentials: email:sysadmin@thingsboard.org Password: sysadmin and change credentials. Now your solution is online. YOU MUST to change it.

N.B.: in Docker implementation the admin panel is on 9090 port, while on Digital Ocean droplet is available on port 8080 .

Digital Ocean Droplets

GitHub repository

The complete example and a more detailed tutorial is available on my GitHub repository at https://github.com/fcolasante/thingsboard-tutorial.

My Dashboard

You can access to my Dashboard as customer at this link.
email: customer@thingsboard.org password: customer

Next Steps:

In the next tutorial I will show:

  • how to setup a HTTPS connection to the admin panel
  • how to build a real IoT device using a ESP32 (link) and RIOT-OS (link)

Website: https://francescocolasante.it/

--

--

Francesco Colasante

Sapienza University — Engineering in Computer Science