Thingsboard on Raspberry Pi Model B

Thingsboard is an open-source IoT platform for collecting data from devices and displaying it in a simple web browser. This can easily be deployed on a home network using an old Raspberry Pi.


There is a walkthrough for deploying Thingsboard on on a Raspberry Pi 3, but all I had on hand was an old Raspberry Pi. I had to check, but I’m fairly certain that I used the very first Model B Pi for this project.


The latest version of Raspbian Stretch Lite was used, since a Desktop GUI won’t be needed for this project.

There are a number of ways to put the image onto an SD card. Not all of the steps from  the given Linux instructions are needed, and you can get it done with just a few commands (below). An old 8GB micro SD card in an adapter was used in this case.

Copy Raspbian Lite to SD Card
Copying Raspbian Stretch Lite to an SD card using the command line

Connecting to the Pi

The SD was put into the Pi, and the Pi was powered and connected to the home router via an Ethernet cable.

The hostname -I command is used to determine what the local IP address is. I found that two addresses were returned when I was connected to a VPN, so ensure you disconnect from any VPNs before running the command.

Using the first 3 fields of the local IP address, nmap can discover all the devices on the local network. Use sudo to uncover the MAC address and friendly names of each device. This will allow you to see which one is actually your Raspberry Pi.

Finding Pi on home network
Using nmap from the command line to find the address of the Raspberry Pi on the home network

I went to SSH into the Pi following the normal method, but discovered that an update to Raspbian had taken place since I’d last used it. For security reasons, SSH is not enabled by default, and to enable it (for a headless Pi), you must place a file simply called “ssh” into the boot partition of the SD card. If you do not do this, you will simply get a message saying “Connection refused”.

Once this was done, connecting to the Pi gave a pretty intense warning message. The IP address of the Pi has to be added to the known SSH hosts, as shown in the screenshot below. Once this was done, you can connect. It gives a very strong recommendation to change your password, which I did.

Initial SSH to Raspberry Pi
Process to SSH into a headless Raspberry Pi, once SSH has been enabled

These changes have come about due to security concerns over the default behaviour.

Installing Thingsboard

Environment setup

Firstly, make sure the environment is up to date:
sudo apt-get update
sudo apt-get upgrade

Java does not come with Raspbian Stretch Lite and must be installed before Thingsboard:
sudo apt-get install oracle-java8-jdk

One of the options in the Raspberry Pi walkthrough is to install and use PostgreSQL. The alternative, and the default, is HSQLDB. I have elected to use HSQLDB as it is lightweight and the Pi will not be storing much data, and I don’t want to push the old Pi too hard with unnecessary services.


Next, download the latest Thingsboard package:

Install the package:
sudo dpkg -i thingsboard-1.3.deb

Change the configuration file /etc/thingsboard/conf/thingsboard.conf so that the JAVA_OPTS line reads:
export JAVA_OPTS="$JAVA_OPTS -Dplatform=rpi -Xms256M -Xmx256M"

This limits its memory usage.

Install Thingsboard with the command:
sudo /usr/share/thingsboard/bin/install/ --loadDemo

I always like to use the --loadDemo argument as it ensures the database is working correctly.

This installation process takes around 10 minutes.

Finally, the server is started with:
sudo service thingsboard start

Look at /var/log/thingsboard.log to check the process of the service starting up. This log showed the it took the service 907 seconds (15 minutes!) to load up on my Pi.

The system time is an important consideration as transmitted data can allow the server to set its data instance’s timestamp. I checked, and system time will update automatically from the internet and default to UTC which is fine.

Using Thingsboard

Connecting from the browser

In order to get access to the web service, port 80 has to be opened and forwarded on to port 8080, as Thingsboard cannot get access to port 80. The easiest way of doing this is through iptables:

sudo iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to 8080

However, be aware that this will have to be rerun whenever the server (the Pi) is rebooted.

Open up a browser from anywhere on your home network and navigate to the Pi’s IP address:

Thingsboard login on mobile phone
Logging in to Thingsboard on a mobile phone by navigating to the Raspberry Pi’s IP address

Pushing some fake data

In order to test that data could come in from a device, I got a “fake” device to talk to Thingsboard via the HTTP Telemetry API.

Log in to Thingsboard using the default tenant account, and create a fake device.

Add fake device
Add a fake device to the Thingsboard platform installed on the Raspberry Pi

Select the new device and copy the access token to your clipboard.

Copy access token
Copy the fake device’s access token

I used a cross-platform app called Insomnia to send data to the device. Use an HTTP POST request, with the IP address of the Raspberry Pi and the entire telemetry API URI, with the device’s access token. Put in a bit of JSON, ensuring under “Header”, Content-Type is set to application/json. Hit Send, and make sure a code of 200 (OK) is returned.

Insomnia post HTTP
Send a post HTTP request using Insomnia to Thingsboard

Verify that the data has come through on Thingsboard, by clicking on the “Latest Telemetry” tab on the device page.

The data sent in the POST request will show, with the timestamp determined by the time it arrived that the Raspberry Pi.

Checking telemetry data
Verify that data from the fake device has gone to Thingsboard

Next steps

Now that a local platform has been deployed, devices can connect as sensors and/or actuators. Initial custom devices will probably be based on the ESP8266 as a standalone module (as it can access the network and run a simple application).

The platform will also be saved as a custom image so it can be easily installed later if required.

2 thoughts on “Thingsboard on Raspberry Pi Model B

  1. Regarding iptables I made the same configuration but the data does not arrive on the device accessing port 80, but when I open port 8080 it works perfectly, what could be done to open thingsboard on port 80?

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s