3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

プロキシ環境内からのAWS IoT デバイスへのメッセージ送信

Last updated at Posted at 2019-02-04

結論

mosquitto コマンドによるMQTTのpublishではなく、curl コマンドでHTTPS POST すればいい。

AWS IoT のデバイスは、Rest API エンドポイントで、MQTTだとポート8883番、 HTTP だと8443番で同じようにメッセージ受信できる。
curl なら、Linux やMac 上で、https_proxy/http_proxy/HTTPS_PROXY/HTTPS_PROXYの環境変数にプロキシサーバの値を設定すれば稼働する。
mosquitto は、これらの環境変数を設定しても動作せず。

方法

以下のように記述する。

ルート証明書ファイル名 < rootCA >
デバイス証明書ファイル名 : < crt >
プライベートキーファイル名 : < private_key >
エンドポイント : < endpoint >
トピック名 : < topic >
デバイス名称 : < device_name >
JSON 形式のメッセージ : < message >

$ mosquitto_pub \
      --cafile <rootCA> --cert <crt> --key <private_key> \
      -h < endpoint > -p 8883 -q 1 -d \
      -t gauge/1 -i <device_name> \
      -m '<message>'
$ curl -D - --tlsv1.2 -X POST \
      --cacert <rootCA> --cert <crt> --key <private_key> \
      "https://<endpoint>:8443/topics/<topic>?qos=1" \
      -d <message>
3
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?