準備編の資料 本編の資料 …...© 2020, Amazon Web Services, Inc. or its Affiliates. All...

103
© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 準備編の資料 http://bit.ly/AfrHandsonPrep 本編の資料 http://bit.ly/AfrHandsOn_2020 コピペテキスト http://bit.ly/2QfUFoA

Transcript of 準備編の資料 本編の資料 …...© 2020, Amazon Web Services, Inc. or its Affiliates. All...

Page 1: 準備編の資料 本編の資料 …...© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. アマゾンウェブサービスジャパン株式会社 Amazon

© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

• 準備編の資料

• http://bit.ly/AfrHandsonPrep

• 本編の資料

• http://bit.ly/AfrHandsOn_2020

• コピペテキスト

• http://bit.ly/2QfUFoA

Page 2: 準備編の資料 本編の資料 …...© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. アマゾンウェブサービスジャパン株式会社 Amazon

© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

アマゾン ウェブ サービスジャパン株式会社

Amazon FreeRTOS ハンズオン本編

Page 3: 準備編の資料 本編の資料 …...© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. アマゾンウェブサービスジャパン株式会社 Amazon

© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

シナリオ1: シャドウによるデバイスコントロール

AWS IoT

Amazon FreeRTOS

AWS Cloud

Page 4: 準備編の資料 本編の資料 …...© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. アマゾンウェブサービスジャパン株式会社 Amazon

© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

シナリオ2: センサーデータの可視化

AWS IoT AmazonElasticSearch

Browser

Amazon FreeRTOS

AWS Cloud

Page 5: 準備編の資料 本編の資料 …...© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. アマゾンウェブサービスジャパン株式会社 Amazon

© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

シナリオ3: センサーデータによるデバイスコントロール

AWS IoT

Lambda

Amazon FreeRTOSAmazon FreeRTOS

AWS Cloud

Page 6: 準備編の資料 本編の資料 …...© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. アマゾンウェブサービスジャパン株式会社 Amazon

© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

作業の流れ

• デバイスを AWS IoT に登録する• デバイスに付与する Policy を作成する• AWS IoT にデバイスを登録し、接続に必要な秘密鍵と証明書をダウンロードする• 接続先の endpoint を確認する

• Amazon FreeRTOS をダウンロードし、ビルドする• AWS コンソールより Amazon FreeRTOS をダウンロードする• STM32 System Workbench に import してビルドする

• プロジェクトを編集する• デバイス名、接続先の endpoint、接続する Wi-Fi 情報を設定する• デバイスの証明書と秘密鍵を設定する

• サンプルを実⾏• サンプルを実⾏し、AWS IoT に接続できることを確認する• デバッグが機能することを確認する。ソースを眺めてみる

Page 7: 準備編の資料 本編の資料 …...© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. アマゾンウェブサービスジャパン株式会社 Amazon

© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

作業の流れ

• シナリオ1) シャドウのふるまいを確認する• ハンズオンサンプル1 をプロジェクトに追加する• クラウドからシャドウを変更することでデバイスをコントロールできることを確認する

• シナリオ2) センサーデータを可視化する• ハンズオンサンプル2 を実⾏し、ボードのセンサ情報のアップロードを確認する• AWS IoT Rule と ElasticSearch の設定により、センサデータを可視化する

• シナリオ3) センサーデータをもとにデバイスをコントロールする• AWS IoT Rule と Lambda の設定により、シャドウをコントロールする• 近接センサの値により、LED がコントロールされることを確認する

• 後⽚付け• ElasticSearch の削除

Page 8: 準備編の資料 本編の資料 …...© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. アマゾンウェブサービスジャパン株式会社 Amazon

© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

必要な機材の確認

• STM32 Discovery kit IoT node• マイクロ usb ケーブル• 事前準備を完了した開発⽤ PC

Page 9: 準備編の資料 本編の資料 …...© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. アマゾンウェブサービスジャパン株式会社 Amazon

© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

AWS Management Console へログイン

• Region: 東京 に設定

Page 10: 準備編の資料 本編の資料 …...© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. アマゾンウェブサービスジャパン株式会社 Amazon

© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

AWS IoT のエンドポイントを確認する

• AWS IoT の Top 画⾯に戻って 設定 を選択• エンドポイント をメモ (あとで利⽤します)

AWS IoT のエンドポイント(接続先)はアカウントごと、リージョンごとに異なります。

このボタンが有る場合は、押してください

Page 11: 準備編の資料 本編の資料 …...© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. アマゾンウェブサービスジャパン株式会社 Amazon

© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

デバイスに付与する Policy を作成する (1/4)

• Management Console => IoT Core• 安全性 => ポリシー => ポリシーの作成(左図)• すでに使ったことがある⽅は右上の作成(右図)

Page 12: 準備編の資料 本編の資料 …...© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. アマゾンウェブサービスジャパン株式会社 Amazon

© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

デバイスに付与する Policy を作成する (2/4)

• 名前を⼊⼒ (任意、例︓afs_handson_${your_id})• アドバンストモードを選択

Page 13: 準備編の資料 本編の資料 …...© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. アマゾンウェブサービスジャパン株式会社 Amazon

© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

デバイスに付与する Policy を作成する (3/4)

• ポリシー構⽂が表⽰されるので次をコピー & ペースト• 作成

{"Version": "2012-10-17","Statement": [{"Effect": "Allow","Action": ["iot:Connect","iot:Publish","iot:Subscribe","iot:Receive"

],"Resource": "*"

}]

}

Page 14: 準備編の資料 本編の資料 …...© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. アマゾンウェブサービスジャパン株式会社 Amazon

© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

デバイスに付与する Policy を作成する (4/4)

• ポリシーが作成されたことを確認

Page 15: 準備編の資料 本編の資料 …...© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. アマゾンウェブサービスジャパン株式会社 Amazon

© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

デバイスを AWS IoT に登録する (1/4)

• 管理 => モノ => モノの登録 (左図)• すでに使ったことがある⽅は右上の作成(右図)

Page 16: 準備編の資料 本編の資料 …...© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. アマゾンウェブサービスジャパン株式会社 Amazon

© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

デバイスを AWS IoT に登録する (2/4)

• AWS IoT モノを作成する• 単⼀のモノを作成する

• Thing Registry にデバイスを追加• 名前︓任意

• 例︓afs_handson_device_${your_id}• 後ほど利⽤するのでメモしておく• それ以外はデフォルトのまま 次へ

Page 17: 準備編の資料 本編の資料 …...© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. アマゾンウェブサービスジャパン株式会社 Amazon

© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

デバイスを AWS IoT に登録する (3/4)

• モノに証明書を追加• 1-Click 証明書作成 にて 証明書の作成• 各種ダウンロード• 有効化してポリシーのアタッチ

忘れずに︕あとで同じものをダウンロードすることはできません。

こちらはあとでも設定可能ですが忘れがちなので注意

エンドポイントの作成が終わっていない場合エラーになることがあります。その場合は、1〜2分待ってから再度作成を押してください

Page 18: 準備編の資料 本編の資料 …...© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. アマゾンウェブサービスジャパン株式会社 Amazon

© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

デバイスを AWS IoT に登録する (4/4)

• モノにポリシーを追加• 先ほど作成したポリシーを選択してモノの登録

• モノが作成されたことを確認

Page 19: 準備編の資料 本編の資料 …...© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. アマゾンウェブサービスジャパン株式会社 Amazon

© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

Amazon FreeRTOS のダウンロード

ZIPファイルを以下のリンクからダウンロード

http://bit.ly/2Zo5ysvAmazonFreeRTOS-201912.00-handson-st.zipを展開

Page 20: 準備編の資料 本編の資料 …...© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. アマゾンウェブサービスジャパン株式会社 Amazon

© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

System Workbench for STM32 の起動

• 事前準備でインストールした System Workbench for STM32 を起動する• Workspace に事前準備で作成したパスを指定する• 表⽰される Welcome タブは閉じる

Page 21: 準備編の資料 本編の資料 …...© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. アマゾンウェブサービスジャパン株式会社 Amazon

© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

System Workbench にインポート

• File > Import• Select

• General > Existing Projects into Workspace > Next

Page 22: 準備編の資料 本編の資料 …...© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. アマゾンウェブサービスジャパン株式会社 Amazon

© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

System Workbench にインポート

• Import Projects• Select root directory > Browse

• ${BASE_FOLDER}/AmazonFreeRTOS/projects/st/stm32l475_discovery/ac6※BASE_FOLDERはダウンロードしたzipを展開した時に出来たフォルダ

• aws_testのチェックを外す• Finish

Page 23: 準備編の資料 本編の資料 …...© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. アマゾンウェブサービスジャパン株式会社 Amazon

© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

プロジェクトのビルド

• Project > Build All• ビルド完了後、 Problems で 0 errors となっていることを確認(少し時

間がかかります)

Page 24: 準備編の資料 本編の資料 …...© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. アマゾンウェブサービスジャパン株式会社 Amazon

© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

プロジェクトの編集• 作成した環境に合わせて以下を修正

• aws_demos\demos\include\aws_clientcredential.h• clientcredentialMQTT_BROKER_ENDPOINT: メモした AWS IoT のエンドポイント

• 例︓12345678-ats.iot.ap-southeast-1.amazonaws.com• clientcredentialIOT_THING_NAME: メモした AWS IoT に登録したデバイス名

• 例︓ fs_handson_device_yourname• clientcredentialWIFI_SSID: デバイスが接続する Wi-Fi の SSID• clientcredentialWIFI_PASSWORD: デバイスが接続する Wi-Fi の Password

Page 25: 準備編の資料 本編の資料 …...© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. アマゾンウェブサービスジャパン株式会社 Amazon

© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

デバイスの証明書と秘密鍵を設定 (1/2)

• 本作業は Workbench 上でなく、エクスプローラ/Finderから実施します• 下記の html ファイルをブラウザにDrag&Dropして開きます

• ${BASE_FOLDER}/AmazonFreeRTOS/tools/certificate_configuration/CertificateConfigurator.html

• ファイルを選択 で次のファイルを設定のうえ、Generate and save • Certificate PEM file: 先の⼿順でダウンロードした証明書(xxx-certificate.pem.crt)• Private Key PEM file:先の⼿順でダウンロードした秘密鍵(xxx-private.pem.key)

簡単に開発を始められるように、開発フェーズでは、証明書と秘密鍵をソースコード上にハードコードします。この html ツールは、ハードコードされたヘッダファイルを⽣成するためのツールになります。本番環境では、デバイスのセキュア領域に秘密鍵を保持する必要があります。

Page 26: 準備編の資料 本編の資料 …...© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. アマゾンウェブサービスジャパン株式会社 Amazon

© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

デバイスの証明書と秘密鍵を設定 (2/2)

• ダウンロードした aws_clientcredential_keys.h をエクスプローラーorFinder上の ${BASE_FOLDER}/AmazonFreeRTOS/demos/includes に置き換える

• aws_clientcredential_keys.h をEclipseにドラッグ&ドロップはしないでください

Page 27: 準備編の資料 本編の資料 …...© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. アマゾンウェブサービスジャパン株式会社 Amazon

© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

サンプルを実⾏

• デバイスと PC をマイクロ USB (ST-LINK) で接続• プロジェクトを再ビルド (Project > Build All)

USB (ST-LINK)

Page 28: 準備編の資料 本編の資料 …...© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. アマゾンウェブサービスジャパン株式会社 Amazon

© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

サンプルを実⾏ (1/4)

• ターミナルソフトウェアでボードの出⼒を表⽰する• Windows

• 後述• Mac

• $ screen /dev/tty.usbmodem**** 115200

• コマンド⼊⼒後にEnterをすると、⼊⼒待ち状態になります

• 使い慣れたターミナルソフトウェアがある場合はそちらをお使い頂いても構いません。

**** は環境によって異なります。ls コマンドで実際のパスを確認してください。

Page 29: 準備編の資料 本編の資料 …...© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. アマゾンウェブサービスジャパン株式会社 Amazon

© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

Windows) Tera Term でデバイスに接続(1/3)

Tera Termを起動し、connectionで「Serial」を選択し、Portのドロップダウンで“STMicroelectronics”を選択して「OK」をクリックします。

※Tera Termがインストール されていない場合

は、以下のリンクからインストールしてください

https://ja.osdn.net/projects/ttssh2/

※Serialの欄がグレーアウトされている場合ST-Link側のUSB端⼦に接続されているかをご確認ください。また、データ通信可能なUSBケーブルを使⽤しているかをご確認ください。

Page 30: 準備編の資料 本編の資料 …...© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. アマゾンウェブサービスジャパン株式会社 Amazon

© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

Windows) Tera term でデバイスに接続(2/3)

メニューの Setup > Serial port を選択し、Baud rateを「115200」に変更し、「OK」をクリックします

Page 31: 準備編の資料 本編の資料 …...© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. アマゾンウェブサービスジャパン株式会社 Amazon

© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

Windows) Tera term でデバイスに接続(3/3)

メニューの Setup > Terminal を選択し、New-lineの設定で、Receiveを「Auto」、Transmitを「LF」、Local echoにチェックを付けて「OK」をクリックします。(この時点では何も表⽰されません)

Page 32: 準備編の資料 本編の資料 …...© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. アマゾンウェブサービスジャパン株式会社 Amazon

© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

サンプルを実⾏ (2/4)

• AWS Console で IoT Core を開く• テスト

• トピックのサブスクリプション: #• トピックへのサブスクライブ

AWS IoT には、 AWS IoT の各トピックに発⾏されたメッセージを確認するテスト機能があります。トピック”#”はワイルドカードで、この AWS IoT の全トピックに発⾏されたメッセージを表⽰します。

Page 33: 準備編の資料 本編の資料 …...© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. アマゾンウェブサービスジャパン株式会社 Amazon

© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

サンプルを実⾏ (3/4)

• Project Explorer で aws_demos を右クリック > Debug As > Ac6 STM32 C/C++ Application

• Confirm Perspective Switch• Yes

Page 34: 準備編の資料 本編の資料 …...© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. アマゾンウェブサービスジャパン株式会社 Amazon

© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

サンプルを実⾏ (4/4)

• main.c の main 関数にブレークポイントが貼られており、デバッグモードとして起動することを確認する

• Resume し、動作確認を⾏う(次ページ)

ブレークポイントで停⽌します

Page 35: 準備編の資料 本編の資料 …...© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. アマゾンウェブサービスジャパン株式会社 Amazon

© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

動作確認 (1/2)

• ターミナル(メッセージの送信までは、少し時間がかかります)

1 3 [Tmr Svc] Write root certificate...2 16 [Tmr Svc] Write device private key...3 454 [Tmr Svc] Write device certificate...4 468 [Tmr Svc] Key provisioning done...5 1053 [Tmr Svc] WiFi module initialized.6 5262 [Tmr Svc] WiFi connected to AP Mobile.7 5266 [Tmr Svc] IP Address acquired 192.168.1.1508 5271 [Tmr Svc] Creating MQTT Echo Task...9 5275 [MQTTEcho] MQTT echo attempting to connect to a1i67hwbky874f.iot.ap-northeast-1.amazonaws.co10 5283 [MQTTEcho] Sending command to MQTT task.11 5288 [MQTT] Received message 10000 from queue.12 28000 [MQTT] About to close socket.13 28239 [MQTT] Socket closed.14 28241 [MQTT] Notifying task.15 28244 [MQTTEcho] Command sent to MQTT task failed.16 28249 [MQTTEcho] ERROR: MQTT echo failed to connect.17 28255 [MQTTEcho] MQTT echo test could not connect to broker.18 28260 [MQTTEcho] Sending command to MQTT task.19 28265 [MQTT] Received message 20000 from queue.20 28270 [MQTT] Notifying task.21 28273 [MQTTEcho] Command sent to MQTT task passed.22 28278 [MQTTEcho] MQTT echo demo finished.

0 [Tmr Svc] Starting key provisioning...1 3 [Tmr Svc] Write root certificate...2 16 [Tmr Svc] Write device private key...3 454 [Tmr Svc] Write device certificate...4 468 [Tmr Svc] Key provisioning done...5 1053 [Tmr Svc] WiFi module initialized.6 5179 [Tmr Svc] WiFi connected to AP Mobile.7 5183 [Tmr Svc] IP Address acquired 192.168.1.1508 5188 [Tmr Svc] Creating MQTT Echo Task...9 5192 [MQTTEcho] MQTT echo attempting to connect to a1i67hwbky874f.iot.ap-northeast-1.amazonaws.co10 5200 [MQTTEcho] Sending command to MQTT task.11 5205 [MQTT] Received message 10000 from queue.12 29850 [MQTT] MQTT Connect was accepted. Connection established.13 29856 [MQTT] Notifying task.14 30068 [MQTTEcho] Command sent to MQTT task passed.15 30072 [MQTTEcho] MQTT echo connected.16 30076 [MQTTEcho] MQTT echo test echoing task created.17 30081 [MQTTEcho] Sending command to MQTT task.18 30086 [MQTT] Received message 20000 from queue.19 30897 [MQTT] MQTT Subscribe was accepted. Subscribed.20 30902 [MQTT] Notifying task.21 31114 [MQTTEcho] Command sent to MQTT task passed.22 31118 [MQTTEcho] MQTT Echo demo subscribed to freertos/demos/echo23 31125 [MQTTEcho] Sending command to MQTT task.24 31129 [MQTT] Received message 30000 from queue.25 32398 [MQTT] MQTT Publish was successful.26 32402 [MQTT] Notifying task.27 32757 [Echoing] Sending command to MQTT task.28 32761 [MQTTEcho] Command sent to MQTT task passed.29 32766 [MQTT] Received message 40000 from queue.30 34031 [MQTT] MQTT Publish was successful.31 34035 [MQTT] Notifying task.32 34390 [MQTTEcho] Echo successfully published 'Hello World 0'33 34395 [Echoing] Command sent to MQTT task passed.34 34400 [Echoing] Message returned with ACK: 'Hello World 0 ACK'35 39400 [MQTTEcho] Sending command to MQTT task.36 39404 [MQTT] Received message 50000 from queue.37 40670 [MQTT] MQTT Publish was successful.

正常時の出⼒例

エラー時の出⼒例(AWS IoT への Connect でエラー)⽂字化けする場合は、Baud rate が115200にセットされていない可能性があります。

Page 36: 準備編の資料 本編の資料 …...© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. アマゾンウェブサービスジャパン株式会社 Amazon

© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

以下のエラーが出る場合WifiモジュールのUpdateが必要なためAppendix.1 を参照してください

Page 37: 準備編の資料 本編の資料 …...© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. アマゾンウェブサービスジャパン株式会社 Amazon

© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

動作確認 (2/2)• AWS Console

このサンプルはデバイスがHello World というメッセージを順次 publish します。また、publish 先のトピックを⾃分で subscribe しており、メッセージを受け取ると Hello World ACK というメッセージを publish します。

Page 38: 準備編の資料 本編の資料 …...© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. アマゾンウェブサービスジャパン株式会社 Amazon

© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

デバッグの終了

• デバッグを終え、開発画⾯に戻すには Window > Perspective > Open Perspective > C/C++ を選択

Page 39: 準備編の資料 本編の資料 …...© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. アマゾンウェブサービスジャパン株式会社 Amazon

© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

シナリオ1: シャドウによるデバイスコントロール

AWS IoT

Amazon FreeRTOS

AWS Cloud

Page 40: 準備編の資料 本編の資料 …...© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. アマゾンウェブサービスジャパン株式会社 Amazon

© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

このシナリオでは、AWSコンソール側からDevice Shadowを操作すると、その結果がデバイス側に反映される動きを体験します

シナリオ1: シャドウによるデバイスコントロール

Page 41: 準備編の資料 本編の資料 …...© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. アマゾンウェブサービスジャパン株式会社 Amazon

© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

シナリオ1を実⾏するよう設定する

• サンプル1 を実⾏するため、SystemWorkbenchの${BASE_FOLDER}/AmazonFreeRTOS/demos/include/iot_demo_runner.h を開き、次の様にコードを改修する

// #define DEMO_entryFUNCTION RunMqttDemo

#define DEMO_entryFUNCTION RunHandson

コメントアウト

コメントアウトを外す

Page 42: 準備編の資料 本編の資料 …...© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. アマゾンウェブサービスジャパン株式会社 Amazon

© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

サンプル1 を実⾏ (1/2)

• プロジェクトを再ビルド (Project > Build All)• AWS Console で IoT Core を開き、管理 > モノ から作成したモノを選択• Shadow を選択

Page 43: 準備編の資料 本編の資料 …...© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. アマゾンウェブサービスジャパン株式会社 Amazon

© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

シナリオ1 を実⾏ (2/2)

• Project Explorer で aws_demos を右クリック > Debug As > Ac6 STM32 C/C++ Application

• main.c の main 関数にブレークポイントが貼られており、デバッグモードとして起動する

• Resume し、動作確認を⾏う(次ページ)

Page 44: 準備編の資料 本編の資料 …...© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. アマゾンウェブサービスジャパン株式会社 Amazon

© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

動作確認 (1/3)• AWS Console

• プログラムを実⾏後、しばらくすると Shadow Document にデバイスから初期状態がアップロードされる

• デバイスコントロールを⾏うため、Edit を選択

シャドウでは、デバイスは⾃⾝の状態を reported としてアップロードします。このサンプルは起動時にデバイスの初期状態として、LED の電源が OFF であるという報告を⾏います。

Page 45: 準備編の資料 本編の資料 …...© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. アマゾンウェブサービスジャパン株式会社 Amazon

© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

動作確認 (2/3)• シャドウの編集

• 下記のように、desired を追記して Save を選択

シャドウでは、デバイスをコントロールする時はdesired としてデバイスに望む状態を定義します。このサンプルではクラウドからデバイスに対し、LED の電源を ON/OFF するというコントロールを⾏います。

{"desired": {"powerOn": 1

},"reported": {"powerOn": 0

}}

新規追加

Page 46: 準備編の資料 本編の資料 …...© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. アマゾンウェブサービスジャパン株式会社 Amazon

© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

動作確認 (3/3)• シャドウの確認

• 保存すると Shadow state として⼀時的に delta が表⽰される• デバイスの LED2 が点灯する• Shadow state の reported が ”powerOn”: 1 となり、delta が削除される• (再度 desired を 0 にして LED2 が消灯、 reported が更新されることを確認)

LED2 が点灯

シャドウでは、デバイスの実際の状態と、あるべき状態に差分が⽣じると、その差分を delta としてデバイスに通知します。

デバイスは delta を受け取ると、あるべき状態になるようアクションし、正しく更新された後 reported として最新の状態を通知します。

シャドウでは、デバイスの実際の状態とあるべき状態の差分がなくなると delta が削除されます。

Page 47: 準備編の資料 本編の資料 …...© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. アマゾンウェブサービスジャパン株式会社 Amazon

© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

シナリオ2: センサーデータの可視化

AWS IoT AmazonElasticSearch

Browser

Amazon FreeRTOS

AWS Cloud

Page 48: 準備編の資料 本編の資料 …...© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. アマゾンウェブサービスジャパン株式会社 Amazon

© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

Elasticsearch Service の構築 (1/6)

• Management Console => Elasticsearch Service• 新しいドメインの作成• デプロイタイプを“開発およびテスト”を選択

Page 49: 準備編の資料 本編の資料 …...© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. アマゾンウェブサービスジャパン株式会社 Amazon

© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

Elasticsearch Service の構築 (2/6)

• クラスターの設定• Elasticsearch ドメイン名を⼊⼒ (任意、

例︓afs-handson-es-${your_id})• ノードの設定において、インスタンスタ

イプに t2.small.elasticsearch を指定して 次へ を選択

Page 50: 準備編の資料 本編の資料 …...© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. アマゾンウェブサービスジャパン株式会社 Amazon

© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

Elasticsearch Service の構築 (3/6)

• アクセスの設定 (1/2)• ネットワーク構成 で パブリックアクセ

ス を選択• アクセスポリシー で ドメインアクセス

ポリシーの設定 から 特定の IP からのドメインへのアクセスを許可 を設定

Page 51: 準備編の資料 本編の資料 …...© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. アマゾンウェブサービスジャパン株式会社 Amazon

© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

Elasticsearch Service の構築 (4/6)

• アクセスの設定 (2/2)• IP アドレスのダイアログに 現在のネットワークのグローバル IP を指定

• 外部 web サイトの例:http://checkip.amazonaws.com/ など利⽤して⾃分のIPを確認

• アクセスポリシーが追加されたことを確認のうえ、次へ

本ハンズオンの wifi 環境に接続している PC からのみ Elasticsearch にアクセス可能な設定になります。グローバル IP が変わる環境では、その全てを設定するか、IP 指定以外のアクセス許可を検討する必要があります。

Page 52: 準備編の資料 本編の資料 …...© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. アマゾンウェブサービスジャパン株式会社 Amazon

© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

Elasticsearch Service の構築 (5/6)

• 確認• 設定を確認のうえ、確認 を選択

Page 53: 準備編の資料 本編の資料 …...© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. アマゾンウェブサービスジャパン株式会社 Amazon

© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

Elasticsearch Service の構築 (6/6)

• 構築完了• 利⽤できるまで 10 分ほどかかります。完了を待たずに次に進みます。

アクティブになれば作成完了

Page 54: 準備編の資料 本編の資料 …...© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. アマゾンウェブサービスジャパン株式会社 Amazon

© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

このシナリオでは、デバイスから送信されてくるデータをElasticSearchServiceを使って可視化する⽅法について学びます

シナリオ2:センサーデータの可視化

Page 55: 準備編の資料 本編の資料 …...© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. アマゾンウェブサービスジャパン株式会社 Amazon

© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

シナリオ2を実⾏するよう設定する

• シナリオ2を実⾏するため、System Workbench上の${BASE_FOLDER}/AmazonFreeRTOS/demos/handson/aws_iot_handson.c を開き、次の様にコードを改修する

#define ENABLE_SENSORS ( 1 ) 1に変更

Page 56: 準備編の資料 本編の資料 …...© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. アマゾンウェブサービスジャパン株式会社 Amazon

© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

利⽤するセンサー

• 本サンプルでは、温度、湿度、気圧、近接センサーを利⽤• 他にもジャイロ、加速度、磁⼒センサーを利⽤可能

• 近接センサには⻩⾊のシートがかぶせてあるので剥がす

温度・湿度センサ

近接センサ

気圧センサ

Page 57: 準備編の資料 本編の資料 …...© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. アマゾンウェブサービスジャパン株式会社 Amazon

© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

サンプル2 を実⾏ (1/2)

• プロジェクトを再ビルド (Project > Build All)• AWS Console で IoT Core を開き、テスト画⾯を表⽰する

Page 58: 準備編の資料 本編の資料 …...© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. アマゾンウェブサービスジャパン株式会社 Amazon

© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

サンプル2 を実⾏ (2/2)

• Project Explorer で aws_demos を右クリック > Debug As > Ac6 STM32 C/C++ Application

• main.c の main 関数にブレークポイントが貼られており、デバッグモードとして起動する

• Resume し、動作確認を⾏う(次ページ)

Page 59: 準備編の資料 本編の資料 …...© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. アマゾンウェブサービスジャパン株式会社 Amazon

© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

動作確認• AWS Console

このサンプルはデバイスが取得したセンサーデータを順次publish します。近接センサに⼿を近づけて、センサからの距離に応じてproximity の値が変化することを確認してください。

Proximityの値が変化しない場合は近接センサには⻩⾊のシートがかぶせてあるので剥がす

Page 60: 準備編の資料 本編の資料 …...© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. アマゾンウェブサービスジャパン株式会社 Amazon

© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

IoT Rule を作成する (1/6)

• Management Console => IoT Core• ACT => ルールの作成(左図)• すでに使ったことがある⽅は右上の作成(右図)

Page 61: 準備編の資料 本編の資料 …...© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. アマゾンウェブサービスジャパン株式会社 Amazon

© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

IoT Rule を作成する (2/6)

• ルールの作成• 名前を⼊⼒ (任意、例︓afs_handson_scenario2_${your_id})• ルールクエリーステートメント

• SELECT parse_time("yyyy-MM-dd'T'HH:mm:ss.SSSZ", timestamp() ) as TIMESTAMP, * from 'freertos/demos/sensor'

Page 62: 準備編の資料 本編の資料 …...© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. アマゾンウェブサービスジャパン株式会社 Amazon

© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

IoT Rule を作成する (3/6)

• ルールの作成• 1つ以上のアクションを設定する にて アクションの追

加 を選択• ElasticSearch を選択して アクションの設定 を選択

Page 63: 準備編の資料 本編の資料 …...© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. アマゾンウェブサービスジャパン株式会社 Amazon

© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

IoT Rule を作成する (4/6)

• ルールの作成• ドメイン名に先程作成した ElasticSearch を選択• ID, 索引, タイプにそれぞれ下記を⼊⼒

• ID: ${newuuid()}• 索引: sensor• タイプ: sensor

まだ ElasticSearch が出来ていない場合は選択できません。作成した ElasticSearchがアクティブになったことを確認のうえリフレッシュボタン(⻘枠)を押して選択してください。

ElasticSearch 投⼊時の ID はランダムなUUIDを設定します

Page 64: 準備編の資料 本編の資料 …...© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. アマゾンウェブサービスジャパン株式会社 Amazon

© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

IoT Rule を作成する (5/6)

• ルールの作成• ロールの作成を選択• IAM ロール名を⼊⼒して 新しいロールの作成 を選択

• 任意、例: afs_handson_${your_id}_es_role• IAM ロール名に今作成したロールを設定• アクションの追加 を選択

Page 65: 準備編の資料 本編の資料 …...© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. アマゾンウェブサービスジャパン株式会社 Amazon

© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

IoT Rule を作成する (6/6)

• ルールの作成• アクションが追加されたことを確認のうえ、ルールの作成 を選択

• 作成したルールが追加されたことを確認する

Page 66: 準備編の資料 本編の資料 …...© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. アマゾンウェブサービスジャパン株式会社 Amazon

© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

センサーデータを可視化する (1/4)

sensorと入力

Discoverを選択

Next stepを選択

sensorが見つからない場合は、データが届いていない

KibanaのURLをクリック

Page 67: 準備編の資料 本編の資料 …...© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. アマゾンウェブサービスジャパン株式会社 Amazon

© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

センサーデータを可視化する (2/4)

select boxから TIMESTAMPを選択

Create index patternを選択

Page 68: 準備編の資料 本編の資料 …...© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. アマゾンウェブサービスジャパン株式会社 Amazon

© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

センサーデータを可視化する (3/4)

• Visualize で Create a visualization を選択• Select visualization type より Line を選択• From a New Search, Select Index から sensor を選択

Page 69: 準備編の資料 本編の資料 …...© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. アマゾンウェブサービスジャパン株式会社 Amazon

© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

センサーデータを可視化する (4/4)

• 次のように Metrics を設定する• Y-Axis (Add metrics で Field 4種類を設定する)

• Aggregation: Average• Field: humidity / pressure /proximity / temperature

• X-Axis• Aggregation: Date Histogram• Field: TIMESTAMP• Interval: Auto

• Apply Changes を実⾏• グラフを確認

Y-Axis を 4つ、X-Axis を 1つ設定します

近接センサに⼿をかざして、値が上下することを確認してください。

Page 70: 準備編の資料 本編の資料 …...© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. アマゾンウェブサービスジャパン株式会社 Amazon

© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

シナリオ3: センサーデータによるデバイスコントロール

AWS IoT

Lambda

Amazon FreeRTOSAmazon FreeRTOS

AWS Cloud

Page 71: 準備編の資料 本編の資料 …...© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. アマゾンウェブサービスジャパン株式会社 Amazon

© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

このシナリオでは、デバイスから送信されてくるデータをLambdaで判定して、デバイス上のLEDをON/OFFする⽅法について学びます

シナリオ3: センサーデータによるデバイスコントロール

Page 72: 準備編の資料 本編の資料 …...© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. アマゾンウェブサービスジャパン株式会社 Amazon

© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

4-1. Lambdaで利用するロールの設定

TopメニューよりIAMと入力し、選択

Page 73: 準備編の資料 本編の資料 …...© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. アマゾンウェブサービスジャパン株式会社 Amazon

© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

4-2. policyの作成

IAMの画面からポリシーの作成->JSONを選択して右のように編集する

"Version": "2012-10-17","Statement": [

{"Effect": "Allow","Action": [

"logs:CreateLogGroup","logs:CreateLogStream","logs:PutLogEvents"

],"Resource": "arn:aws:logs:*:*:*"

},{

"Effect": "Allow","Action": [

"iot:GetThingShadow","iot:UpdateThingShadow"

],"Resource": [

"*"]

}]

}

Page 74: 準備編の資料 本編の資料 …...© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. アマゾンウェブサービスジャパン株式会社 Amazon

© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

4-3. policyの作成

Policyに任意の名前をつけて、“ポリシーの作成”を押下

Page 75: 準備編の資料 本編の資料 …...© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. アマゾンウェブサービスジャパン株式会社 Amazon

© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

4-4. ロールの作成

ダッシュボードからロールを選択し、 “ロールの作成”を選択

Page 76: 準備編の資料 本編の資料 …...© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. アマゾンウェブサービスジャパン株式会社 Amazon

© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

4-5. エンティティの選択

Lambdaを選択して、次のステップへ

Page 77: 準備編の資料 本編の資料 …...© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. アマゾンウェブサービスジャパン株式会社 Amazon

© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

ロールの作成

先程作成したポリシーにチェックを入れて次のステップを押下

Page 78: 準備編の資料 本編の資料 …...© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. アマゾンウェブサービスジャパン株式会社 Amazon

© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

4-6. タグの追加

今回はタグをつけずに”次のステップ: 確認”を選択

Page 79: 準備編の資料 本編の資料 …...© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. アマゾンウェブサービスジャパン株式会社 Amazon

© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

4-6. ロール名をつけてロール作成

ロール名に”afs_handson_ {お名前}- _lambda_role”を入力

“ロールの作成”を選択

先程選択したポリシーがあることを確認

Page 80: 準備編の資料 本編の資料 …...© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. アマゾンウェブサービスジャパン株式会社 Amazon

© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

Lambda の作成 (1/6)

• Management Console => Lambda• 関数の作成 を選択

• 初めて作成する⼈は左図• 既に作成したことがある⼈は右図

Page 81: 準備編の資料 本編の資料 …...© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. アマゾンウェブサービスジャパン株式会社 Amazon

© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

Lambda の作成 (2/6)

• ⼀から作成 を選択• ランタイム: Python 3.8• ロール: 既存のロールを使⽤する を選択 (先程作成したロールを選択)

Page 82: 準備編の資料 本編の資料 …...© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. アマゾンウェブサービスジャパン株式会社 Amazon

© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

Lambda の作成 (4/6)

• 作成した画⾯をスクロールダウンして、関数コードを表⽰

Page 83: 準備編の資料 本編の資料 …...© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. アマゾンウェブサービスジャパン株式会社 Amazon

© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

Lambda の作成 (5/6)

• 関数コードの設定• http://bit.ly/2ZlhOtI をブラウザで開く

• 表⽰されたソースコードをすべて選択し、以下の場所に上書く

Page 84: 準備編の資料 本編の資料 …...© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. アマゾンウェブサービスジャパン株式会社 Amazon

© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

Lambda の作成 (6/6)

• 環境変数を設定• キー: ThingName

• 値: AWS IoT に登録したデバイス名• キー︓Region

• 値: ap-northeast-1

• 画⾯右上の「保存」を選択

Page 85: 準備編の資料 本編の資料 …...© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. アマゾンウェブサービスジャパン株式会社 Amazon

© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

IoT Rule を作成する (1/5)

• Management Console => IoT Core• ACT => 作成

Page 86: 準備編の資料 本編の資料 …...© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. アマゾンウェブサービスジャパン株式会社 Amazon

© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

IoT Rule を作成する (2/5)

• ルールの作成• 名前を⼊⼒ (任意、例︓afs_handson_scenario3_${your_id})• ルールクエリーステートメント

• select proximity from 'freertos/demos/sensor'

AWS IoT に送られた payload のうち、 proximity のみ後段のアクションの引数にわたすことを意味します。

Page 87: 準備編の資料 本編の資料 …...© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. アマゾンウェブサービスジャパン株式会社 Amazon

© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

IoT Rule を作成する (3/5)

• ルールの作成• 1つ以上のアクションを設定する にて アクションの追

加 を選択• Lambda を選択して アクションの設定 を選択

Page 88: 準備編の資料 本編の資料 …...© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. アマゾンウェブサービスジャパン株式会社 Amazon

© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

IoT Rule を作成する (4/5)

• ルールの作成• 関数名に先程作成した Lambda を選択• アクションの追加 を選択

Page 89: 準備編の資料 本編の資料 …...© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. アマゾンウェブサービスジャパン株式会社 Amazon

© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

IoT Rule を作成する (5/5)

• ルールの作成• アクションが追加されたことを確認のうえ、ルールの作成 を選択

• 作成したルールが追加されたことを確認する

Page 90: 準備編の資料 本編の資料 …...© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. アマゾンウェブサービスジャパン株式会社 Amazon

© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

実⾏ (1/2)

• プロジェクトを再ビルド (Project > Build All)• AWS Console で IoT Core を開き、テスト画⾯を表⽰する

• トピックのサブスクリプション: freertos/demos/sensor

Page 91: 準備編の資料 本編の資料 …...© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. アマゾンウェブサービスジャパン株式会社 Amazon

© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

実⾏ (1/2)

• ブラウザの別ウィンドウ/タブにて、AWS Console で IoT Core を開き、管理 > モノ から作成したモノを選択

• Shadow を選択

Page 92: 準備編の資料 本編の資料 …...© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. アマゾンウェブサービスジャパン株式会社 Amazon

© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

実⾏ (2/2)

• Project Explorer で aws_demos を右クリック > Debug As > Ac6 STM32 C/C++ Application

• main.c の main 関数にブレークポイントが貼られており、デバッグモードとして起動する

• Resume し、動作確認を⾏う(次ページ)

Page 93: 準備編の資料 本編の資料 …...© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. アマゾンウェブサービスジャパン株式会社 Amazon

© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

動作確認 (1/2)• AWS Console

近接センサに⼿を近づけて、proximity の値を300以下にしてください。

Page 94: 準備編の資料 本編の資料 …...© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. アマゾンウェブサービスジャパン株式会社 Amazon

© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

動作確認 (2/2)• シャドウの確認

• Proximity が 300 未満になると Shadow state として⼀時的に delta が表⽰される• デバイスの LED2 が点灯する• Shadow state の reported が ”powerOn”: 1 となり、delta が削除される• (Proxymity が 300 以上になると desired を 0 にして LED2 が消灯、 reported が更

新される)LED2 が点灯

シャドウでは、デバイスの実際の状態と、あるべき状態に差分が⽣じると、その差分を delta としてデバイスに通知します。

デバイスは delta を受け取ると、あるべき状態になるようアクションし、正しく更新された後 reported として最新の状態を通知します。

シャドウでは、デバイスの実際の状態とあるべき状態の差分がなくなると delta が削除されます。

Page 95: 準備編の資料 本編の資料 …...© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. アマゾンウェブサービスジャパン株式会社 Amazon

© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

後⽚付け• ElasticSearch Service

• 起動しているとお⾦がかかるので、これだけは忘れずに• AWS IoT Core

• ルール• モノ• 証明書

• Lambdaファンクション• IAM(Role、Policy)• CloudWatch Logs (AWS IoT⽤、Lambda⽤)

Page 96: 準備編の資料 本編の資料 …...© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. アマゾンウェブサービスジャパン株式会社 Amazon

© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

ElasticSearch Service の削除

• Management Console => ElasticSearch Service• 作成したドメインを選択• ドメインの削除を選択• ドメインの削除 にチェックをいれて 削除

Page 97: 準備編の資料 本編の資料 …...© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. アマゾンウェブサービスジャパン株式会社 Amazon

© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

IoT Core:ACTACTを選択し、作成したルールの詳細を開きます。Actions -> Deleteで削除します。作成したルール分繰り返します。

Page 98: 準備編の資料 本編の資料 …...© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. アマゾンウェブサービスジャパン株式会社 Amazon

© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

IoT Core:Things管理=>モノから、作成したモノを選択します。Actions -> 削除を選択し、ダイアログが表示されるので、「はい、削除して続行する」を選択

Page 99: 準備編の資料 本編の資料 …...© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. アマゾンウェブサービスジャパン株式会社 Amazon

© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

IoT Core:証明書安全性=>証明書から、作成した証明書を選択します。「●●●」=>削除を選択し、ダイアログが表示されるので、「はい、削除して続行する」を選択

Page 100: 準備編の資料 本編の資料 …...© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. アマゾンウェブサービスジャパン株式会社 Amazon

© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

IoT Core:ポリシー安全性=>ポリシーから、作成したポリシーを選択します。「●●●」=>削除を選択し、ダイアログが表示されるので、「はい、削除して続行する」を選択

Page 101: 準備編の資料 本編の資料 …...© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. アマゾンウェブサービスジャパン株式会社 Amazon

© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

Lambda作成したLambdaを選択して、Action => 削除を選択ダイアログが表示されるので、削除を選択

Page 102: 準備編の資料 本編の資料 …...© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. アマゾンウェブサービスジャパン株式会社 Amazon

© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

Appendix.1

以下を参考にFWモジュールのアップデートを行ってください

http://bit.ly/365QwKF

Page 103: 準備編の資料 本編の資料 …...© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. アマゾンウェブサービスジャパン株式会社 Amazon

© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.