Se ha denunciado esta presentación.
Se está descargando tu SlideShare. ×

2023-01-26_IoTに活かそう!「UNIXという考え方」.pdf

Anuncio
Anuncio
Anuncio
Anuncio
Anuncio
Anuncio
Anuncio
Anuncio
Anuncio
Anuncio
Anuncio
Anuncio
Cargando en…3
×

Eche un vistazo a continuación

1 de 45 Anuncio

2023-01-26_IoTに活かそう!「UNIXという考え方」.pdf

Descargar para leer sin conexión

2023年1月26日(木)に開催されたJAWS-UG IoT専門支部イベントの講演資料です。AWS活用の鍵を握るUNIXという考え方をIoT開発に応用する方法について簡単に説明しています。

2023年1月26日(木)に開催されたJAWS-UG IoT専門支部イベントの講演資料です。AWS活用の鍵を握るUNIXという考え方をIoT開発に応用する方法について簡単に説明しています。

Anuncio
Anuncio

Más Contenido Relacionado

Similares a 2023-01-26_IoTに活かそう!「UNIXという考え方」.pdf (20)

Más de Akira Tateishi (9)

Anuncio

Más reciente (20)

2023-01-26_IoTに活かそう!「UNIXという考え方」.pdf

  1. 1. IoTに活かそう! 「UNIXという考え方」 2023年1月26日 AWS Community Builder JAWS-UG IoT専門支部運営メンバー 立石(株式会社グリーンノート)
  2. 2. 自己紹介 2023/01/26 © 2023 Greennote Inc. All rights reserved. 1 l 立石 彰 Ø 株式会社グリーンノート 代表取締役社長 Ø AWS Community Builder (3年目) l 製造業とITの2足歩行で33年 Ø 材料、部品、装置からシステムまで開発 Ø 独立して5年目 Ø 幻滅期のIoTを復興するお手伝いをしています l 好きなAWSサービス Ø IoT Analytics、Greengrass、1-click
  3. 3. 「UNIXという考え方」 2023/01/26 © 2023 Greennote Inc. All rights reserved. 2 l みなさんご存知のこととは思いますが… l re:Invent 2022で行われたキーノートスピーチ Ø Dr. Werner Vogels, Amazon.com Vice President and Chief Technology Officer l 雑なまとめ Ø 世の中のできごとは同時多発的に発生するもの Ø それを処理するシステムは非同期・疎結合であるべき Ø 「小さく」「単純な」コンポーネントの組み合わせ Ø コンポーネント間を流れる「イベント」 l UNIXが体現した世界
  4. 4. アーカイブが見られます 2023/01/26 © 2023 Greennote Inc. All rights reserved. 3
  5. 5. 2023/01/26 © 2023 Greennote Inc. All rights reserved. 4 reCap
  6. 6. UNIXパイプ 2023/01/26 © 2023 Greennote Inc. All rights reserved. 5 AWS re:Invent 2022 - Keynote with Dr. Werner Vogels より(35分22秒)
  7. 7. UNIXパイプ 2023/01/26 © 2023 Greennote Inc. All rights reserved. 6 access.log を読み込み /gateway/allapi を含む行を取り出し " 500 を含む行を取り出し テキストの順序を反転 スペースで区切られた要素の4番目を取り出し テキストの順序を反転 並べ替え 重複削除
  8. 8. access̲log の例 2023/01/26 © 2023 Greennote Inc. All rights reserved. 7
  9. 9. grep /api 2023/01/26 © 2023 Greennote Inc. All rights reserved. 8
  10. 10. grep "¥" 200" 2023/01/26 © 2023 Greennote Inc. All rights reserved. 9
  11. 11. rev 2023/01/26 © 2023 Greennote Inc. All rights reserved. 10
  12. 12. cut -d " " -f4 2023/01/26 © 2023 Greennote Inc. All rights reserved. 11
  13. 13. rev | sort | uniq 2023/01/26 © 2023 Greennote Inc. All rights reserved. 12 access̲logのうち、/apiへのアクセスが200となったケースの一覧
  14. 14. IoT開発の現場では…… 2023/01/26 © 2023 Greennote Inc. All rights reserved. 13 l デバッグ手段が限られる場合が多い Ø ログファイルを回収して解析するしかない場合も l ログ解析能力が開発効率向上に直結 Ø デバッグログは極めて大量になりがち Ø しかし、必要なログはごく少数である場合が多い Ø 手作業では効率が悪いだけでなく、抜け漏れが発生 l UNIXライクなツールを使いこなして 開発効率を上げよう!
  15. 15. その他 IoT開発者必修コマンド 2023/01/26 © 2023 Greennote Inc. All rights reserved. 14 l sed Ø 主に行単位で検索、置換、抽出などを実行 l awk Ø テキストからのデータ抽出、演算、整形出力など l jq Ø JSONファイルの整形、抽出、データ処理など
  16. 16. 特にAWS CLIとの相性は抜群 2023/01/26 © 2023 Greennote Inc. All rights reserved. 15 ローカル リモート ローカルで生成した一時クレデンシャルを リモート側に渡したい コピペが面倒 かつ ミスが発生しやすい
  17. 17. 特にAWS CLIとの相性は抜群 2023/01/26 © 2023 Greennote Inc. All rights reserved. 16 AWS CLIの出力結果から、コピペ可能な一時クレデンシャルを生成
  18. 18. 2023/01/26 © 2023 Greennote Inc. All rights reserved. 17 パイプ以外にも……
  19. 19. その他のパターン 2023/01/26 © 2023 Greennote Inc. All rights reserved. 18
  20. 20. Lチカを考える 2023/01/26 © 2023 Greennote Inc. All rights reserved. 19 0.5秒おきにLEDを点滅させてください。
  21. 21. Lチカを考える 2023/01/26 © 2023 Greennote Inc. All rights reserved. 20 スタート LEDを点灯させる 0.5秒待つ LEDを消灯する 0.5秒待つ
  22. 22. Lチカを考える 2023/01/26 © 2023 Greennote Inc. All rights reserved. 21 あ、やっぱりボタンで ON/OFFできるように してください。
  23. 23. Lチカを考える 2023/01/26 © 2023 Greennote Inc. All rights reserved. 22 スタート LEDを点灯させる ボタンが押されるのを待つ LEDを消灯する ボタンが離されるのを待つ
  24. 24. Lチカを考える 2023/01/26 © 2023 Greennote Inc. All rights reserved. 23 いや、そうじゃなくて ボタンが押されたら 光るようにしてください。
  25. 25. Lチカを考える 2023/01/26 © 2023 Greennote Inc. All rights reserved. 24 スタート ボタンが押されるのを待つ LEDを点灯させる ボタンが離されるのを待つ LEDを消灯させる
  26. 26. Lチカを考える 2023/01/26 © 2023 Greennote Inc. All rights reserved. 25 ボタンを2つに増やして、 LEDも2つに増やします LED①はタイマーで 制御してください センサを追加して、 値に応じて光らせましょう ボタンを押したらLED②を 点滅させてください ……
  27. 27. Lチカを考える 2023/01/26 © 2023 Greennote Inc. All rights reserved. 26 もうムリ。
  28. 28. 実装を考えてみよう 2023/01/26 © 2023 Greennote Inc. All rights reserved. 27 l 使用するプラットフォームごとに違ってくる Ø FreeRTOSなど ü OSレベルでキュー、メッセージ、ストリームなど 高度な処理がサポートされている Ø Arduino ü 適切な外部ライブラリを使用する必要あり (自分で実装することも不可能ではない) Ø AWS IoT Greengrass ü コンポーネント間通信によるPub/Subをサポート
  29. 29. AWS IoT Greengrassとは 2023/01/26 © 2023 Greennote Inc. All rights reserved. 28
  30. 30. AWS IoT Greengrassとは 2023/01/26 © 2023 Greennote Inc. All rights reserved. 29 コンポーネント
  31. 31. UNIX的なコンポーネント設計 2023/01/26 © 2023 Greennote Inc. All rights reserved. 30 l 小さく単純なコンポーネント l それぞれが疎結合なコンポーネント群 l 非同期的なコンポーネント間の通信 l 開発効率化 l デプロイ工数削減 l 管理工数削減 等々
  32. 32. 実例 2023/01/26 © 2023 Greennote Inc. All rights reserved. 31 l センサ可視化ソリューション Ø 現在はCO2センサに対応 Ø 夏に向けWBGTセンサなど追加予定 l 多様な入力、出力に対応したい Ø EnOcean、BLE、I2Cなど Ø 内蔵データベース、表示画面 Ø クラウド連携 l 管理工数、開発工数の削減 Ø Greengrassを効率的に使う工夫
  33. 33. 複雑に入り組んだデータの流れ 2023/01/26 © 2023 Greennote Inc. All rights reserved. 32 センサ センサ センサ CO2センサ データ解釈 WBGTセンサ データ解釈 温湿度センサ データ解釈 監視データ収集 EnOcean BLE Wi-Fi I2C クラウド連携 DB 可視化 その他のセンサ データ解釈 認証・認可
  34. 34. ブローカーによる流れの整理 2023/01/26 © 2023 Greennote Inc. All rights reserved. 33 センサ センサ センサ CO2センサ データ解釈 WBGTセンサ データ解釈 温湿度センサ データ解釈 監視データ収集 クラウド連携 DB 可視化 その他のセンサ データ解釈 認証・認可
  35. 35. Grenngrass IPC (Pub/Sub) 2023/01/26 © 2023 Greennote Inc. All rights reserved. 34 Subscriber Subscriber Subscriber Subscriber Subscriber Publisher Broker publish̲to̲topic() aws.greengrass#PublishToTopic subscribe̲to̲topic() aws.greengrass#SubscribeToTopic
  36. 36. Greengrassコンポーネント 2023/01/26 © 2023 Greennote Inc. All rights reserved. 35 コンポーネント recipe.yaml / recipe.json gdk-config.json 実行ファイルなど コンポーネント自体に関する情報 コンポーネントの中身に関する情報 実行可能であればおよそ何でも
  37. 37. 権限設定 recipe.json 2023/01/26 © 2023 Greennote Inc. All rights reserved. 36 { "accessControl": { "aws.greengrass.ipc.pubsub": { "com.example.MyLocalPubSubComponent:pubsub:1": { "policyDescription": "Allows access", "operations": [ "aws.greengrass#PublishToTopic", "aws.greengrass#SubscribeToTopic" ], "resources": [ "*" ] } } } }
  38. 38. Publish部のpythonコード例 2023/01/26 © 2023 Greennote Inc. All rights reserved. 37 from awsiot.greengrasscoreipc.clientv2 import ¥ GreengrassCoreIPCClientV2 from awsiot.greengrasscoreipc.model import ( PublishMessage, BinaryMessage ) ipc_client = GreengrassCoreIPCClientV2() binary_message = ¥ BinaryMessage(message=bytes(message, 'utf-8')) publish_message = ¥ PublishMessage(binary_message=binary_message) ipc_client.publish_to_topic( ¥ topic=topic, publish_message=publish_message)
  39. 39. Subscribe部のpythonコード例 2023/01/26 © 2023 Greennote Inc. All rights reserved. 38 from awsiot.greengrasscoreipc.clientv2 import ¥ GreengrassCoreIPCClientV2 from awsiot.greengrasscoreipc.model import ( SubscriptionResponseMessage ) ipc_client = GreengrassCoreIPCClientV2() _, operation = ipc_client.subscribe_to_topic( topic=topic, on_stream_event=on_stream_event, on_stream_error=on_stream_error, on_stream_closed=on_stream_closed ) def on_stream_event(event: SubscriptionResponseMessage) -> None: def on_stream_error(error: Exception) -> bool: def on_stream_closed() -> None:
  40. 40. 小さく単機能なコンポーネント 2023/01/26 © 2023 Greennote Inc. All rights reserved. 39 CO2センサ データ解釈 WBGTセンサ データ解釈 温湿度センサ データ解釈 監視データ収集 クラウド連携 DB 可視化 その他のセンサ データ解釈 認証・認可 ハードウェア関連 LED、ボタン等 AWS IoT Greengrass
  41. 41. コンポーネント開発の例 2023/01/26 © 2023 Greennote Inc. All rights reserved. 40 CO2センサ USBドングル 産業用Raspberry Pi EnOcean 細切れのバイナリデータ 意味のあるパケット データパケット 抽出 800ppm パース コンポーネント コンポーネント ブローカー
  42. 42. メリット① 拡張性 2023/01/26 © 2023 Greennote Inc. All rights reserved. 41 細切れのバイナリデータ 意味のあるパケット データパケット 抽出 CO2 パース コンポーネント コンポーネント ブローカー 熱中症 その他 パーサを用意するだけで対応センサが増やせる
  43. 43. メリット② テストが容易 2023/01/26 © 2023 Greennote Inc. All rights reserved. 42 ダミーパケット パース 多数のテストケースに対する単体テストが容易に実施/自動化できる 800ppm テストデータ 800ppm 結果 自動テスト
  44. 44. まとめ 2023/01/26 © 2023 Greennote Inc. All rights reserved. 43 l UNIXという考え方は、 IoT開発においても大変重要になります。 l 開発途中のログ解析には、 UNIXライクなツールの使いこなしが効果大です。 l IoTは現実社会を写す鏡です。 同時多発的に様々なことが起こるだけでなく、 さまざまな予測不能なできごとが発生します。 l IoTの設計にUNIXという考え方を活かすことで、 非同期・疎結合 かつ 開発しやすい設計が できるようになります。

×