thingsboard安装及配置

来源:互联网 发布:网王之数据涟漪了 编辑:程序博客网 时间:2024/06/15 03:37

参考网址:https://thingsboard.io/docs/getting-started-guides/helloworld/

github地主:https://github.com/thingsboard/thingsboard

thingsboard使用了

actor模型:akka

用作服务调度:zookeeper

远程调用:gRPC,thrift

持久化:Cassandrahttps://cassandra.apache.org/数据存储),datastax(数据访问)

演示环境:https://demo.thingsboard.io/login


服务端安装(rpm安装):参考文档https://thingsboard.io/docs/user-guide/install/linux/(centos7)

1:thingsboard-1.3.rpm。下载地址https://github.com/thingsboard/thingsboard/releases/download/v1.3/thingsboard-1.3.rpm

2:sudo rpm -Uvh thingsboard-1.3.rpm,报错:java-1.8.0 is needed by thingsboard-0:1.3.0-1.noarch。猜测跟jdk的某些配置有关

sudo alternatives --config java

sudo alternatives --install /usr/bin/java java /usr/jdk1.8.0_60/bin/java 1,错误继续.删除配置

sudo alternatives --remove java /usr/jdk1.8.0_60/bin/java


下载rpm版的jdk安装文件(jdk-8u144-linux-x64.rpm)

sudo rpm -Uvh jdk-8u144-linux-x64.rpm.sudo rpm -Uvh thingsboard-1.3.rpm执行成功


使用postgres数据库

# Install packages

sudo yum install postgresql-server postgresql-contrib

# Initialize your PostgreSQL DB

sudo postgresql-setup initdbsudo 

systemctl start postgresq

# Optional: Configure PostgreSQL to start on bootsudo 

systemctl enable postgresql


修改/var/lib/pgsql/data/postgresql.conf

listen_addresses = '*'    


修改pg_hba.conf 

host    all             all            x.x.x.x/32        md5。允许某个ip地址登录

host    all             all            127.0.0.1/32            trust.允许本机其他用户名登录


修改postgres密码

修改thingsboard.yml为postgres连接


启动postgres。systemctl start postgresql


sudo /usr/share/thingsboard/bin/install/install.sh --loadDemo

sudo systemctl start thingsboard.service.


服务端安装(maven build:略。参考https://thingsboard.io/docs/user-guide/install/building-from-source/

git clone https://github.com/thingsboard/thingsboard.git

git checkout release-1.3

mvn clean package


客户端安装:安装mqttcoaphttp模拟器。参考https://thingsboard.io/docs/getting-started-guides/helloworld/#introduction

视个人情况安装nodejs,Mosquitto-client,curl。

npm install coap-cli -g 

npm install mqtt -g

创建mosquitto.repo源

[home_oojah_mqtt]name=mqtt (CentOS_CentOS-7)type=rpm-mdbaseurl=http://download.opensuse.org/repositories/home:/oojah:/mqtt/CentOS_CentOS-7/gpgcheck=1gpgkey=http://download.opensuse.org/repositories/home:/oojah:/mqtt/CentOS_CentOS-7//repodata/repomd.xml.keyenabled=1

yum search all mosquitto

==== Matched: mosquitto ================================================================
mosquitto-clients.x86_64 : Mosquitto command line publish/subscribe clients
mosquitto-debuginfo.x86_64 : Debug information for package mosquitto
libmosquitto-devel.x86_64 : MQTT C client library development files
libmosquitto1.x86_64 : MQTT C client library
libmosquittopp-devel.x86_64 : MQTT C++ client library development files
libmosquittopp1.x86_64 : MQTT C++ client library
mosquitto.x86_64 : MQTT version 3.1/3.1.1 compatible message broker

yum install mosquitto-clients


模拟设备发送:下载模拟文件脚本,修改脚本变量,执行脚本。参考https://thingsboard.io/docs/getting-started-guides/helloworld/#introduction

mqtt.js/publish.js:模拟mqtt

#!/bin/sh# Set ThingsBoard host to "demo.thingsboard.io" or "localhost"export THINGSBOARD_HOST=demo.thingsboard.io# Replace YOUR_ACCESS_TOKEN with one from Device credentials window.export ACCESS_TOKEN=YOUR_ACCESS_TOKEN# 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


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();});


Mosquitto-client:模拟mqtt

#!/bin/sh# Set ThingsBoard host to "demo.thingsboard.io" or "localhost"THINGSBOARD_HOST="demo.thingsboard.io"# Replace YOUR_ACCESS_TOKEN with one from Device credentials window.ACCESS_TOKEN="YOUR_ACCESS_TOKEN"# 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"


coap.js:模拟coap

# 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


curl:模拟curl

# 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"

模拟数据

attributes-data.json:

{"firmware_version":"1.0.1", "serial_number":"SN-001"}

telemetry-data.json 

{"temperature":21, "humidity":55.0, "active": false}

export THINGSBOARD_HOST=xxx.xxx.xxx.xxx
export ACCESS_TOKEN=xxxxxxx

export THINGSBOARD_PORT=xxxx


执行./coap-js.sh

或者./curl.sh

或者./mqtt-js.sh

或者./mosquitto.sh


在dashboard上可以看到刚才设备发送的消息及时间