在官網下載thingsboard和tb-gatewayjava
須要安裝java8web
thingsboard服務安裝json
https://thingsboard.io/docs/user-guide/install/windows/windows
把thingsboard-windows-1.4.zip解壓到C盤app
在這個文件夾打開管理員模式cmd 輸入ide
install.bat
安裝服務,成功後提示ui
C:\thingsboard>install.bat --loadDemo Detecting Java version installed. Detecting if it is 64 bit machine CurrentVersion Detecting if it is 32 bit machine CurrentVersion 1.8 Java 1.8 found! Installing thingsboard ... =================================================== :: ThingsBoard :: (v1.4) =================================================== Starting ThingsBoard Installation... Installing DataBase schema... Installing Cassandra DataBase schema... Loading system data... Installation finished successfully! 2017-07-23 21:47:12,079 INFO - Starting ServiceWrapper in the CLI mode 2017-07-23 21:47:12,317 INFO - Completed. Exit code is 0 ThingsBoard installed successfully!
tb-gateway服務安裝spa
https://thingsboard.io/docs/iot-gateway/install/windows/code
下載tb-gateway-windows-1.2.1.zip解壓到c盤component
輸入
install.bat
出現下文就安裝成功
C:\tb-gateway>install.bat Detecting if it is 64-bit machine CurrentVersion 1.8 Java 1.8 found! Installing tb-gateway ... 2017-01-31 02:26:50,704 INFO - Starting ServiceWrapper in the CLI mode 2017-01-31 02:26:50,907 INFO - Completed. Exit code is 0 DONE.
啓動服務
安裝成功後啓動thingsboard服務
net start thingsboard
若是須要重啓thingsboard服務:
net stop thingsboard
net start thingsboard
啓動服務後查看C:\thingsboard\logs下的log,出現這些纔算啓動完成
2018-04-13 09:42:59,091 [main] INFO o.s.b.c.e.t.TomcatEmbeddedServletContainer - Tomcat started on port(s): 8080 (http) 2018-04-13 09:42:59,108 [main] INFO o.t.s.ThingsboardServerApplication - Started ThingsboardServerApplication in 54.39 seconds (JVM running for 56.581)
可能的錯誤:
2018-04-02 14:29:23,215 [main] ERROR o.t.s.s.c.rpc.ClusterGrpcService - Failed to start RPC server! java.io.IOException: Failed to bind
緣由是端口占用,刪除佔用端口的進程
netstat -ano|findstr 9001 taskkill /pid 4708 /f
使用ThingsBoard GUI進行後續工做
log提示thingsboard啓動後能夠打開網頁 它的做用和live demo同樣 只不過在本地
http://localhost:8080/
先登陸admin
sysadmin@thingsboard.org sysadmin
在租戶添加下面帳號
- Username: tenant@thingsboard.org
- Password: tenant
登陸租戶tenant,tenant能夠管理設備,添加規則等
啓動完thingsboard後能夠啓動tb-gateway
net start tb-gateway
啓動成功:
YYYY-MM-DD HH:mm:ss,sss [main] INFO o.t.gateway.GatewayApplication - Started GatewayApplication in x.xxx seconds (JVM running for x.xxx)
裝完服務後這兩個服務會開機啓動,若是log提示有問題只能一個個重啓,先重啓thingsboard再重啓tb-gateway
net stop thingsboard net start thingsboard net stop tb-gateway net start tb-gateway
若是要在本地啓動,修改 tb-gateway.yml,否則yml寫的是live demo的配置,以後再啓動tb-gateway
live demo 網址,需註冊
https://demo.thingsboard.io/signup
IoT Gateway Configuration
Change gateway.connection.host and gateway.connection.port properties to your ThingsBoard host (leave without modifications in case of live demo instance).
Change gateway.connection.security.accessToken property to your access token that was copied during step 3.
原來的配置:
gateway: reporting: interval: 60000 persistence: type: file path: storage bufferSize: 1000 connection: host: "demo.thingsboard.io" port: 1883 retryInterval: 3000 maxInFlight: 1000 security: accessToken: your_token # keystore: mqttclient.jks # keystorePassword: password # keystoreKeyAlias: clientalias # truststore: mqttclient.jks # truststorePassword: password opc: enabled: false configuration: opc-config.json mqtt: enabled: false configuration: mqtt-config.json sigfox: enabled: false configuration: sigfox-config.json server: # Server bind address address: "0.0.0.0" # Server bind port port: "9090" # Check new version updates parameters updates: # Enable/disable updates checking. enabled: "${UPDATES_ENABLED:true}"
本地使用,修改了host 和accessToken :
若是要經過ThingsBoard GUI設置ThingsBoard Gateway, remoteConfiguration在tb-gateway.yaml必須設置爲true:
gateway: tenants: label: "Tenant" # Some configuration omitted remoteConfiguration: true reporting: interval: 60000 persistence: type: file path: storage bufferSize: 1000 connection: host: "localhost" port: 1883 retryInterval: 3000 maxInFlight: 1000 security: accessToken: "6BW88NMt0nbsfVefQsGc" # keystore: mqttclient.jks # keystorePassword: password # keystoreKeyAlias: clientalias # truststore: mqttclient.jks # truststorePassword: password opc: enabled: false configuration: opc-config.json mqtt: enabled: false configuration: mqtt-config.json sigfox: enabled: false configuration: sigfox-config.json server: # Server bind address address: "0.0.0.0" # Server bind port port: "9090" # Check new version updates parameters updates: # Enable/disable updates checking. enabled: "${UPDATES_ENABLED:true}"
remoteConfiguration官方例子:
gateways: tenants: - label: "Tenant" # Some configuration omitted remoteConfiguration: true
If remoteConfiguration is set to false, GUI configuration will not take effect and ThingsBoard Gateway will look for configuration in config files.
得到Gateway的Access Token
在租戶帳號下:
In order to connect your IoT gateway to ThingsBoard server, you need to provision gateway credentials first. We will use access token credentials as the most simple one. See device authentication options for more details.
新建設備
Login as tenant administrator. Use default credentials in case of local ThingsBoard server. Open Devices and click on big red 「+」 button in the bottom right corner.
Populate your gateway name and select 「Is gateway」 checkbox.
設置爲網關
NOTE: Gateway and device names should be unique in the scope of a tenant.
Open new device card and click on 「Copy Access Token」 button.
查看gateway設備詳情,複製 Access Token
若是gateway和thingsboard連上gateway設備的last elementry會出現「devicesOnline」, 「attributesUploaded」 and 「telemetryUploaded」.:
Open the web UI of your ThingsBoard server and review statistics that is uploaded from your thingsboard gateway. Login as Tenant Administrator and open Devices page. Click on the gateway device card. Open 「Latest Telemetry」 tab and review following statistics: 「devicesOnline」, 「attributesUploaded」 and 「telemetryUploaded」. All values should be set to 「0」.
使用GateWay鏈接到MQTT broker
https://thingsboard.io/docs/iot-gateway/getting-started/#step-8-connect-to-external-mqtt-broker
首先下載安裝Mosquitto MQTT broker
有兩種配置方式,一種是經過file configuration,一種是在ThingsBoard GUI
tb-gateway.yaml配置文件須要注意:
file configuration:remoteConfiguration:false
ThingsBoard GUI:remoteConfiguration:ture
同時若是用file啓動要修改配置文件mqtt-config.json,且tb-gateway.yaml應該修改
mqtt: enabled: true configuration: mqtt-config.json
官方的配置無論怎麼作都沒法作到status出現sync但願會的人告知(無論是mqtt仍是opcua)
不須要網關Sync鏈接MQTT並創建dashboard:
救命視頻:Creating an MQTT (IOT) Dashboard Using Thingsboard
https://www.youtube.com/watch?v=eqbTNXf2m7s
視頻中的代碼
http://www.steves-internet-guide.com/thingsboard-mqtt-dashboard/
用kafka plugin發送數據到kafka
Kafka plugin is responsible for sending messages to Kafka brokers triggered by specific rules
https://thingsboard.io/docs/reference/plugins/kafka/
須要注意的最後發送數據他寫錯了,引號寫的不對,應該是
mosquitto_pub -d -h "localhost" -p 1883 -t "v1/devices/me/telemetry" -u "1EU6SlQetuBTC4I5a0bk" -m "{'temp':73.4}"
這裏1883是tb-gateway的端口,mqtt和它原本是同一個端口,我修改了mqtt的端口
v1/devices/me/telemetry是固定的語句
1EU6SlQetuBTC4I5a0bk是accesstoken
關鍵點是把數據發送到特定access token,這樣有這個access token的device就能夠讀取發送的數據
Kafka Plugin Action 沒試過
This component allows creating a kafka message by substitution of device attributes and message data into configurable templates.
https://thingsboard.io/docs/reference/actions/kafka-plugin-action/
thingsboard拜拜嘍