Skip to main content

Ubidots統合(Helium経由)

この記事では、SenseCAP T1000 TrackerをHelium LNS経由でUbidotsに接続するプロセスを説明します。

Ubidotsチーム - Juan David Tangarife 著

ソース

pir

必要なもの

アクティブなUbidotsアカウント SenseCAP T1000 Tracker DCを持つHeliumコンソールのアクティブアカウント Google Play StoreまたはAppStoreとBluetoothをサポートする携帯電話

SenseCAP Mateアプリのインストールとトラッカーの設定

以下のQRコードをスキャンしてください。Seeed StudioのSenseCAP Mateアプリ公式ダウンロードページに移動します。

pir

インストールが完了したら、携帯電話のBluetoothを有効にしてアプリを起動してください。まだアカウントをお持ちでない場合は、アプリを使用するために登録する必要があります。

その後、トラッカーのボタンを少なくとも3秒間、またはLEDが点滅し始めるまで長押しします。次に、デバイスのリストからTracker T1000を選択します。

pir

デバイスをタップします:

pir

設定タブに移動し、次にLoRaタブに移動します。そこで_プラットフォーム_としてHeliumを選択し、要件に応じて_周波数プラン_を選択します。また、後の手順で必要になるため、Device EUI、APP EUIAPP Keyをコピーしてください。完了したら、送信ボタンをタップして設定を保存します。

pir

Helium LNSでのトラッカー登録

Heliumコンソールにログインし、**「Devices」セクションに移動して「Add device」**ボタンをクリックします。

pir

デバイス名**、LoRaWAN認証情報などの必要なフィールドを入力します。次にSave Device**ボタンをクリックします。

pir

Heliumでのデコーダー関数の作成

次のステップは、生のバイトを人間が読める形式にデコードする関数を設定することです。左側のパネルのFunctionタブに移動します。次にAdd New Functionボタンをクリックして名前を付けます:

pir

Seeed Studioは、以下のリポジトリでこのデバイス専用のデコーダーを提供しています。そのデコーダーをテキストフィールドに貼り付けて、変更を保存します。

Ubidotsへの統合の作成

Integrationsセクションに移動し、Add integrationをクリックしてUbidots統合を検索します:

pir

+Add integrationをクリックします

pir

該当するフィールドにUbidotsトークンを入力し、Continueボタンをクリックして確認ポップアップメッセージを待ちます。その後、統合に名前を付けてAdd Integrationボタンをクリックします:

pir

この手順を実行すると、Ubidotsアカウントに新しいHeliumプラグインが作成されます。

統合をUbidotsに接続するフローの作成

Flowsセクションに移動し、左上角のドロップダウンメニューから、デバイス、デコーダー関数、統合を空白エリアにドラッグアンドドロップし、以下のGIFに示すようにドットを接続します:

pir

この例では、デバイスとデコーダー関数の両方が「sensecap-lorawan-tracker」と呼ばれ、統合は「send data to ubidots」と呼ばれています。

Seeed Studioのデコーダーが返すJSONオブジェクトはUbidotsスキーマと互換性がないため、関心のあるデータを抽出した後に変換が必要です。
Heliumプラグインのデコーダーセクションに移動し、そこにあるすべてのコードを削除して、以下のコードに置き換えます:

#Set to true in order to enable hotspot information
HOTSPOT_INFO_ENABLE = False

def format_payload(args):

messages = args.get("decoded", {}).get("payload", {}).get("data", {}).get("messages", [])
ubidots_payload = {}

error = assert_error(messages[0][0])
if error is not None:
return error

if HOTSPOT_INFO_ENABLE:
hotspot_info = args.get('hotspots', None)
ubidots_payload['SNR'] = hotspot_info[0].get('snr') if hotspot_info is not None else None
ubidots_payload['RSSI'] = hotspot_info[0].get('rssi') if hotspot_info is not None else None
ubidots_payload["port"] = args.get("port", None)
ubidots_payload['Frame Counter'] = args.get('fcnt', None)

for msg in messages:
for sensor in msg:
message_type = sensor.get("type", None)
value = sensor.get("measurementValue")
if message_type == "Latitude" or message_type == "Longitude":
position = ubidots_payload.setdefault("position", {})
position.update({message_type.lower(): value})
continue
elif message_type == "Timestamp":
ubidots_payload["timestamp"] = value
continue
ubidots_payload[message_type] = value

print(ubidots_payload)
return ubidots_payload


def assert_error(data : dict):
if "error" in data:
return {"ERROR" : { "value" : data["errorCode"], "context" : { "status" : data["error"]}}}
return None

すべてが正しく接続されていれば、Ubidots上で新しく作成されたデバイスで以下のように表示されるはずです

pir

Loading Comments...