SlideShare a Scribd company logo
1 of 20
アンナほえたワン
with Python
2019-10-30
西本 卓也(株式会社シュアルタ)
@nishimotz / @24motz
1
音センサー + IchigoSoda + sakura.io
2
アンナほえたワン(2019年6月)
3
システム構成(バージョン1)
4
IchigoSoda
音センサー
sakura.io
(DataStore API)
ifttt Slack
Python つかってません
5分間にほえた回数が
2回以上の場合に回数を通知
IchigoJam BASIC で実装
問題点
• ifttt で「ほえた回数」をペイロードから取り出していない
• イベントを記録していない
5
システム構成(バージョン2)
6
IchigoSoda
音センサー
sakura.io
(MQTT)
IoT Core
Slack
DynamoDB
Lambda
(Python)
Lambda
(node.js)
AWS
sakura.io から AWS IoT まで
• 公式チュートリアル
• https://sakura.io/docs/pages/guide/tutorial/service/aws.html
• エンドポイント URL や証明書は AWS IoT Core で作る
7
AWS IoT から DynamoDB まで
• 参考
• https://qiita.com/Ichiro_Tsuji/items/3815f2b683336e7088f4
• 流れ
• DynamoDB テーブルを作成
• Lambda を作成
• Lambda にルールを作成
• IoT のルールで起動
• DynamoDB に書き込む
• node.js のコードをコピペする
• まだ Python 使ってない
8
DynamoDB テーブル作成
• datetime をパーティションキーにする
• channel-0 に受信した値が入る
9
Lambda (1個目)のトリガー
• ルールクエリステートメント: SELECT * FROM 'sakuraio/#'
10
データが書き込まれる
11
DynamoDB ストリーム
• 項目が書き込まれたら別の Lambda をトリガーできる
• https://docs.aws.amazon.com/lambda/latest/dg/with-ddb.html
12
domovoi
13
使い方は chalice そっくり
$ domovoi new-project
New Domovoi project name: ichigosoda
New Domovoi project created in ichigosoda
$ cd ichigosoda
$ domovoi deploy
14
policy-dev.json に追加
{
"Action": [
"dynamodb:DescribeStream",
"dynamodb:GetRecords",
"dynamodb:GetShardIterator",
"dynamodb:ListStreams"
],
"Resource": [
"arn:aws:dynamodb:*:*:*"
],
"Effect": "Allow"
}
15
app.py
@app.dynamodb_stream_handler(table_name="IchigoSoda190925", batch_size=200
)
def handle_dynamodb_stream(event, context):
first_event = event["Records"][0]["dynamodb"]
new_image = first_event.get('NewImage')
if not new_image:
return
channel_0 = new_image.get('channel-0')
if not channel_0:
return
value = channel_0.get('N')
if value is None:
return
slack.notify(text=f'アンナ {value} 回ほえたワン')
16
Slack カスタムインテグレーション
• Incoming Webhook から WEBHOOK_URL を取得
17
Slack 投稿
import slackweb
slack = slackweb.Slack(url=WEBHOOK_URL)
18
Ver 1 と Ver 2
19
まとめ
• 回数がわかると状況がよくわかる
• 3回ほえたワン
• 93回ほえたワン
• 今後の方針
• Lambda は2個必要なのか
• 履歴の可視化
• モバイルネットワークやめて WiFi にする
• RasPi で Python か
• ESPxx で MicroPython か
• ほえるタイミングの予測
20

More Related Content

What's hot

電子工作のためのPython
電子工作のためのPython 電子工作のためのPython
電子工作のためのPython Takuya Nishimoto
 
スクレイピングとPython
スクレイピングとPythonスクレイピングとPython
スクレイピングとPythonHironori Sekine
 
次世代言語 Python による PyPy を使った次世代の処理系開発
次世代言語 Python による PyPy を使った次世代の処理系開発次世代言語 Python による PyPy を使った次世代の処理系開発
次世代言語 Python による PyPy を使った次世代の処理系開発shoma h
 
なぜ科学計算にはPythonか?
なぜ科学計算にはPythonか?なぜ科学計算にはPythonか?
なぜ科学計算にはPythonか?Aki Ariga
 
PythonとRによるデータ分析環境の構築と機械学習によるデータ認識 第3版
PythonとRによるデータ分析環境の構築と機械学習によるデータ認識 第3版PythonとRによるデータ分析環境の構築と機械学習によるデータ認識 第3版
PythonとRによるデータ分析環境の構築と機械学習によるデータ認識 第3版Katsuhiro Morishita
 
Pythonスタートアップ勉強会201109 python入門
Pythonスタートアップ勉強会201109 python入門Pythonスタートアップ勉強会201109 python入門
Pythonスタートアップ勉強会201109 python入門Takayuki Shimizukawa
 
Python3 プログラミング勉強会
Python3 プログラミング勉強会Python3 プログラミング勉強会
Python3 プログラミング勉強会Tetsuya Morimoto
 
210526 Power Automate Desktop Python
210526 Power Automate Desktop Python210526 Power Automate Desktop Python
210526 Power Automate Desktop PythonTakuya Nishimoto
 
10分でわかるPythonの開発環境
10分でわかるPythonの開発環境10分でわかるPythonの開発環境
10分でわかるPythonの開発環境Hisao Soyama
 
「Python言語」はじめの一歩 / First step of Python
「Python言語」はじめの一歩 / First step of Python「Python言語」はじめの一歩 / First step of Python
「Python言語」はじめの一歩 / First step of PythonTakanori Suzuki
 
GBDC 勉強会 #1 Python を用いたツール作成工数の最小化
GBDC 勉強会 #1 Python を用いたツール作成工数の最小化GBDC 勉強会 #1 Python を用いたツール作成工数の最小化
GBDC 勉強会 #1 Python を用いたツール作成工数の最小化Yutaka Kato
 
CPythonを読もう
CPythonを読もうCPythonを読もう
CPythonを読もうAkira Nonaka
 
Pynyumon03 LT
Pynyumon03 LTPynyumon03 LT
Pynyumon03 LTdrillan
 
Py datameetup1
Py datameetup1Py datameetup1
Py datameetup1shiroyagi
 
第3回メドレー読書会後半
第3回メドレー読書会後半第3回メドレー読書会後半
第3回メドレー読書会後半Kazuhiro Himoto
 
scikit-learnを用いた機械学習チュートリアル
scikit-learnを用いた機械学習チュートリアルscikit-learnを用いた機械学習チュートリアル
scikit-learnを用いた機械学習チュートリアル敦志 金谷
 

What's hot (20)

電子工作のためのPython
電子工作のためのPython 電子工作のためのPython
電子工作のためのPython
 
スクレイピングとPython
スクレイピングとPythonスクレイピングとPython
スクレイピングとPython
 
次世代言語 Python による PyPy を使った次世代の処理系開発
次世代言語 Python による PyPy を使った次世代の処理系開発次世代言語 Python による PyPy を使った次世代の処理系開発
次世代言語 Python による PyPy を使った次世代の処理系開発
 
なぜ科学計算にはPythonか?
なぜ科学計算にはPythonか?なぜ科学計算にはPythonか?
なぜ科学計算にはPythonか?
 
Jupyter notebook
Jupyter notebookJupyter notebook
Jupyter notebook
 
PythonとRによるデータ分析環境の構築と機械学習によるデータ認識 第3版
PythonとRによるデータ分析環境の構築と機械学習によるデータ認識 第3版PythonとRによるデータ分析環境の構築と機械学習によるデータ認識 第3版
PythonとRによるデータ分析環境の構築と機械学習によるデータ認識 第3版
 
Pythonスタートアップ勉強会201109 python入門
Pythonスタートアップ勉強会201109 python入門Pythonスタートアップ勉強会201109 python入門
Pythonスタートアップ勉強会201109 python入門
 
Python3 プログラミング勉強会
Python3 プログラミング勉強会Python3 プログラミング勉強会
Python3 プログラミング勉強会
 
210526 Power Automate Desktop Python
210526 Power Automate Desktop Python210526 Power Automate Desktop Python
210526 Power Automate Desktop Python
 
Pythonのすすめ
PythonのすすめPythonのすすめ
Pythonのすすめ
 
10分でわかるPythonの開発環境
10分でわかるPythonの開発環境10分でわかるPythonの開発環境
10分でわかるPythonの開発環境
 
Pythonでpdfをいじってみる
PythonでpdfをいじってみるPythonでpdfをいじってみる
Pythonでpdfをいじってみる
 
「Python言語」はじめの一歩 / First step of Python
「Python言語」はじめの一歩 / First step of Python「Python言語」はじめの一歩 / First step of Python
「Python言語」はじめの一歩 / First step of Python
 
MicroPython + ESP32
MicroPython + ESP32MicroPython + ESP32
MicroPython + ESP32
 
GBDC 勉強会 #1 Python を用いたツール作成工数の最小化
GBDC 勉強会 #1 Python を用いたツール作成工数の最小化GBDC 勉強会 #1 Python を用いたツール作成工数の最小化
GBDC 勉強会 #1 Python を用いたツール作成工数の最小化
 
CPythonを読もう
CPythonを読もうCPythonを読もう
CPythonを読もう
 
Pynyumon03 LT
Pynyumon03 LTPynyumon03 LT
Pynyumon03 LT
 
Py datameetup1
Py datameetup1Py datameetup1
Py datameetup1
 
第3回メドレー読書会後半
第3回メドレー読書会後半第3回メドレー読書会後半
第3回メドレー読書会後半
 
scikit-learnを用いた機械学習チュートリアル
scikit-learnを用いた機械学習チュートリアルscikit-learnを用いた機械学習チュートリアル
scikit-learnを用いた機械学習チュートリアル
 

Similar to 191030 anna-with-python

Getting Started with Graph Database with Python
Getting Started with Graph Database with PythonGetting Started with Graph Database with Python
Getting Started with Graph Database with Pythonロフト くん
 
Visual Studio App Centerで始めるCI/CD(iOS)
Visual Studio App Centerで始めるCI/CD(iOS)Visual Studio App Centerで始めるCI/CD(iOS)
Visual Studio App Centerで始めるCI/CD(iOS)Shinya Nakajima
 
ノンコーディングで LINE Bot 開発! Azure Logic Apps × Azure Cognitive Services ×LINE メッセー...
ノンコーディングで LINE Bot 開発! Azure Logic Apps × Azure Cognitive Services ×LINE メッセー...ノンコーディングで LINE Bot 開発! Azure Logic Apps × Azure Cognitive Services ×LINE メッセー...
ノンコーディングで LINE Bot 開発! Azure Logic Apps × Azure Cognitive Services ×LINE メッセー...典子 松本
 
Microsoft Intelligent Edge Technologies
Microsoft Intelligent Edge TechnologiesMicrosoft Intelligent Edge Technologies
Microsoft Intelligent Edge TechnologiesTakeshi Fukuhara
 
Pythonでパケット解析
Pythonでパケット解析Pythonでパケット解析
Pythonでパケット解析euphoricwavism
 
さくらのIoT Platformを使ってみよう ~Developers in KOBE編~
さくらのIoT Platformを使ってみよう ~Developers in KOBE編~さくらのIoT Platformを使ってみよう ~Developers in KOBE編~
さくらのIoT Platformを使ってみよう ~Developers in KOBE編~法林浩之
 
Azure Serverless or Power Platform 〜 あなたならどっち?! - Azure Serverless 編
Azure Serverless or Power Platform 〜 あなたならどっち?! - Azure Serverless 編Azure Serverless or Power Platform 〜 あなたならどっち?! - Azure Serverless 編
Azure Serverless or Power Platform 〜 あなたならどっち?! - Azure Serverless 編Kazumi IWANAGA
 
さくらのIoT Platformを使ってみよう ~OSC大阪編~
さくらのIoT Platformを使ってみよう ~OSC大阪編~さくらのIoT Platformを使ってみよう ~OSC大阪編~
さくらのIoT Platformを使ってみよう ~OSC大阪編~法林浩之
 
Tokyo Jazug Night 2020-01 Azure Monitor を使った運用監視コトハジメ
Tokyo Jazug Night 2020-01 Azure Monitor を使った運用監視コトハジメTokyo Jazug Night 2020-01 Azure Monitor を使った運用監視コトハジメ
Tokyo Jazug Night 2020-01 Azure Monitor を使った運用監視コトハジメTsubasa Yoshino
 
itnerface 2018年9月号オフ会発表資料
itnerface 2018年9月号オフ会発表資料itnerface 2018年9月号オフ会発表資料
itnerface 2018年9月号オフ会発表資料Kenichi Miyata
 
ExcelとPythonによる社会インフラシステムの設定ファイルの自動生成
ExcelとPythonによる社会インフラシステムの設定ファイルの自動生成ExcelとPythonによる社会インフラシステムの設定ファイルの自動生成
ExcelとPythonによる社会インフラシステムの設定ファイルの自動生成Fuminobu TAKEYAMA
 
2014 0228 OSC-Spring Tokyo NETMF
2014 0228 OSC-Spring Tokyo NETMF2014 0228 OSC-Spring Tokyo NETMF
2014 0228 OSC-Spring Tokyo NETMFAtomu Hidaka
 
【ログ分析勉強会】セッションアクティビティログは使えるのか
【ログ分析勉強会】セッションアクティビティログは使えるのか【ログ分析勉強会】セッションアクティビティログは使えるのか
【ログ分析勉強会】セッションアクティビティログは使えるのかHibino Hisashi
 
Python languageupdate (2004)
Python languageupdate (2004)Python languageupdate (2004)
Python languageupdate (2004)泰 増田
 
ネットワークOS野郎 ~ インフラ野郎Night 20160414
ネットワークOS野郎 ~ インフラ野郎Night 20160414ネットワークOS野郎 ~ インフラ野郎Night 20160414
ネットワークOS野郎 ~ インフラ野郎Night 20160414Kentaro Ebisawa
 
OSSはどこまで産業用機器に使えるか_20230520.pdf
OSSはどこまで産業用機器に使えるか_20230520.pdfOSSはどこまで産業用機器に使えるか_20230520.pdf
OSSはどこまで産業用機器に使えるか_20230520.pdfKioto Hirahara
 
2020 年も最高のゲームをつくろう! Game Stack でゲーム開発をしよう! ~ LiveOps とデータ分析編 ~
2020 年も最高のゲームをつくろう! Game Stack でゲーム開発をしよう! ~ LiveOps とデータ分析編 ~2020 年も最高のゲームをつくろう! Game Stack でゲーム開発をしよう! ~ LiveOps とデータ分析編 ~
2020 年も最高のゲームをつくろう! Game Stack でゲーム開発をしよう! ~ LiveOps とデータ分析編 ~Daisuke Masubuchi
 
【de:code 2020】 2020 年も最高のゲームをつくろう! Game Stack でゲーム開発をしよう! ~ LiveOps とデータ分析編 ~
【de:code 2020】 2020 年も最高のゲームをつくろう! Game Stack でゲーム開発をしよう! ~ LiveOps とデータ分析編 ~【de:code 2020】 2020 年も最高のゲームをつくろう! Game Stack でゲーム開発をしよう! ~ LiveOps とデータ分析編 ~
【de:code 2020】 2020 年も最高のゲームをつくろう! Game Stack でゲーム開発をしよう! ~ LiveOps とデータ分析編 ~日本マイクロソフト株式会社
 

Similar to 191030 anna-with-python (20)

Getting Started with Graph Database with Python
Getting Started with Graph Database with PythonGetting Started with Graph Database with Python
Getting Started with Graph Database with Python
 
Visual Studio App Centerで始めるCI/CD(iOS)
Visual Studio App Centerで始めるCI/CD(iOS)Visual Studio App Centerで始めるCI/CD(iOS)
Visual Studio App Centerで始めるCI/CD(iOS)
 
ノンコーディングで LINE Bot 開発! Azure Logic Apps × Azure Cognitive Services ×LINE メッセー...
ノンコーディングで LINE Bot 開発! Azure Logic Apps × Azure Cognitive Services ×LINE メッセー...ノンコーディングで LINE Bot 開発! Azure Logic Apps × Azure Cognitive Services ×LINE メッセー...
ノンコーディングで LINE Bot 開発! Azure Logic Apps × Azure Cognitive Services ×LINE メッセー...
 
Microsoft Intelligent Edge Technologies
Microsoft Intelligent Edge TechnologiesMicrosoft Intelligent Edge Technologies
Microsoft Intelligent Edge Technologies
 
Inside MF
Inside MFInside MF
Inside MF
 
なぜ今OSGiか
なぜ今OSGiかなぜ今OSGiか
なぜ今OSGiか
 
Pythonでパケット解析
Pythonでパケット解析Pythonでパケット解析
Pythonでパケット解析
 
さくらのIoT Platformを使ってみよう ~Developers in KOBE編~
さくらのIoT Platformを使ってみよう ~Developers in KOBE編~さくらのIoT Platformを使ってみよう ~Developers in KOBE編~
さくらのIoT Platformを使ってみよう ~Developers in KOBE編~
 
Azure Serverless or Power Platform 〜 あなたならどっち?! - Azure Serverless 編
Azure Serverless or Power Platform 〜 あなたならどっち?! - Azure Serverless 編Azure Serverless or Power Platform 〜 あなたならどっち?! - Azure Serverless 編
Azure Serverless or Power Platform 〜 あなたならどっち?! - Azure Serverless 編
 
さくらのIoT Platformを使ってみよう ~OSC大阪編~
さくらのIoT Platformを使ってみよう ~OSC大阪編~さくらのIoT Platformを使ってみよう ~OSC大阪編~
さくらのIoT Platformを使ってみよう ~OSC大阪編~
 
Tokyo Jazug Night 2020-01 Azure Monitor を使った運用監視コトハジメ
Tokyo Jazug Night 2020-01 Azure Monitor を使った運用監視コトハジメTokyo Jazug Night 2020-01 Azure Monitor を使った運用監視コトハジメ
Tokyo Jazug Night 2020-01 Azure Monitor を使った運用監視コトハジメ
 
itnerface 2018年9月号オフ会発表資料
itnerface 2018年9月号オフ会発表資料itnerface 2018年9月号オフ会発表資料
itnerface 2018年9月号オフ会発表資料
 
ExcelとPythonによる社会インフラシステムの設定ファイルの自動生成
ExcelとPythonによる社会インフラシステムの設定ファイルの自動生成ExcelとPythonによる社会インフラシステムの設定ファイルの自動生成
ExcelとPythonによる社会インフラシステムの設定ファイルの自動生成
 
2014 0228 OSC-Spring Tokyo NETMF
2014 0228 OSC-Spring Tokyo NETMF2014 0228 OSC-Spring Tokyo NETMF
2014 0228 OSC-Spring Tokyo NETMF
 
【ログ分析勉強会】セッションアクティビティログは使えるのか
【ログ分析勉強会】セッションアクティビティログは使えるのか【ログ分析勉強会】セッションアクティビティログは使えるのか
【ログ分析勉強会】セッションアクティビティログは使えるのか
 
Python languageupdate (2004)
Python languageupdate (2004)Python languageupdate (2004)
Python languageupdate (2004)
 
ネットワークOS野郎 ~ インフラ野郎Night 20160414
ネットワークOS野郎 ~ インフラ野郎Night 20160414ネットワークOS野郎 ~ インフラ野郎Night 20160414
ネットワークOS野郎 ~ インフラ野郎Night 20160414
 
OSSはどこまで産業用機器に使えるか_20230520.pdf
OSSはどこまで産業用機器に使えるか_20230520.pdfOSSはどこまで産業用機器に使えるか_20230520.pdf
OSSはどこまで産業用機器に使えるか_20230520.pdf
 
2020 年も最高のゲームをつくろう! Game Stack でゲーム開発をしよう! ~ LiveOps とデータ分析編 ~
2020 年も最高のゲームをつくろう! Game Stack でゲーム開発をしよう! ~ LiveOps とデータ分析編 ~2020 年も最高のゲームをつくろう! Game Stack でゲーム開発をしよう! ~ LiveOps とデータ分析編 ~
2020 年も最高のゲームをつくろう! Game Stack でゲーム開発をしよう! ~ LiveOps とデータ分析編 ~
 
【de:code 2020】 2020 年も最高のゲームをつくろう! Game Stack でゲーム開発をしよう! ~ LiveOps とデータ分析編 ~
【de:code 2020】 2020 年も最高のゲームをつくろう! Game Stack でゲーム開発をしよう! ~ LiveOps とデータ分析編 ~【de:code 2020】 2020 年も最高のゲームをつくろう! Game Stack でゲーム開発をしよう! ~ LiveOps とデータ分析編 ~
【de:code 2020】 2020 年も最高のゲームをつくろう! Game Stack でゲーム開発をしよう! ~ LiveOps とデータ分析編 ~
 

More from Takuya Nishimoto

More from Takuya Nishimoto (20)

221217 SwiftはPythonに似ている
221217 SwiftはPythonに似ている221217 SwiftはPythonに似ている
221217 SwiftはPythonに似ている
 
220427-pydata 統計・データ分析 特集
220427-pydata 統計・データ分析 特集220427-pydata 統計・データ分析 特集
220427-pydata 統計・データ分析 特集
 
220126 python-datalake-spark
220126 python-datalake-spark220126 python-datalake-spark
220126 python-datalake-spark
 
211020 すごい広島 with OSH 2021.10
211020 すごい広島 with OSH 2021.10211020 すごい広島 with OSH 2021.10
211020 すごい広島 with OSH 2021.10
 
210917 オープンセミナー@広島のこれまでとこれから
210917 オープンセミナー@広島のこれまでとこれから210917 オープンセミナー@広島のこれまでとこれから
210917 オープンセミナー@広島のこれまでとこれから
 
210630 python
210630 python210630 python
210630 python
 
210428 python
210428 python210428 python
210428 python
 
200918 hannari-python
200918 hannari-python200918 hannari-python
200918 hannari-python
 
200429 python
200429 python200429 python
200429 python
 
200325 flask
200325 flask200325 flask
200325 flask
 
200208 osh-nishimoto-v2
200208 osh-nishimoto-v2200208 osh-nishimoto-v2
200208 osh-nishimoto-v2
 
191208 python-kansai-nishimoto
191208 python-kansai-nishimoto191208 python-kansai-nishimoto
191208 python-kansai-nishimoto
 
191101 nvda-sightworld-nishimoto
191101 nvda-sightworld-nishimoto191101 nvda-sightworld-nishimoto
191101 nvda-sightworld-nishimoto
 
191114 iotlt-nishimoto
191114 iotlt-nishimoto191114 iotlt-nishimoto
191114 iotlt-nishimoto
 
190916 nishimoto-nvda-pyconjp
190916 nishimoto-nvda-pyconjp190916 nishimoto-nvda-pyconjp
190916 nishimoto-nvda-pyconjp
 
190925 python-windows
190925 python-windows190925 python-windows
190925 python-windows
 
190731 chalice
190731 chalice190731 chalice
190731 chalice
 
190719 nishimoto nvda talk
190719 nishimoto nvda talk190719 nishimoto nvda talk
190719 nishimoto nvda talk
 
PCN 190630 v2
PCN 190630 v2PCN 190630 v2
PCN 190630 v2
 
190516 nishimoto
190516 nishimoto190516 nishimoto
190516 nishimoto
 

191030 anna-with-python