ThingsBoard and Raspberry PI (part 1): getting a Professional IoT dashboard
Last Updated on 2nd September 2023 by peppe8o
In this tutorial, I’m going to show you how to install ThingsBoard on Raspberry PI computer boards.
IoT devices can collect a lot of environment data that you have to manage, rearrange and show. ThingsBoard on Raspberry PI lets you create amazing dashboards getting data from a wide number of devices
ThingsBoard features
ThingsBoard is an Open Source platform allowing you to easily manage IoT devices, collect data and create amazing dashboards for your IoT projects. You can also set triggers with connected notifications or general reactions, in order to manage outages or issues in real-time.
The official ThingsBoard page shows as common use case Device Metering, Energy Management, Smart Farming and Fleet Tracking, but it has a so versatile structure that the only limit to its usage fields is your imagination.
Finally, the following gives you a brief list of ThingsBoard features, but you can refer ThingsBoard official page for more details:
- Collect and store telemetry data in reliable way, surviving network and hardware failures.
- Support multi-tenant installations out-of-the-box
- Provides 30+ configurable widgets out-of-the-box and ability to create your own widgets using built-in editor
- Amount of supported server-side requests and devices increase linearly as new thingsboard servers are added in clustering mode
- Process incoming device data with flexible rule chains based on entity attributes or message content. Forward data to external systems or trigger alarms using custom logic.
- Allows to monitor client-side and provision server-side device attributes. Provides API for server-side applications to send RPC commands to devices and vice-versa.
- Supports transport encryption for both MQTT and HTTP(s) protocols.
- Provides ability to register and manage assets.
- Extend default platform functionality using customizable rule chains, widgets and transport implementations.
- ThingsBoard is licensed under Apache License 2.0, so you can use any it in your commercial products for free.
- Offers a Cloud implementation with managed services
The following procedure starts from the ThingsBoard install guide for Raspberry PI, but adding RPI specific tricks to make your setup more performant. For this tutorial, I’m going to use a Raspberry PI 3 Model B+ computer board, but this also applies to all newer Raspberry PI computer boards.
What We Need
As usual, I suggest adding from now to your favourite e-commerce shopping cart all the needed hardware, so that at the end you will be able to evaluate overall costs and decide if continue with the project or remove them from the shopping cart. So, hardware will be only:
- Raspberry PI 3 Model A+ (including proper power supply or using a smartphone micro usb charger with at least 3A) or newer Raspberry PI Board
- high speed micro SD card (at least 16 GB, at least class 10)
Check hardware prices with the following links:
Step-by-Step Procedure
Prepare Operating System
Start with a fresh Raspberry PI OS Lite installation to get a fast Operating System.
Make sure that your OS is updated. From terminal, please use the following command:
sudo apt update -y && sudo apt upgrade -y
We also need to install Java. From terminal:
sudo apt install openjdk-11-jdk -y
The official guide also tells to execute the “sudo update-alternatives –config java”, but I found that current Raspberry PI OS Lite doesn’t require it as it doesn’t have any other Java alternative installed:
pi@raspberrypi:~ $ sudo update-alternatives --config java
There is only one alternative in link group java (providing /usr/bin/java): /usr/lib/jvm/java-11-openjdk-armhf/bin/java
Nothing to configure.
Test Java:
pi@raspberrypi:~ $ java -version
openjdk version "11.0.13" 2021-10-19
OpenJDK Runtime Environment (build 11.0.13+8-post-Raspbian-1deb11u1)
OpenJDK Server VM (build 11.0.13+8-post-Raspbian-1deb11u1, mixed mode)
Before proceeding with Thingsboard installation, let’s get some further optimizations specific to Raspberry PI.
The first one is to increase available RAM: as we use a Lite installation without a desktop environment, we can put to minimal value (16MB) the GPU RAM. For this, please refer to my Manage Raspberry PI GPU Memory Split tutorial.
The second optimization, still on RAM, we’ll increase SWAP memory for Raspberry PI in order to leverage RAM usage with additional space from SD. This will make us able to assign more RAM to java process without risking Thingsboard to crash. In this case, please refer to my Set Raspberry PI Swap Memory tutorial to set Swap memory to 1000.
Install ThingsBoard
We need to download the .deb file from ThingsBoard website:
wget https://github.com/thingsboard/thingsboard/releases/download/v3.3.2/thingsboard-3.3.2.deb
And now we can install it:
sudo dpkg -i thingsboard-3.3.2.deb
At this point ThingsBoard is installed but not active. We have to make some more setup to make it running.
Install and Setup PostgreSQL
The supported database for ThingsBoard is PostgreSQL. Install it with the following command:
sudo apt install postgresql
As the default installation comes with an empty password and we’ll need a password for ThingsBoard application properties, we have to change it. The following commands sequence will help to set a new one for the postgres user:
sudo su - postgres
psql
\password
\q
In the following I will refer to this password as “My_PostgreSQL_Password”. Once finished, type “exit” to go back into “pi” shell.
Now, let’s create the empty ThingsBoard database. Use the following commands, row by row:
psql -U postgres -d postgres -h 127.0.0.1 -W
CREATE DATABASE thingsboard
\q
Finally, we can exit from postgres shell:
exit
Configure ThingsBoard Properties
Now, we need to set ThingsBoard config file to keep database reference and to limit Java memory allocation (in order to avoid RAM crashes). From terminal:
sudo nano /etc/thingsboard/conf/thingsboard.conf
Append the following lines to the configuration file. Please remember to change the password below (in red) with the one you set for PostgreSQL in the previous step:
# DB Configuration
export DATABASE_TS_TYPE=sql
export SPRING_JPA_DATABASE_PLATFORM=org.hibernate.dialect.PostgreSQLDialect
export SPRING_DRIVER_CLASS_NAME=org.postgresql.Driver
export SPRING_DATASOURCE_URL=jdbc:postgresql://localhost:5432/thingsboard
export SPRING_DATASOURCE_USERNAME=postgres
export SPRING_DATASOURCE_PASSWORD=My_PostgreSQL_Password
export SPRING_DATASOURCE_MAXIMUM_POOL_SIZE=5
# Specify partitioning size for timestamp key-value storage. Allowed values: DAYS, MONTHS, YEARS, INDEFINITE.
export SQL_POSTGRES_TS_KV_PARTITIONING=MONTHS
# Update ThingsBoard memory usage and restrict it to 512MB
export JAVA_OPTS="$JAVA_OPTS -Xms512M -Xmx512M"
Passing a password via a plain config file is never a great idea, and this should be an improving field for ThingsBoard. For this reason, a way for us to improve security is by restricting access to our TB installation only to known devices and limited to needed ports.
Compared to the official procedure, we added more RAM as we are leveraging memory crashes with Swap.
We can now execute the installation script. Please note that by appending a final “–loadDemo” option to the next command we’ll load demo data: users, devices, assets, rules, widgets.
sudo /usr/share/thingsboard/bin/install/install.sh
It will last a few minutes, with the following output:
pi@raspberrypi:~ $ sudo /usr/share/thingsboard/bin/install/install.sh
______ __ _ ____ __
/_ __/ / /_ (_) ____ ____ _ _____ / __ ) ____ ____ _ _____ ____/ /
/ / / __ \ / / / __ \ / __ `/ / ___/ / __ | / __ \ / __ `/ / ___/ / __ /
/ / / / / / / / / / / / / /_/ / (__ ) / /_/ / / /_/ // /_/ / / / / /_/ /
/_/ /_/ /_/ /_/ /_/ /_/ \__, / /____/ /_____/ \____/ \__,_/ /_/ \__,_/
/____/
===================================================
:: ThingsBoard :: (v3.3.2)
===================================================
Starting ThingsBoard Installation...
Installing DataBase schema for entities...
Installing SQL DataBase schema part: schema-entities.sql
Installing SQL DataBase schema indexes part: schema-entities-idx.sql
Installing SQL DataBase schema PostgreSQL specific indexes part: schema-entities-idx-psql-addon.sql
Installing DataBase schema for timeseries...
Installing SQL DataBase schema part: schema-ts-psql.sql
Successfully executed query: CREATE TABLE IF NOT EXISTS ts_kv_indefinite PARTITION OF ts_kv DEFAULT;
Loading system data...
Installation finished successfully!
ThingsBoard installed successfully!
Start ThingsBoard:
sudo systemctl start thingsboard
With the “systemctl status” command, check that ThingsBoard has been completely loaded:
sudo systemctl status thingsboard
Please wait more time, especially on RPI3, to get the web GUI available. You can monitor it with the following command:
watch tail /var/log/thingsboard/thingsboard.log
You will get the Gui ready when the following row will appear from log tailing:
INFO o.s.b.w.e.tomcat.TomcatWebServer - Tomcat started on port(s): 8080 (http) with context path ''
At this point, the ThingsBoard will be available from a web browser by using your Raspberry PI address as URL and appending “8080” port. In my case, my RPI local address is 192.168.1.238 and the URL will be “http://192.168.1.238:8080/login”. You will receive the Thingsboard login page:

The following default credential will be available for very first access as System administrator:
Username(email): sysadmin@thingsboard.org
Password: sysadmin
You will be logged in System Administrator home page:

In my next tutorial, I’ll show how to create your first tenant user and how to add the first measurements from the Raspberry PI. please find this on the following link: ThingsBoard and Raspberry PI (part 2): Add Device telemetry by MTTQ and Python.
Enjoy!
Just to avoid further mistakes in other people
There’s a semicolon missing at the end of CREATE DATABASE thingsboard instance.