Thingsboard 中文教程:快速入门

Thingsboard中文社区群聊二维码.png
可复制:121202538

中文社区:http://thingsboard.org.cn
介绍

The goal of this guide is for you to collect and visualize some IoT device data using ThingsBoard. This guide will let you:
Provision your device
Manage device credentials
Push data from device to your ThingsBoard instance using MQTT, CoAP or HTTP protocols
Create dashboard to visualize the data

该指南旨在通过以下方式帮助您使用ThingsBoard采集IoT设备数据以及完成数据可视化。
置备设备。
管理设备凭证。
使用MQTT, CoAP 或者HTTP协议将设备数据添加到ThingsBoard实例。
创建仪表盘实现数据可视化。
设置和需求

If you don’t have access to a running ThingsBoard instance, use either Live Demo or Installation Guide to fix this.

如果你无法访问正在运行中的ThingsBoard实例,可查阅在线演示Live Demo或安装指南进行修复。
演示账号

All ThingsBoard installations are equipped with a demo account that simplifies the first user experience. This demo account contains several pre-provisioned devices, dashboards, rules, and plugins installed. Please note that you are free to delete this account in the production deployment.

所有的ThingsBoard都配置了一个演示帐号,简化了第一次用户体验。这个演示帐户包含了几个预先置备的设备、仪表盘、规则和插件。请注意,您可以在生产部署中删除该帐户。
You can use ThingsBoard device emulators to simulate real-life devices and play-around with server-side APIs, data visualization, and processing logic.
您可以使用ThingsBoard设备仿真器来模拟真实的设备,并使用服务器端api、数据可视化和处理逻辑进行模拟。

We will use these emulators in advanced tutorials, however, the for the purpose of this guide, we will just use pre-provisioned tenant administrator account.

在高级教程中,我们将使用这些模拟器,但是,出于本指南的目的,我们将使用预先配置的租户管理员帐户。
登录租户管理账户

The first step is to login into administration Web UI. If you are using local ThingsBoard installation you can login to administration Web UI using default account:
Username: tenant@thingsboard.org
Password: tenant

第一步是登录到管理界面。 如果你使用的是本地ThingsBoard安装,你可以使用默认账户登录到管理界面:

If you are using Live Demo you can login to Live Demo server using Tenant Administrator account (the one that you created during sign-up).

如果你使用的是在线演示点击这里查看:Live Demo账号,你可以使用租户管理账号(你之前创建的账号)登录在线演示服务器。
image.png
添加设备

Open Devices panel and click on “+” button in the bottom-right corner of the page.

打开设备面板(Devices panel)点击右下角“+”
image.png

Populate and save device name (for example, “SN-001”). It will be referred to later as $DEVICE_NAME. Device names must be unique. Populating device name based on a unique serial number or other device identifier is generally a good idea. Click “Add” button will add corresponding device card to the panel.

填写并保存设备名称(例如,“SN-001”)。下文中被称作$DEVICE_NAME。设备名称必须是唯一的。建议根据惟一的序列号或其他设备标识符填写设备名称。单击“Add”按钮将向面板添加相应的设备卡。
image.png
管理设备凭证

Click on the “device card” we have created in the previous step. This action will open “device details” panel. Click on the “manage credentials” button on the top of the panel. This action will open a popup window with device credentials.

点击上一步骤中创建的“device card”打开“device details”面板。 点击面板顶部“manage credentials”按钮弹出设备凭证弹窗。
image.png

Device credentials window will show auto-generated device access token that you can change. Please save this device token. It will be referred to later as $ACCESS_TOKEN.

设备凭据窗口将显示自动生成的设备访问token,您可以更改它。请保存这个设备token。该token下文中被称为$ACCESS_TOKEN。
image.png

Congratulations! You have just provisioned your first device! Now you can push some data from this device to ThingsBoard for visualization and analysis.

恭喜您,您刚才完成了第一个设备置备!现在你可以将该设备的数据传递到ThingsBoard实现可视化并进行分析了。
传递设备数据

In order to simplify this guide, we will push data using MQTT, CoAP or HTTP protocol from your local PC. Please refer to samples for advanced examples of for various hardware platforms.

为了简化这个指南,我们将使用来自本地PC的MQTT、CoAP或HTTP协议来传递数据。有关各种硬件平台的高级示例,请参考samples。
客户端库安装

Install preferred MQTT (Mosquitto or MQTT.js), CoAP (CoAP.js) or HTTP (cURL) client using following commands.

使用以下命令安装MQTT (Mosquitto or MQTT.js), CoAP (CoAP.js) or HTTP (cURL) 客户端。
image.png
下面是表格中的文本:

MQTT.js	Mosquitto (Ubuntu)	Mosquitto (macOS)	CoAP.js	cURL (Ubuntu)	cURL (macOS)
resources/node-mqtt.sh	resources/mosquitto-ubuntu.sh	resources/mosquitto-macos.sh	resources/node-coap.sh	resources/curl-ubuntu.sh	resources/curl-macos.sh
npm install mqtt -g	sudo apt-get install mosquitto-clients	brew install mosquitto-clients	sudo npm install coap-cli -g	sudo apt-get install curl	brew install curl

示例数据文件

Create some folder to store all necessary files for this tutorial. Download to this folder or create the following data files:
attributes-data.json - contains two device attributes values: firmware version and serial number.
telemetry-data.json - contains three time-series values: temperature, humidity and active flag.

创建一个文件夹存放该指南需要的文件。将文件下载到该文件夹或者创建以下数据文件
attributes-data.json - 包含两个设备属性值:固件版本和序列号。
telemetry-data.json - 包含三个时间序列值:temperature, humidity and active flag。

Please note that data in this files is basically in key-value format. You can use your own keys and values. See MQTT, CoAP or HTTP protocol reference for more details.

请注意,这些文件的数据是以键-值方式存储。你可以使用自定义键值。
image.png
下面是表格中的文本:

attributes-data.json	telemetry-data.json
{"firmware_version":"1.0.1", "serial_number":"SN-001"}	{"firmware_version":"1.0.1", "serial_number":"SN-001"}

使用MQTT, CoAP or HTTP传送数据
Download the following files to previously created folder according to the preferred client:
根据首选客户端下载以下文件到之前创建的文件夹:

**MQTT.js (MQTT)**
[mqtt-js.sh](https://raw.githubusercontent.com/thingsboard/thingsboard.github.io/master/docs/getting-started-guides/resources/mqtt-js.sh) (Ubuntu & MacOS) or [mqtt-js.bat](https://raw.githubusercontent.com/thingsboard/thingsboard.github.io/master/docs/getting-started-guides/resources/mqtt-js.bat)(Windows)
[publish.js](https://raw.githubusercontent.com/thingsboard/thingsboard.github.io/master/docs/getting-started-guides/resources/publish.js)
**Mosquitto (MQTT)**
[mosquitto.sh](https://raw.githubusercontent.com/thingsboard/thingsboard.github.io/master/docs/getting-started-guides/resources/mosquitto.sh)
**CoAP.js (CoAP)**
[coap-js.sh](https://raw.githubusercontent.com/thingsboard/thingsboard.github.io/master/docs/getting-started-guides/resources/coap-js.sh)
**cURL (HTTP)**
[curl.sh](https://raw.githubusercontent.com/thingsboard/thingsboard.github.io/master/docs/getting-started-guides/resources/curl.sh)
If you are using a shell script (*.sh) make sure that it is executable:

如果您使用的是shell脚本(.sh),请确保它是可执行的:

chmod +x *.sh
Before executing script don’t forget to:
replace $ACCESS_TOKEN with one from Device credentials window.
replace $THINGSBOARD_HOST with either 127.0.0.1 (in case of local installation) or demo.thingsboard.io (in case of live-demo).

执行脚本之前请记住:
使用设备凭证窗口的访问token替换 A C C E S S T O K E N 。 使 用 127.0.0.1 ( 本 地 安 装 ) 或 者 d e m o . t h i n g s b o a r d . i o ( 在 线 演 示 ) 替 换 ACCESS_TOKEN。 使用127.0.0.1 (本地安装) 或者demo.thingsboard.io (在线演示)替换 ACCESSTOKEN使127.0.0.1()demo.thingsboard.io(线)THINGSBOARD_HOST。

Finally, execute corresponding .sh or .bat script to push data to the server.

最后,执行相应的.sh 或者.bat脚本向服务器传送数据。

Below are tabs with the content of the scripts provided.

image.png
下面是图中表格的数据:

MQTT.js(Ubuntu & MacOS)	MQTT.js(Windows)	publish.js	Mosquitto (MQTT)	CoAP.js(CoAP)	cURL (HTTP)
resources/node-mqtt.sh	resources/mosquitto-ubuntu.sh	resources/mosquitto-macos.sh	resources/node-coap.sh	resources/curl-ubuntu.sh	resources/curl-macos.sh
# Assuming you have Node.js and NPM installed on your Windows/Linux/MacOS machine
npm install mqtt -g	sudo apt-get install mosquitto-clients	brew install mosquitto-clients	sudo npm install coap-cli -g	sudo apt-get install curl	brew install curl

在Web界面观察数据

Once you execute commands listed above you should see attributes and latest telemetry data in corresponding device detail tabs.

执行完上述命令后,你可以在对应的设备详情列看到属性和最新遥测数据。
image.png
image.png
创建新仪表盘使数据可视化

The easiest way to create new dashboard is to select device attributes and show them on widget

最简单的创建新仪表盘的方式是选择设备属性并在小部件上展示这些选中的属性。
image.png

Once you click on “Show on widget” button, you will see a “widget preview” panel where you can
Select widget bundle
Select preferred widget
Add widget to new or existing dashboard

点击“Show on widget”按钮以后,显示“widget preview”面板,在该面板中可进行如下操作:
选择小部件包。
选择首选小部件*
将小部件添加到新的或者已存在的仪表盘中。
image.png

Let’s add our first widget to new dashboard named “SN-001 Dashboard”

我们将第一个小部件添加到名为“SN-001 Dashboard”的仪表盘上。
image.png

Let’s also add widget to visualize temperature

添加小部件来可视化温度。
image.png

Click Show on widget and select Digital gauges bundle. Use carousel to select thermometer widget as shown below.

点击“Show on widget”并选择“Digital gauges”。使用carousel(旋转进度条)来选择温度计小部件,如下所示。
image.png

Please note that in this case, we will add a widget to an already existing dashboard. We will also select “Open dashboard” option to see results of our work.

请注意,在此示例中我们将为已经存在的仪表盘添加小部件。我们仍然选择的是“Open dashboard”选项来查看结果。
image.png

Finally, we are able to see our new dashboard. Now we can edit the dashboard to
Configure dashboard settings
Tune widget sizes and layout
Modify advanced settings of individual widget
Add new widgets or remove existing
Widgets import/export

最后,我们可以查看我们的新仪表盘了。我们可以编辑仪表盘进行如下操作:
配置仪表盘设置
调节小部件的尺寸和布局。
修改每一个小部件的高级设置。
添加或者移除小部件。
小部件导入/导出。
image.png
Next steps

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.
ThingsBoard是基于IoT设备的数据可视化和管理平台。它为物联网设备提供了数据收集、处理、可视化和控制的功能。本文将介绍ThingsBoard入门教程,内容包括平台安装、设备添加和数据可视化等。 第一步:平台安装 ThingsBoard的安装有两种方式:一种是在本地环境中构建和运行它,另一种是使用ThingsBoard.io提供的云托管服务。 首先,我们来介绍如何在本地环境中构建ThingsBoard平台。在此之前,请确保您已经安装了Java运行时环境和PostgreSQL数据库。 从ThingsBoard官方网站下载源代码,并在控制台中运行以下命令: ``` $ git clone https://github.com/thingsboard/thingsboard.git $ cd thingsboard $ ./gradlew build ``` 这会生成安装包,然后运行以下命令启动ThingsBoard: ``` $ cd application/target $ java -jar thingsboard.jar ``` 然后,您可以在浏览器中输入localhost:8080访问ThingsBoard平台管理页面。接下来,我们将配置数据库。 打开conf文件夹下的thingsboard.yml文件,修改以下几行: ``` spring: datasource: url: jdbc:postgresql://localhost:5432/thingsboard username: postgres password: postgres tenants: install: - default ``` 这将指定ThingsBoard使用PostgreSQL数据库,并将默认的管理员用户设置为default。 第二步:添加设备 要开始添加设备,您需要先创建一个租户,然后将设备分配给该租户。 在Dashboard页面,单击“新建租户”,然后填写必要的信息。接下来,单击左侧的“设备”,然后单击“添加新设备”。在此页面中,输入设备名称、设备类型和设备ID,并选择所属的租户。最后,单击“创建设备”。 第三步:数据可视化 一旦设备被添加到ThingsBoard,您就可以开始通过Dashboard页面查看设备数据。 首先,单击左侧的“仪表板”,然后单击“新建仪表板”。在此页面中,选择所需的小部件和设备,并设置您希望看到的数据。然后,单击“保存仪表板”。 要查看仪表板,请返回到Dashboard页面,并单击所需的仪表板名称。您将看到实时数据的可视化以及与设备有关的其他信息。 总结 本文介绍了如何通过本地环境构建和运行ThingsBoard平台,以及如何添加设备和创建数据可视化。在使用ThingsBoard时,请记得定期更新其软件和安全设置,以确保系统的稳定性和安全性。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值