Ubidots統合(TTS経由)
Ubidotsは、コードを書いたりソフトウェア開発チームを雇ったりすることなく、IoTアプリケーションを迅速に組み立てて起動できるローコードIoTアプリケーション開発プラットフォームです。現在、40,000以上のアプリケーションがすでにUbidotsで接続されています。
IoTアプリケーション構築の需要の高まりに応えるため、私たちはUbidotsと協力し、コミュニティがThe Things Networkを通じてSenseCAP T1000 Trackerを簡単にUbidotsに追加できるようサポートしています。
セットアップを開始する前に、SenseCAP T1000をTTSに接続を確認して、まずSenseCAP T1000 TrackerをTTSに接続してください。
Ubidotsの設定
開始するには、Ubidotsでアカウントを作成してください。
Ubidotsアカウントにログインし、ダッシュボードの上部にあるDevicesタブを見つけます。そのドロップダウンリストで、Pluginsを選択します。
Ubidots Plugins
+またはCreate Data Pluginボタンをクリックして、新しいプラグインを作成します。
利用可能なプラグインが表示されたら、The Things Stackプラグインを選択します。
次に、Ubidotsトークンを選択する必要があります。Default tokenを使用することも、新しいトークンを作成することもできます。
新しいトークンを作成するには、まず右上角のアバターをクリックしてAPI Credentialsを選択します。次に、Default tokenの下のMoreを選択し、API Credentialsページ内で新しいトークンを追加します。
**>**を選択して続行し、チェックマークをクリックして完了します。
デコーダーの設定
プラグインを作成したら、デコーダーセクションに移動し、すべてのコードを削除して以下のコードに置き換えます:
const HOTSPOT_INFO = false;
function handleErrorIfExists(data){
const error = 'error' in data;
if (error) {
const errorMsg = { "error": { "value": data.errorCode, "context" : { "reason": data.error } } };
return errorMsg;
}
return false;
}
function addLat(lat, ubidotsPayload){
ubidotsPayload.position.context.lat = lat;
}
function addLng(lng, ubidotsPayload){
ubidotsPayload.position.context.lng = lng;
}
const coordinateActions = {
"Longitude": addLng,
"Latitude": addLat,
}
const assignPayloadKeys = (data, ubidotsPayload) => {
const { type, measurementValue } = data;
if (type === "Longitude" || type === "Latitude") {
if (!ubidotsPayload.position) {
ubidotsPayload.position = { "value": 1, "context": { "lat": undefined, "lng": undefined } };
}
coordinateActions[type](measurementValue, ubidotsPayload);
}
else if (data.type === "Timestamp") {
ubidotsPayload.timestamp = data.measurementValue;
}
else {
ubidotsPayload[type] = measurementValue;
}
};
function buildUbidotsPayload(data){
const ubidotsPayload = {};
data.forEach(innerData => {
innerData.forEach(innerInnerData => {
assignPayloadKeys(innerInnerData, ubidotsPayload);
});
});
return ubidotsPayload;
}
async function formatPayload(args){
const data = args.uplink_message.decoded_payload.messages;
let ubidotsPayload = {};
const error = handleErrorIfExists(data[0][0]);
if (error) return error;
if (HOTSPOT_INFO) {
const { hotspots, port, fcnt } = args;
const { snr, rssi } = hotspots[0];
Object.assign(ubidotsPayload, { SNR: snr, RSSI: rssi, port, 'Frame Counter': fcnt });
}
ubidotsPayload = buildUbidotsPayload(data);
console.log(ubidotsPayload);
return ubidotsPayload;
};
module.exports = { formatPayload };
The Things Stack の設定
Ubidots での設定を準備したら、Ubidots Webhook テンプレートを使用して The Things Stack で Webhook 統合を作成する必要があります。
The Things Stack で、Integrations → Webhooks に移動し、Add Webhook をクリックします。
Ubidots Webhook テンプレートを選択します。
Webhook ID を入力して統合に名前を付け、Plugin ID と Ubidots トークンの値を貼り付けます。
Plugin ID を見つけるには、新しく作成したプラグインをクリックし、左側の Decoder タブに移動します。Plugin ID は HTTPs Endpoint URL の一部として利用できます(下の画像でハイライトされている部分)。
データの監視
統合を完了したら、Devices メニューに移動します。エンドデバイスがアップリンクメッセージを送信すると、エンドデバイスリストにエンドデバイスが表示されます。