Thingsboard is an open-source server-side platform that allows you to monitor and control IoT devices. It is free for both personal and commercial usage and you can deploy it anywhere. If this is your first experience with the platform we recommend to review what-is-thingsboard page and getting-started guide.
This sample application will allow you to control GPIO of your Raspberry Pi device using Thingsboard web UI. We will observe GPIO control using Led connected to one of the pins. The purpose of this application is to demonstrate Thingsboard RPC capabilities.
Raspberry Pi will use simple application written in Python that will connect to Thingsboard server via MQTT and listen to RPC commands. Current GPIO state and GPIO control widget is visualized using built-in customizable dashboard.
The video below demonstrates the final result of this tutorial.
List of hardware and pinouts
Raspberry Pi - we will use Raspberry Pi 3 Model B but you can use any other model.
Led and corresponding resistor
2 female-to-male jumper wires
Since our application will allow to control state of all available GPIO pins, we recommend to attach some LEDs to those pins for visibility. You can use this basic instruction or another one to wire some LEDs.
Programming the Raspberry Pi
MQTT library installation
Following command will install MQTT Python library:
sudo pip install paho-mqtt
Application source code
Our application consists of single python script that is well commented. You will need to modify THINGSBOARD_HOST constant to match your Thingsboard server installation IP address or hostname. Use “demo.thingsboard.io” if you are using live demo server.
The value of ACCESS_TOKEN constant corresponds to sample Raspberry Pi device in pre-provisioned demo data. If you are using live demo server - get the access token for pre-provisioned “Raspberry Pi Demo Device”.
Running the application
This simple command will launch the application:
In order to simplify this guide we have included “Raspberry PI GPIO Demo Dashboard” to the demo data that is available in each thingboard installation. Of course, you can modify this dashboard: tune, add, delete widgets, etc. You can access this dashboard by logging in as a tenant administrator. Use
- login: [email protected]
- password: tenant
in case of local Thingsboard installation.
Once logged in, open Dashboards->Raspberry PI GPIO Demo Dashboard page. You should observe demo dashboard with GPIO control and status panel for your device. Now you can switch status of GPIOs using control panel. As a result you will see LEDs status change on device and on the status panel.
Below is the screenshot of the “Raspberry PI GPIO Demo Dashboard”.
Browse other samples or explore guides related to main Thingsboard features: