Lab2 で Cloud9 を選択した場合は 3-2-a を、Raspberry Pi を選択した場合は 3-2-b を実施してください。
ターミナルもしくは Tera Term から先程ダウンロードした証明書を Raspberry Pi に転送します
先程ダウンロードした対象の証明書を Tera Term にドラッグ&ドロップします。
**-certificate.pem.crt
**-private.pem.key
./dummy_client/certs/
と入力する以下のコマンドの ~/Downloads/**
の部分と <IPアドレス>
をご自身のファイル名、Raspberry Pi のIPアドレスに修正して、コマンドを実行します。
scp ~/Downloads/**-private.pem.key ~/Downloads/**-certificate.pem.crt pi@<IPアドレス>:./dummy_client/certs/
ターミナルもしくはTera TermからRaspberry Piへ接続した状態で、以下のコマンドを実行していきます。
以下のコマンドを実行し、AWS IoT のルートCA証明書をダウンロードします。
cd ~/dummy_client/certs/
wget https://www.amazontrust.com/repository/AmazonRootCA1.pem -O AmazonRootCA1.pem
以下のコマンドを実行し、dummy client を起動します。
{ご自分の作ったモノ名}
と {AWS IoTのendpoint_url}
は事前にメモした内容に置き換えます
python3 device_main.py --device_name tanaka-20200723 --endpoint xxxxx-ats.iot.ap-northeast-1.amazonaws.com
cd ~/dummy_client/
python3 device_main.py --device_name {ご自分の作ったモノ名} --endpoint {AWS IoTのendpoint_url}
上記コマンドを実行すると、 dummy client は AWS IoT Core へ MQTT で接続し、5秒おき(デフォルト設定の場合)にメッセージを送信します。
topic
をメモしておいてください。(以下の例では data/tanaka-20200723
です)device_name: tanaka-20200723
endpoint: random-ats.iot.ap-northeast-1.amazonaws.com
rootca cert: ./certs/AmazonRootCA1.pem
private key: ./certs/random-private.pem.key
certificate: ./certs/random-certificate.pem.crt
Check latest Shadow status
Subscribing to Shadow Delta events...
Subscribing to Shadow Update responses...
Finished getting initial shadow state.
un subscribe from get shadow events
topic: data/tanaka-20200723
モノの名前や AWS IoT のエンドポイント URL は AWS CLI などを用いて取得することも可能です。
aws iot list-things
aws iot describe-endpoint --endpoint-type iot:Data-ATS
AWS IoT画面の左メニューから テスト
を選択し 先程メモしたtopic名を入力して、トピックへのサブスクライブをすると送信されたデータが確認できます。