Raspberry Pi

How to Install and Setup ThingsBoard on Raspberry Pi

ThingsBoard is an IoT-based open-source platform used for data collection, visualization, processing and device management. It combines the scalability, performance and fault tolerance to protect users’ data. Further, it also opens up device connectivity through different standard IoT protocols such as MQTT, HTTP and CoAP, as well as supports both cloud and software deployment.

In this tutorial, you will find the guideline to setup ThingsBoard on Raspberry Pi.

Install and setup ThingsBoard on Raspberry Pi

As ThingsBoard uses the Web interface for performing various tasks, you will require the server-side configuration to set up ThingsBoard on Raspberry Pi. The following step-by-step guidelines will assist you in installing and setting up ThingsBoard on Raspberry Pi:

Step 1: Install Java

ThingsBoard service requires Java on Raspberry Pi. If the Java isn’t installed, issue the following commands to install it:

$ sudo apt install openjdk-17-jdk

Step 2: Install ThingsBoard

Now, to install ThingsBoard on Raspberry Pi, you will first need to download its deb package using the following command:

$ wget https://github.com/thingsboard/thingsboard/releases/download/v3.3.4.1/thingsboard-3.3.4.1.deb

Then use the following apt command to install it on your Raspberry Pi:

$ sudo apt install ./thingsboard-3.3.4.1.deb

The above command will install the Thingsboard deb package on Raspberry on Raspberry Pi.

Step 3: CreatingThingsBoard Database using PostgreSQL

After the successful installation of ThingsBoard on Raspberry Pi, it’s now time to configure its database. The team of ThingsBoard recommends the use of PostgreSQL because it’s the most cost-effective solution for several ThingsBoard instances.

To install PostgreSQL on Raspberry Pi, use the following command:

$ sudo apt install postgresql

After the installation, set the password for the existing default user “Postgres” by issuing the following command:

$ sudo su - postgres

Then use the following statement to enter the postgres workspace:

$ psql

Next, type in the following statement to add the new password for the user:

\password

Then use “\q” to quit.

Now, use “CTRL+D” to return to the main user. Then run the below-given command to connect to PostgreSQL for creating the ThingsBoard database.

$ psql -U postgres -d postgres -h 127.0.0.1 -W

Type password, you have set before.

Now, create ThingsBoard database through following statement:

CREATE DATABASE thingsboard;

Then use “\q” to go back to the main user.

Step 4: Configure ThingsBoard on Raspberry Pi

After creating the database, it’s now time to configure ThingsBoard on Raspberry Pi. For that, open the configuration file via below-given command:

$ sudo nano /etc/thingsboard/conf/thingsboard.conf

Now, paste the following lines in the file.

# Database 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_MAXIMUM_POOL_SIZE=5
export SPRING_DATASOURCE_URL=jdbc:postgresql://localhost:5432/thingsboard
export SPRING_DATASOURCE_USERNAME=postgres
export SPRING_DATASOURCE_PASSWORD=
export SQL_POSTGRES_TS_KV_PARTITIONING=MONTHS

Save the file by using the “CTRL+X” buttons, press “Y” and enter.

Step 5: Optional Step for Low Memory Machines

If you have a device having 2GB of RAM, you can add the following line in the configuration file to update the ThingsBoard memory usage by restricting it to the value of your choice.

export JAVA_OPTS="$JAVA_OPTS -Xms256M -Xmx256M"

Step 6: Execute installation script

After completing the above step, you are now good to run the following ThingsBoard installation command on your Raspberry Pi terminal:

$ sudo /usr/share/thingsboard/bin/install/install.sh --loadDemo

Step 7: Start ThingsBoard Service

After the installation, you can start ThingsBoard service using the following command:

$ sudo service thingsboard start

To check the status, use the following command:

$ sudo service thingsboard status

Step 8: Opening Web Interface

Now, go to your browser tab and use the address “http://localhost:8080/” to open the ThingsBoard web interface.

You can find the IP address of Raspberry Pi via issuing the below-given command:

$ hostname -I

This will open the ThingsBoard login screen. You can use the default login credential if you have specified –loadDemo during the script execution.

Conclusion

ThingsBoard is a robust and scalable IoT platform used to collect data and manage the devices from a remote location. It helps to enhance the performance of both software and hardware as well as includes several other features that make your IoT experience well above your imagination. The above setup guide will assist you in installing and setting ThingsBoard on Raspberry Pi by creating a database through PostgreSQL so that you will be able to access the ThingsBoard dashboard right onto your browser tab.

About the author

Awais Khan

I'm an Engineer and an academic researcher by profession. My interest for Raspberry Pi, embedded systems and blogging has brought me here to share my knowledge with others.