1.安装Java1.8
2.安装Maven
3.安装node js
4.安装git
5.安装npm依赖 以管理员权限运行cmd,然后分别执行如下命令:
npm install -g cross-envnpm install -g webpack
6.安装IDEA
7.安装postgreSQL数据库
下载地址:
Postgresql数据库安装过程,请将用户postgres的密码设置成 postgres。方便后续操作。
Postgresql数据库安装完成后,创建数据库thingsboard,所有者为postgres,然后用数据库工具(我用的是Navicat Premium 12)分别运行D:\thingsboard-develop-1.5\dao\src\main\resources\sql目录下schema-entities.sql、schema-ts.sql、 system-data.sql
8.下载源码
9.编译源码
mvn clean install -DskipTests
如下则代表编译成功:
如果一次不成功则多试几次。
10.导入IDEA,运行 ThingsboardServerApplication
需要安装的插件:IntelliJ Lombok plugin, Protobuf Support
11.API测试工具安装及需要的测试文件 (win10下Ubuntu)
ubuntu:win10应用商店 Ubuntu 18.04 LTS
测试coap协议:安装
sudo npm install coap-cli -g
测试脚本:
# Set ThingsBoard host to "demo.thingsboard.io" or "localhost"THINGSBOARD_HOST="localhost"# Replace YOUR_ACCESS_TOKEN with one from Device details panel.ACCESS_TOKEN="i5OqJGOWWV6vWku8v25B"# Publish serial number and firmware version attributescat attributes-data.json | coap post coap://$THINGSBOARD_HOST/api/v1/$ACCESS_TOKEN/attributes# Publish timeseries data as an object without timestamp (server-side timestamp will be used)cat telemetry-data.json | coap post coap://$THINGSBOARD_HOST/api/v1/$ACCESS_TOKEN/telemetry
测试http协议:安装cURL
sudo apt-get updatesudo apt install curl
测试脚本:
# Set ThingsBoard host to "demo.thingsboard.io" or "localhost"THINGSBOARD_HOST="localhost"# Set ThingsBoard port to 80 or 8080THINGSBOARD_PORT=8080# Replace YOUR_ACCESS_TOKEN with one from Device details panel.ACCESS_TOKEN="i5OqJGOWWV6vWku8v25B"# Publish serial number and firmware version attributes# replace $THINGSBOARD_PORT with 8080 (in case of local installation) or 80 (in case of live-demo).curl -v -X POST -d @attributes-data.json http://$THINGSBOARD_HOST:$THINGSBOARD_PORT/api/v1/$ACCESS_TOKEN/attributes --header "Content-Type:application/json"# Publish timeseries data as an object without timestamp (server-side timestamp will be used)# replace $THINGSBOARD_PORT with 8080 (in case of local installation) or 80 (in case of live-demo).curl -v -X POST -d @telemetry-data.json http://$THINGSBOARD_HOST:$THINGSBOARD_PORT/api/v1/$ACCESS_TOKEN/telemetry --header "Content-Type:application/json"
测试mqtt协议:安装
npm install mqtt -g
测试脚本:mqtt-js.sh
#!/bin/sh# Set ThingsBoard host to "demo.thingsboard.io" or "localhost"export THINGSBOARD_HOST="localhost"# Replace YOUR_ACCESS_TOKEN with one from Device details panel.export ACCESS_TOKEN="i5OqJGOWWV6vWku8v25B"# Read serial number and firmware version attributesATTRIBUTES=$( cat attributes-data.json )export ATTRIBUTES# Read timeseries data as an object without timestamp (server-side timestamp will be used)TELEMETRY=$( cat telemetry-data.json )export TELEMETRY# publish attributes and telemetry data via mqtt clientnode publish.js
测试mqtt协议:安装
测试脚本:mosquitto.sh
resources/mosquitto.shCopy resources/mosquitto.sh to clipboard#!/bin/sh# Set ThingsBoard host to "demo.thingsboard.io" or "localhost"THINGSBOARD_HOST="localhost"# Replace YOUR_ACCESS_TOKEN with one from Device details panel.ACCESS_TOKEN="i5OqJGOWWV6vWku8v25B"# Publish serial number and firmware version attributesmosquitto_pub -d -h "$THINGSBOARD_HOST" -t "v1/devices/me/attributes" -u "$ACCESS_TOKEN" -f "attributes-data.json"# Publish timeseries data as an object without timestamp (server-side timestamp will be used)mosquitto_pub -d -h "$THINGSBOARD_HOST" -t "v1/devices/me/telemetry" -u "$ACCESS_TOKEN" -f "telemetry-data.json"
测试脚本:attributes-data.json
{"firmware_version":"1.0.1", "serial_number":"SN-001"}
测试脚本:telemetry-data.json
{"temperature":21, "humidity":55.0, "active": false}
测试脚本:publish.js
var mqtt = require('mqtt');console.log('Connecting to: %s using access token: %s', process.env.THINGSBOARD_HOST, process.env.ACCESS_TOKEN);var client = mqtt.connect('mqtt://'+ process.env.THINGSBOARD_HOST,{ username: process.env.ACCESS_TOKEN});client.on('connect', function () { console.log('Client connected!'); client.publish('v1/devices/me/attributes', process.env.ATTRIBUTES); console.log('Attributes published!'); client.publish('v1/devices/me/telemetry', process.env.TELEMETRY); console.log('Telemetry published!'); client.end();});
测试方法:
1.运行ubuntu terminal
2.新建thingsboads文件夹
mkdir thingsboard
3.将上述测试脚本添加到thingsboard文件加下
4.配置.sh文件可执行权限
chmod +x *.sh
5.执行测试,比如测试coap协议上传
./coap-js.sh
返回成功标识 如下:
服务器接收到消息:
详细测试步骤,请参见官方文档:
12.官方文档