- Introduction
- 必备条件
- List of hardware and pinouts
- Wiring schema
- Programming the Raspberry Pi
- Data visualization
- See Also
- Your feedback
- Next steps
Introduction
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.
必备条件
你需要启动并运行ThingsBoard服务, 建议使用演示服务。
另一种选项是通过安装指南进行独立部署 Windows用户应遵循本指南,已经安装docker的Linux用户执行以下命令:
1
2
3
4
5
mkdir -p ~/.mytb-data && sudo chown -R 799:799 ~/.mytb-data
mkdir -p ~/.mytb-logs && sudo chown -R 799:799 ~/.mytb-logs
docker run -it -p 9090:9090 -p 7070:7070 -p 1883:1883 -p 5683-5688:5683-5688/udp -v ~/.mytb-data:/data \
-v ~/.mytb-logs:/var/log/thingsboard --name mytb --restart always thingsboard/tb-postgres
以上命令可以完成ThingsBoard安装和生成演示数据。
你可以通过ThingsBoard页面地址http://localhost:8080、 用户名tenant@thingsboard.org和密码tenant进行访问, 有关模拟帐户请参见此处。
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
Wiring schema
Since our application will allow controlling the state of all available GPIO pins, we recommend attaching 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
The following command will install MQTT Python library:
1
sudo pip install paho-mqtt
Application source code
Our application consists of a single python script that is well documented. 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:
1
python gpio.py
Data visualization
In order to simplify this guide, we have included “Raspberry PI GPIO Demo Dashboard” to the demo data that is available in each ThingsBoard installation. You still can modify this dashboard: tune, add, delete widgets, etc. You can access this dashboard by logging in as a tenant administrator. Use
- login: tenant@thingsboard.org
- 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 the device and on the status panel.
Below is the screenshot of the “Raspberry PI GPIO Demo Dashboard”.
See Also
Browse other samples or explore guides related to main ThingsBoard features:
- Device attributes - how to use device attributes.
- Telemetry data collection - how to collect telemetry data.
- Using RPC capabilities - how to send commands to/from devices.
- Rule Engine - how to use rule engine to analyze data from devices.
- Data Visualization - how to visualize collected data.
Your feedback
Don’t hesitate to star ThingsBoard on github to help us spread the word. If you have any questions about this sample - post it on the issues.
Next steps
-
入门指南 - 快速学习ThingsBoard相关功能。
-
安装指南 - 学习如何在各种操作系统上安装ThingsBoard。
-
连接设备 - 学习如何根据你的连接方式或解决方案连接设备。
-
可 视 化 - 学习如何配置复杂的ThingsBoard仪表板说明。
-
数据处理 - 学习如何使用ThingsBoard规则引擎。
-
数据分析 - 学习如何使用规则引擎执行基本的分析任务。
-
高级功能 - 学习高级ThingsBoard功能。
-
开发指南 - 学习ThingsBoard中的贡献和开发。