thingsboardの使用方法の例
12825 ワード
1.アクセス
アドレス:127.0.0.1:8080
ユーザーのテスト:[email protected]パスワード:tenant
他のテストアカウント、テストデバイスTokensはDemo Accountを参照してください.
2.データアップロード
DashboardのTemperature & Humidity Demo
対応デバイスDHT 11 Demo、TokenはDHT 11_DEMO_TOKEN.
2.1 cURLによるデータのアップロード
sudo apt-get install curl
curl -v -X POST -d "{\"temperature\": 30, \"humidity\": 80}" http://localhost:8080/api/v1/DHT11_DEMO_TOKEN/telemetry --header "Content-Type:application/json" # Dashboards ?
2.2 MQTTを通過する.jsアップロードデータ
mkdir tmp #
cd tmp
npm install mqtt # mqtt
デバイス属性値attributes-data.json
およびfirmware_version
を含むデータファイルserial_number
が作成される.{"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();
});
作成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=DHT11_DEMO_TOKEN
# Read serial number and firmware version attributes
ATTRIBUTES=$( 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 client
node publish.js
chmod +x mqtt-js.sh
./mqtt-js.sh
Connecting to: localhost using access token: DHT11_DEMO_TOKEN
Client connected!
Attributes published!
Telemetry published!
2.3 MQTT Mosquittoクライアントによるデータアップロード
sudo apt-get install mosquitto-clients
作成mosquitto.sh
:#!/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="DHT11_DEMO_TOKEN"
# Publish serial number and firmware version attributes
mosquitto_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"
アップロード:chmod +x mosquitto.sh
./mosquitto.sh
Client mosqpub/23608-hy-OptiPl sending CONNECT
Client mosqpub/23608-hy-OptiPl received CONNACK
Client mosqpub/23608-hy-OptiPl sending PUBLISH (d0, q0, r0, m1, 'v1/devices/me/attributes', ... (55 bytes))
Client mosqpub/23608-hy-OptiPl sending DISCONNECT
Client mosqpub/23614-hy-OptiPl sending CONNECT
Client mosqpub/23614-hy-OptiPl received CONNACK
Client mosqpub/23614-hy-OptiPl sending PUBLISH (d0, q0, r0, m1, 'v1/devices/me/telemetry', ... (53 bytes))
Client mosqpub/23614-hy-OptiPl sending DISCONNECT
2.4 CoAPクライアントによるデータアップロード
sudo npm install coap-cli -g
作成coap-js.sh
:#!/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="DHT11_DEMO_TOKEN"
# Publish serial number and firmware version attributes
cat 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
アップロード:chmod +x coap-js.sh
./coap-js.sh
Resources
https://thingsboard.io/docs/samples/demo-account/https://thingsboard.io/docs/getting-started-guides/helloworld/
Dashboardの
Temperature & Humidity Demo
対応デバイスDHT 11 Demo、TokenはDHT 11_DEMO_TOKEN. 2.1 cURLによるデータのアップロード
sudo apt-get install curl
curl -v -X POST -d "{\"temperature\": 30, \"humidity\": 80}" http://localhost:8080/api/v1/DHT11_DEMO_TOKEN/telemetry --header "Content-Type:application/json" # Dashboards ?
2.2 MQTTを通過する.jsアップロードデータ
mkdir tmp #
cd tmp
npm install mqtt # mqtt
デバイス属性値
attributes-data.json
およびfirmware_version
を含むデータファイルserial_number
が作成される.{"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();
});
作成
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=DHT11_DEMO_TOKEN
# Read serial number and firmware version attributes
ATTRIBUTES=$( 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 client
node publish.js
chmod +x mqtt-js.sh
./mqtt-js.sh
Connecting to: localhost using access token: DHT11_DEMO_TOKEN
Client connected!
Attributes published!
Telemetry published!
2.3 MQTT Mosquittoクライアントによるデータアップロード
sudo apt-get install mosquitto-clients
作成
mosquitto.sh
:#!/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="DHT11_DEMO_TOKEN"
# Publish serial number and firmware version attributes
mosquitto_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"
アップロード:
chmod +x mosquitto.sh
./mosquitto.sh
Client mosqpub/23608-hy-OptiPl sending CONNECT
Client mosqpub/23608-hy-OptiPl received CONNACK
Client mosqpub/23608-hy-OptiPl sending PUBLISH (d0, q0, r0, m1, 'v1/devices/me/attributes', ... (55 bytes))
Client mosqpub/23608-hy-OptiPl sending DISCONNECT
Client mosqpub/23614-hy-OptiPl sending CONNECT
Client mosqpub/23614-hy-OptiPl received CONNACK
Client mosqpub/23614-hy-OptiPl sending PUBLISH (d0, q0, r0, m1, 'v1/devices/me/telemetry', ... (53 bytes))
Client mosqpub/23614-hy-OptiPl sending DISCONNECT
2.4 CoAPクライアントによるデータアップロード
sudo npm install coap-cli -g
作成
coap-js.sh
:#!/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="DHT11_DEMO_TOKEN"
# Publish serial number and firmware version attributes
cat 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
アップロード:
chmod +x coap-js.sh
./coap-js.sh