3.6. デバイス開発者向け IoT

通常、デバイス開発者は、既存のデバイスをクラウドプラットフォームに接続するか、デバイス用のソフトウェア作成を担当します。以下の情報において、サポートされているプロトコルのいずれかを使用してデバイスを接続する方法について説明します。

3.6.1. HTTP デバイス

3.6.1.1. HTTP を使用した telemetry の送信

HTTP プロトコルを使用して、デバイスからクラウドに telemetry を送信できます。

手順

  1. HTTP プロトコルを使用して telemetry を送信します。

    curl --insecure -X POST -i -u sensor1@myapp.iot:hono-secret -H 'Content-Type: application/json' --data-binary '{"temp": 5}' https://$(oc -n amq-online-infra get routes iot-http-adapter --template='{{ .spec.host }}')/telemetry

3.6.1.2. HTTP を使用したイベントの送信

HTTP プロトコルを使用して、顧客アプリケーションからデバイスにイベントメッセージを送信できます。

手順

  1. HTTP プロトコルを使用してイベントを送信します。

    curl --insecure -X POST -i -u sensor1@myapp.iot:hono-secret -H 'Content-Type: application/json' --data-binary '{"temp": 5}' https://$(oc -n amq-online-infra get routes iot-http-adapter --template='{{ .spec.host }}')/events

3.6.1.3. HTTP プロトコルを使用したコマンドの受信

HTTP プロトコルを使用して、クラウドからデバイスにコマンドを送信できます。

手順

  1. クライアントがコマンドを待機する時間を示す hono-ttd パラメーターを指定し、HTTP プロトコルを使用して Telemetry メッセージを送信します。

    curl --insecure -X POST -i -u sensor1@myapp.iot:hono-secret -H 'Content-Type: application/json' --data-binary '{"temp": 5}' https://$(oc -n amq-online-infra get routes iot-http-adapter --template='{{ .spec.host }}')/telemetry?hono-ttd=600
  2. カスタマーアプリケーションを実行して、ID が 4711 のデバイスにコマンドを送信します。

    java -jar hono-cli-*-exec.jar --hono.client.host=$MESSAGING_HOST --hono.client.port=$MESSAGING_PORT --hono.client.username=consumer --hono.client.password=foobar --tenant.id=myapp.iot --hono.client.trustStorePath=tls.crt --device.id=4711 --spring.profiles.active=command
  3. コマンドの名前、ペイロード、およびコンテンツタイプを入力するための指示に従います。以下に例を示します。

    >>>>>>>>> Enter name of command for device [4711] in tenant [myapp.iot] (prefix with 'ow:' to send one-way command):
    ow:setVolume
    >>>>>>>>> Enter command payload:
    {"level": 50}
    >>>>>>>>> Enter content type:
    application/json
    
    INFO  org.eclipse.hono.cli.app.Commander - Command sent to device

    クライアントは HTTP 応答でコマンドを受け取ります。

    HTTP/1.1 200 OK
    hono-command: setVolume
    content-type: application/json
    content-length: 13
    
    {"level": 50}