2
5

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.

Raspberry Pi で、mosquitto を使って、AWS IOT に Pub/Sub する

Last updated at Posted at 2017-12-08

Raspberry Pi の mosquitto-clientsはバージョンが古いため、mosquitto.orgで公開されているdebをインストールする必要があります。
こちらに、その記述が
【Raspberry Pi】AWS IoTとRaspberry PiでIoTをやってみよう

wget http://repo.mosquitto.org/debian/mosquitto-repo.gpg.key
sudo apt-key add mosquitto-repo.gpg.key
get http://repo.mosquitto.org/debian/mosquitto-wheezy.list
sudo cp mosquitto-wheezy.list /etc/apt/sources.list.d/
sudo apt update
sudo apt install mosquitto-clients

IOT のブローカーの作り方は、こちらです。
AWS IOT の簡単な使い方

次が必要です。
 モノの証明書 r10001.cert.pem
 プライベートキー r10001.private.key
 ルート CA root-CA.crt

Publish コマンド
エンドポイントは変更して下さい。

mosquitto_pub --cafile root-CA.crt \
	--cert r10001.cert.pem --key r10001.private.key \
	-h "xxx00iq1d4m00.iot.ap-northeast-1.amazonaws.com" \
	-p 8883 -q 1 -d -t r10001/topic_1 -m "Hello World"

Subscribe コマンド
エンドポイントは変更して下さい。

mosquitto_sub --cafile root-CA.crt --cert r10001.cert.pem \
	--key r10001.private.key \
	-h "xxx00iq1d4m00.iot.ap-northeast-1.amazonaws.com" \
	-p 8883 -q 1 -d -t r10001/topic_1

エンドポイントの調べ方

aws iot describe-endpoint

追加
次のファイルを Publish するには

in01.json
{
  "greeting": "Hello World",
  "key1": "aaa",
  "key2": "bbb",
  "key3": "ccc"
}
mosquitto_pub --cafile root-CA.crt \
    --cert r10001.cert.pem --key r10001.private.key \
    -h "xxx00iq1d4m00.iot.ap-northeast-1.amazonaws.com" \
    -p 8883 -q 1 -d -t r10001/topic_1 -f in01.json
2
5
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
2
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?