ããã«ã¡ã¯ãæè¡ï¼èª²ã®å¤ç°ã§ãã
å
æ¥JAWS FESTA æ±æµ·é2016ã«ã¦LTã§IoTã®çºè¡¨ããã¾ããï¼
çºè¡¨è³æã¨ãã¯ããã¡ãã®ã¬ãã¼ãã«ã¾ã¨ãã¦ããã¾ãã®ã§ãåããã¦ã覧ãã ããã
ä»åãIoTã®äºå§ãã¨ãã¦ãRaspberry Piã¨AWS IoTãçµã¿åããã¦ãèªä½åä»ã·ã¹ãã ãä½ã£ã¦ã¿ããã¨æãã
Raspberry Piã¨ãã®äººæã»ã³ãµã¼ãè²·ã£ã¦ã¿ã¾ããã
çºè¡¨ããæã«ããã¤ã¹ã¨AWSã¸ã®é£æºé¨åã«ã¤ãã¦è§£èª¬ãã§ãã¦ããªãã£ãã®ã§ã
æ¹ãã¦æè¡ããã°ã§ãLTã§çºè¡¨ããå
容ãã©ãå®ç¾ããããã¾ã¨ãã¦ããã¾ãã
ä»åã®æ§æ
ä»åã®æ§æã¨ãã¦ã¯ã以ä¸ã®éãã§ãã
å¦çã¯ãRasberry Piã«åãä»ãã人æã»ã³ãµã¼ããAWS IoTã«ãã¼ã¿ãéã£ã¦ãAWS IoTããã®ãã¼ã¿ãSNSã¸éãã
LambdaããSlackã¸ã¡ãã»ã¼ã¸ãéã£ã¦ãã¾ãã
å®ç¾æ¹æ³
ããã§ã¯ãã®æ§æãã©ã®ããã«å®ç¾ãããã«ã¤ãã¦ã§ããã以ä¸ã®3ã¹ãããã§æ¸ãã¦ããã¾ãã
- AWS IoTå´ã®ã»ããã¢ãã
- Raspberry Piå´ã®è¨å®
- Lambdaã®è¨å®
1. AWS IoTå´ã®ã»ããã¢ãã
AWSããã¸ã¡ã³ãã³ã³ã½ã¼ã«ããAWS IoTãé¸æããã¾ãã¯ãããã¤ã¹ã¨AWSãç¹ãã²ã¼ãã¦ã§ã¤ãä½ãã¾ãã
ãããããThingãã¨å¼ã°ããAWS IoTã«ãããä»®æ³ããã¤ã¹ã§ãAWS IoTã¢ã«ã¦ã³ãã«æ¥ç¶ãããããã¤ã¹ã«ã¤ãã¦ãã¼ã¿ãä¿æã§ãã¾ãã
ããã§ã¯ãThingåãã¤ãã¦ã[Create]ãæ¼ãã¾ãã
次ã«ãAWS IoTã«éããããã¼ã¿ã«å¯¾ãã¦ã©ãã¢ã¯ã·ã§ã³ãã¤ããããå®ç¾©ãã¾ãã
ãããããã«ã¼ã«ã¨ã³ã¸ã³ãã§ãã
ä»åã¯ãAWS IoTã¨SNSãé£æºããã®ã§ããã®è¨å®ãè¡ãã¾ãã
å°ãSNSã®ãããã¯ä½æã¯å®äºãã¦ããã¨ããåæã§è¨å®å
容ã¯å²æãã¾ãã
ã¾ããã«ã¼ã«ã¨ã³ã¸ã³ã«ä»»æã®ååãã¤ãã¾ãã
次ã«ã[Atturibute]ã«ã*ããè¨å®ãã¾ãããããã§å
¨ã¦ã®MQTTã¡ãã»ã¼ã¸å
¨ä½ãéä¿¡ã§ãã¾ãã
ã¾ãã[Topic filter]ã«ãraspi/snsããè¨å®ãã¾ãããã«ã¼ã«ã¨ã³ã¸ã³ã¯[Topic filter]ã使ã£ã¦MQTTã¡ãã»ã¼ã¸ãåä¿¡ããæã®ããªã¬ã¼ããã«ã¼ã«ã決å®ãã¾ãã
ããã¦ãã«ã¼ã«ã¨ã³ã¸ã³ã®ã¢ã¯ã·ã§ã³ãå®ç¾©ãã¾ãããããã§ã¯ããSNSããé¸æãã¾ãã
ã¾ããäºãä½æããSNSãããã¯ã¨é©å®IAMãã¼ã«ã®ä½æãè¡ãã[Add action]ãæ¼ãã¾ãã
ããã¨ã以ä¸ã®ãããªç¶æ ã«ãªãã®ã§ããã®ã¾ã¾[Create]ãæ¼ãã¾ãã
次ã«ãAWS IoTããªã·ã¼ãä½ãã¾ãã
ããã¯ãMQTTãããã¯ã®ãµãã¹ã¯ã©ã¤ããçºè¡çã®AWS IoTæä½ã®å®è¡ãããã¤ã¹å´ã«è¨±å¯ããããã«å¿
è¦ã§ãã
[Create a policy]ãé¸æãã¾ãã
ããªã·ã¼åã¨ãAWS IoTã®ã¢ã¯ã·ã§ã³ã¨ãªã½ã¼ã¹ãå®ç¾©ãã¾ãã
ä»åã¯ã[Action]ã«ãiot:ããã[Resource]ã«ãããå
¥åããAllowãæå¹åãã¾ããã
ããã§ãAWS IoTã®ãã¹ã¦ã®æä½ã«å¯¾ãã¦è¨±å¯ãè¡ããã¨ã«ãªãã¾ããã
åé¡ãªããã°ã[Add statement]ã¨[Create]ãæ¼ãã¾ãã
次ã«ãããã¤ã¹ã¨AWS IoTéã®éä¿¡ãã»ãã¥ã¢ã«è¡ãããã®è¨¼ææ¸ãä½æãã¾ãã
å°ãAWS IoTã§ã¯ãX.509証ææ¸ã使ç¨ãã¦éä¿¡ãè¡ãã¾ãã
証ææ¸ã®ä½æã¯ç°¡åã§ãã
[Create a certificate]ãé¸æå¾ã[1-Click certificate create]ãæ¼ãã¾ãã
ããã¨ã以ä¸ã®ãããªè¨¼ææ¸ãã¦ã³ãã¼ãç»é¢ã¸é·ç§»ãã¾ãã
ç§å¯éµã¨è¨¼ææ¸ããã¦ã³ãã¼ããããã¡ãããRoot証ææ¸ããã¦ã³ãã¼ããã¾ãã
ãã®å¾ã証ææ¸ã®ã¢ã¯ãã£ãã¼ããè¡ãã¾ãã
以ä¸ã®ããã«ã¢ã¯ãã£ãã¼ããããã証ææ¸ãé¸æãã[Actions]ãã[Activate]ãé¸æãã¾ãã
æå¾ã«ãããªã·ã¼ã¨è¨¼ææ¸ãé¢é£ä»ãã¾ãã
ä½æãã証ææ¸ããã§ãã¯ãã¦ã[Actions]ãã[Attach a policy]ãé¸æãã¾ãã
é¢é£ã¥ããããªã·ã¼ãå ¥åããããæ±ããããã®ã§ãå ¥åå¾ã[Attach]ãã¾ãã
以ä¸ã§AWS IoTå´ã®è¨å®ãå®äºã§ãã
2. Raspberry Piå´ã®è¨å®
AWS IoTã§ä½ã£ã証ææ¸ã¨Root証ææ¸ãRaspberry Piã«é
ç½®ãã¾ãã
ä»åã¯ã/homeé
ä¸ã«certificateãã£ã¬ã¯ããªãä½ããRoot証ææ¸ãç§å¯éµã証ææ¸ãé
ç½®ãã¾ããã
ã¾ããMQTTã§AWSã¨éä¿¡ããã®ã§ãMosquittoã¯ã©ã¤ã¢ã³ããå°å ¥ãã¾ããã
$ sudo apt-get install -y mosquitto-clients
ã¤ã³ã¹ãã¼ã«å®äºå¾ã試ãã«AWS IoTã«éä¿¡ãã¦ã¿ã¾ãã
å°ããã®æç¹ã§ã¯SNSãããã¯ã¯ãç§ã®ã¡ã¼ã«ã¢ãã¬ã¹ãéç¥å
ã«æå®ãã¦ãã¾ãã
$ mosquitto_pub --cafile certificate/Root証ææ¸ \ --cert certificate/AWS IoTã§çæãã証ææ¸ \ --key certificate/AWS IoTã§çæããç§å¯éµ \ -h xxxxxx.iot.ap-northeast-1.amazonaws.com(Thingã®ã¨ã³ããã¤ã³ã) \ -p 8883 -q 1 -d \ -t raspi/sns \ -m '{"message":"å¨ãã«äººãæç¥ãããï¼"}'
ããéç¥ãæ¥ã¾ãããã
ãã¨ã¯ã人æã»ã³ãµã¼ãåå¿ããæã«ãMosquittoã¯ã©ã¤ã¢ã³ãã®ã³ãã³ããå®è¡ããã³ã¼ãã£ã³ã°ãè¡ãã
Raspberry Piå´ã®è¨å®ãå®äºã§ãã
3.Lambdaã®è¨å®
LambdaããSlackã¸ã®æ稿ã®è¨å®ã¯ãCS課åæ¬ã®ããã°ã§ç´¹ä»ããè¨å®ã¨åæ§ã®ä½æ¥ãè¡ã£ã¦ããããã
å²æãã¾ãã
ä½µãã¦ä¸è¨ã®ããã°ã«ã¦ç¢ºèªããã ãã¾ãã¨å¹¸ãã§ãã
Lambdaã¨Slacké£æºè¨å®ã¨SNSããã®éç¥ãLambdaã§å¦çããã³ã¼ããå®äºãã
人æã»ã³ãµã¼ã«è¿ã¥ããããé¢ããããã¦ããã¨ããã
Slackã«Rasberry Piããã®ã¡ãã»ã¼ã¸ãæ稿ããã¾ããï¼
ã¾ã¨ã
ããã¤ã¹ã¨AWSé£æºã«ã¤ãã¦ç°¡åãªç´¹ä»ã¨ãªãã¾ãããããããã§ããã§ããããï¼
èªåèªèº«ãã£ã¦ã¿ãã¾ã§ããããé£ããã¨æã£ã¦ããã¨ãããããã¾ãããããã£ã¦ã¿ããæå¤ã¨ç°¡åã§ããï¼
ä»åº¦ã¯ãSORACOMããã®æ©è½ã¨ãé£æºãã¦ã¿ãããä»ã®ã»ã³ãµã¼ãçµã¿åããã¦ã¿ãçµæãã¬ãã¼ããããã¨æã£ã¦ãã¾ãã
ããã§ã¯ï¼