Más contenido relacionado
Similar a 2023-01-26_IoTに活かそう!「UNIXという考え方」.pdf (20)
Más de Akira Tateishi (11)
2023-01-26_IoTに活かそう!「UNIXという考え方」.pdf
- 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. 「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が体現した世界
- 6. UNIXパイプ
2023/01/26 © 2023 Greennote Inc. All rights reserved. 5
AWS re:Invent 2022 - Keynote with Dr. Werner Vogels より(35分22秒)
- 7. UNIXパイプ
2023/01/26 © 2023 Greennote Inc. All rights reserved. 6
access.log を読み込み
/gateway/allapi を含む行を取り出し
" 500 を含む行を取り出し
テキストの順序を反転
スペースで区切られた要素の4番目を取り出し
テキストの順序を反転
並べ替え
重複削除
- 12. cut -d " " -f4
2023/01/26 © 2023 Greennote Inc. All rights reserved. 11
- 13. rev | sort | uniq
2023/01/26 © 2023 Greennote Inc. All rights reserved. 12
access̲logのうち、/apiへのアクセスが200となったケースの一覧
- 14. IoT開発の現場では……
2023/01/26 © 2023 Greennote Inc. All rights reserved. 13
l デバッグ手段が限られる場合が多い
Ø ログファイルを回収して解析するしかない場合も
l ログ解析能力が開発効率向上に直結
Ø デバッグログは極めて大量になりがち
Ø しかし、必要なログはごく少数である場合が多い
Ø 手作業では効率が悪いだけでなく、抜け漏れが発生
l UNIXライクなツールを使いこなして
開発効率を上げよう!
- 15. その他 IoT開発者必修コマンド
2023/01/26 © 2023 Greennote Inc. All rights reserved. 14
l sed
Ø 主に行単位で検索、置換、抽出などを実行
l awk
Ø テキストからのデータ抽出、演算、整形出力など
l jq
Ø JSONファイルの整形、抽出、データ処理など
- 26. Lチカを考える
2023/01/26 © 2023 Greennote Inc. All rights reserved. 25
ボタンを2つに増やして、
LEDも2つに増やします
LED①はタイマーで
制御してください
センサを追加して、
値に応じて光らせましょう
ボタンを押したらLED②を
点滅させてください
……
- 28. 実装を考えてみよう
2023/01/26 © 2023 Greennote Inc. All rights reserved. 27
l 使用するプラットフォームごとに違ってくる
Ø FreeRTOSなど
ü OSレベルでキュー、メッセージ、ストリームなど
高度な処理がサポートされている
Ø Arduino
ü 適切な外部ライブラリを使用する必要あり
(自分で実装することも不可能ではない)
Ø AWS IoT Greengrass
ü コンポーネント間通信によるPub/Subをサポート
- 32. 実例
2023/01/26 © 2023 Greennote Inc. All rights reserved. 31
l センサ可視化ソリューション
Ø 現在はCO2センサに対応
Ø 夏に向けWBGTセンサなど追加予定
l 多様な入力、出力に対応したい
Ø EnOcean、BLE、I2Cなど
Ø 内蔵データベース、表示画面
Ø クラウド連携
l 管理工数、開発工数の削減
Ø Greengrassを効率的に使う工夫
- 33. 複雑に入り組んだデータの流れ
2023/01/26 © 2023 Greennote Inc. All rights reserved. 32
センサ
センサ
センサ
CO2センサ
データ解釈
WBGTセンサ
データ解釈
温湿度センサ
データ解釈
監視データ収集
EnOcean
BLE
Wi-Fi
I2C クラウド連携
DB 可視化
その他のセンサ
データ解釈
認証・認可
- 34. ブローカーによる流れの整理
2023/01/26 © 2023 Greennote Inc. All rights reserved. 33
センサ
センサ
センサ
CO2センサ
データ解釈
WBGTセンサ
データ解釈
温湿度センサ
データ解釈
監視データ収集
クラウド連携
DB 可視化
その他のセンサ
データ解釈
認証・認可
- 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. Greengrassコンポーネント
2023/01/26 © 2023 Greennote Inc. All rights reserved. 35
コンポーネント
recipe.yaml / recipe.json
gdk-config.json
実行ファイルなど
コンポーネント自体に関する情報
コンポーネントの中身に関する情報
実行可能であればおよそ何でも
- 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. 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. 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. 小さく単機能なコンポーネント
2023/01/26 © 2023 Greennote Inc. All rights reserved. 39
CO2センサ
データ解釈
WBGTセンサ
データ解釈
温湿度センサ
データ解釈
監視データ収集
クラウド連携
DB
可視化
その他のセンサ
データ解釈
認証・認可
ハードウェア関連
LED、ボタン等
AWS IoT Greengrass
- 41. コンポーネント開発の例
2023/01/26 © 2023 Greennote Inc. All rights reserved. 40
CO2センサ USBドングル 産業用Raspberry Pi
EnOcean
細切れのバイナリデータ 意味のあるパケット
データパケット
抽出
800ppm
パース
コンポーネント コンポーネント
ブローカー
- 42. メリット① 拡張性
2023/01/26 © 2023 Greennote Inc. All rights reserved. 41
細切れのバイナリデータ 意味のあるパケット
データパケット
抽出
CO2
パース
コンポーネント コンポーネント
ブローカー
熱中症
その他
パーサを用意するだけで対応センサが増やせる
- 43. メリット② テストが容易
2023/01/26 © 2023 Greennote Inc. All rights reserved. 42
ダミーパケット パース
多数のテストケースに対する単体テストが容易に実施/自動化できる
800ppm
テストデータ
800ppm
結果
自動テスト
- 44. まとめ
2023/01/26 © 2023 Greennote Inc. All rights reserved. 43
l UNIXという考え方は、
IoT開発においても大変重要になります。
l 開発途中のログ解析には、
UNIXライクなツールの使いこなしが効果大です。
l IoTは現実社会を写す鏡です。
同時多発的に様々なことが起こるだけでなく、
さまざまな予測不能なできごとが発生します。
l IoTの設計にUNIXという考え方を活かすことで、
非同期・疎結合 かつ 開発しやすい設計が
できるようになります。