æ¬è¨äºã¯
myThings Advent Calendar 2015
ã¨
Milkcocoa Advent Calendar 2015
ã®10æ¥ç®ã®è¨äºã§ãã
ä»åã¯ä¸äººæ®ããã®ç¥æ¯ã®å®å¦ãããã確èªã§ããããã¤ã¹ãä½ã£ããã¨ã®è¨é²ãæ¸ãã¾ãã
åã®Advent Calendarã§ãã®ã§ãä¸è¶³ãããã¾ãããæ¯éã³ã¡ã³ãã§ãç¥ããããã ããã°ã¨åãã¾ãã
ç®æ¬¡
- ç®æ¬¡
- èæ¯ã»æ±ãã¦ããåé¡
- æè¡ç課é¡
- æ¹ãã¦ä½ããã®ã®èª¬æ
- å®éã®è£½ä½ã®æµã
- 使ã£ã¦ã¿ãã»ææ³
- ä»å¾
èæ¯ã»æ±ãã¦ããåé¡
åã®ç¥æ¯ã¯é ãã§ä¸äººæ®ããããã¦ãã¾ãã
é«é½¢ã®ä¸äººæ®ãããªã®ã§ä¸¡è¦ªã¯å¿é
ãã¦ãããç¥æ¯ã«è¿ãã«å¼ã£è¶ãã¦ããããã«ã»ãããã¯åå±
ããããã«ææ¡ãããã®ã®ãå¼ã£è¶ããã¨ã¯å«ã ã¨ãããã¨ã§ãä½ãåºæ¥ããã¨ã¯ãªããã¨æ©ãã§ãã¾ããã
解決æ¡
ããã§ããããã§ãè¯ãã®ã§å®å¦ç¢ºèªãã§ããã両親ãå°ãã¯å®å¿ããããã¨èããä½ãããã®åããæ¤ç¥ãã¦ãæ¯æ¥æ±ºã¾ã£ãæéã«éç¥ããããã®ãä½ããã¨ã«ãã¾ããã
ä½ãä½ãã
åãã®æ¤ç¥ã¨ããæå³ã§ã¯ãããã®ä½¿ç¨ç¶æ³ããå®å¦ã確èªã§ããã¨ããååãããã¾ãããåã®ç¥æ¯ãæ¯æ¥ãããã使ã£ã¦ããããããããªãã
ããã§ãã¾ãã¯ã誰ã§ãã»æ¯æ¥ä½¿ã£ã¦ããããã¤ã¬ã®æã®ééã®ãã°ãåãã¾ãã
ããã¦ãæ¯æ¥æ8æã»å¤8æã®æç¹ã§å®å¦ï¼åãããã£ããã©ããï¼ã®éç¥ããã¦ãããããã«ãã¾ãã
æè¡ç課é¡
ãã¦ãä½ããã®ã¯æ±ºã¾ãã¾ãããæè¡çãªèª²é¡ãè²ã ã¨ããã¾ãã
課é¡ãã®1 : éä¿¡ç°å¢ãã©ãããã
課é¡ãã®2 : ãµã¼ãã¼ãã©ãããã
課é¡ãã®3 : éç¥ãã©ãããã
課é¡ãã®1.éä¿¡ç°å¢ãã©ãããã
ç¥æ¯ã®å®¶ã«ã¯é»æ°ã¯ããããã¦éã£ã¦ãããã®ã®ãã¤ã³ã¿ã¼ããããªãã¦ããç¾ä»£çãªãã®ã¯å½ç¶ããã¾ããã
ããããæ°ããã¤ã³ã¿ã¼ãããã®å¥ç´ãããã¨ããã®ã¯ä»åã®å©ç¨ç®çãèããã¨ã³ã¹ããæªãã
ããã§ãsimããªã¼ã®ãã±ããWiFiãè³¼å
¥ããã¨ããã·ã§å¥ç´ããæé¡500åã»ä½éã»ç¡å¶éã®simãå
¥ãã¦ä½¿ããã¨ã«ãã¾ãããï¼ãªãã¨ãéä¿¡ã§ãã¾ãããï¼
課é¡ãã®2.ãµã¼ãã¼ãã©ãããã
ãã¼ã¿ãåãå ¥ãããåãåºãããã¨ãããµã¼ãã¼å´ã®ããã°ã©ã ãæ¸ãã®ã¯æå¤ã¨é¢åã§ãã
ããã§ãä»åã¯
èªåã§ãµã¼ããæºåããã«ãã¯ã©ã¤ã¢ã³ãSDKãä»ãã¦ãã¼ã¿ã®ä¿åãæ´æ°ãåå¾ã¾ãPub/Subéä¿¡ãè¡ããã¨ãåºæ¥ã
ã¨ããmilkcocoaã使ãããã¨æãã¾ãã
課é¡ãã®ï¼.ã¹ããã¸ã®éç¥ãã©ãããã
ã¢ããªã®ç¥èã¯0ãªã®ã§ãã¹ããã¸ã®ããã·ã¥éç¥ã®ããæ¹ããããã¾ãããã¨ãããã¨ã§ãmyThingsã使ãã¾ãã
æ¹ãã¦ä½ããã®ã®èª¬æ
ã ããããããªæµãã§ãã
å®éã®è£½ä½ã®æµã
ãã¦ãåç½®ããé·ããªãã¾ãããã製ä½ã®æµãã®èª¬æã«å ¥ãã¾ãã ãã£ããã¨ããæµãã¯ãããªæãã§ãã
- raspberry_piã®ã»ããã¢ããã¨milkcocoaã«ç»é²
- IDCFã¯ã©ã¦ãã«å¥ç´ã¨myThingsã»ããã¢ãã
- æã®ééãã¼ã¿ãmilkcocoaã«éä¿¡
- ééãã¼ã¿ã®æç¡ã確èªãã¦ãmythingsã«éç¥ãããããã¼ã¿ãã»ãã
- myThingsã§ããã·ã¥éç¥ãåãã
ã§ã¯ãä¸ã¤ãã¤è¦ã¦ããã¾ã
1.raspberry_piã®ã»ããã¢ããã¨milkcocoaã®ç»é²
ãã®è¾ºãã¯ãã¡ãã®è¨äºãåèã«ãã¾ããã http://blog.mlkcca.com/iot/realtime-data-visualization-with-raspberry-pi-1/
2.IDCFã¯ã©ã¦ãã«å¥ç´ã¨myThingsã»ããã¢ãã
IDCFã¯ã©ã¦ãå¥ç´ã»myThingsã®ã»ããã¢ããã¯ãã¡ãã®è¨äºãåèã«ãã¾ããã myThingsãå§ããã
3.æã®ééãmilkcocoaã«éä¿¡
ãã¦ãããã¾ã§ã®ã¹ãããã§ç°å¢ãã§ããã®ã§ãããã°ã©ã ãæ¸ãã¦ããã¾ãã
ä»åã¯æã®ééãç£è¦ããã®ã§ããªã¼ãã¹ã¤ããï¼ç£ç³ã®æ¥è¿ã§on/offãåãæ¿ããã¹ã¤ããï¼ã使ãã¾ãã
ãã¡ãã®è¨äºã®ã¹ã¤ããå ¥åãåãä»ããã¨ããç®æã®ãµã³ãã«ãæ¸ãæãã¦ãmilkcocoaã«ãã¼ã¿ãéä¿¡ããä»çµã¿ã追å ãã¾ããã
ãã®ããã°ã©ã ã¯ããã¯ã°ã©ã¦ã³ãã§å®è¡ãç¶ãã¾ãã
$ sudo node door_check.js &
var fs = require('fs'); var MilkCocoa = require('milkcocoa'); var milkcocoa = new MilkCocoa('*******.mlkcca.com'); var ds = milkcocoa.dataStore('door'); fs.writeFileSync('/sys/class/gpio/export', 21); fs.writeFileSync('/sys/class/gpio/gpio21/direction', 'in'); var pre_value = 1; loop(); function loop() { var value = parseInt(fs.readFileSync('/sys/class/gpio/gpio21/value', 'ascii')); if ( value != pre_value ) { console.log(value); ds.push({DoorOpenFlag:value}); pre_value = value; } setTimeout(loop, 1000/10); }
åä½ä¸ã®åç»
以åpythonã§æ¸ãããã¼ã¸ã§ã³ãªã®ã§ãå¾®å¦ã«æåãéãã¾ãã大ä½ãããªæãã§ãã
4. ééãã¼ã¿ã®æç¡ã確èªãã¦ãmythingsã«éç¥ãããããã¼ã¿ãã»ãã
ä¸è¨ã®ããã°ã©ã ãæã®8æã¨å¤ã®8æã«cronã§åãã¾ãã
var MilkCocoa = require('milkcocoa'); var milkcocoa = new MilkCocoa('********.mlkcca.com'); var history = milkcocoa.dataStore('door').history(); var execSync = require('child_process').execSync; var myD = new Date(); var myYear = myD.getFullYear(); var myMonth = myD.getMonth(); var myDate = myD.getDate(); var yesterday = beforeDay(myYear,myMonth,myDate); if(myD.getHours() >= 19){ var myYear_start = myYear_end = myYear; var myMonth_start= myMonth_end = myMonth; var myDate_start = myMonth_end = myDate; var myHour_start = 8; var myHour_end = 20; }else{ var myYear_start = yesterday['year']; var myMonth_start= yesterday['month']; var myDate_start = yesterday['date']; var myYear_end = myYear; var myMonth_end = myMonth; var myDate_end = myDate; var myHour_start = 20; var myHour_end = 8; } history.sort('desc'); history.size(1); history.limit(1); history.span(new Date(myYear_start,myMonth_start,myDate_start,myHour_start,0,0).getTime(), new Date(myYear_end,myMonth_end,myDate_end,myHour_end,0,0).getTime()); history.on('end', function(data) { if (data) { console.log('data_exists'); execSync('curl -X POST "https://***.***.***.***/data/UUID" --insecure --header "meshblu_auth_uuid: UUID" --header "meshblu_auth_token: TOKEN"'); process.exit(); }else{ console.log('data_nothing'); execSync('curl -X POST "https://***.***.***.***/data/UUID" --insecure --header "meshblu_auth_uuid: UUID" --header "meshblu_auth_token: TOKEN"'); process.exit(); } }); history.run(); function beforeDay(year, month, date) { var d = new Date(year, month, date); d.setDate(d.getDate() - 1); return { year: d.getFullYear(), month: d.getMonth(), date: d.getDate() }; }
å 容ã¨ãã¦ã¯ å®è¡ãããæéãæã®8æã§ããã°ãåæ¥ã®20æããå½æ¥ã®8æã¾ã§ã®ãã¼ã¿ãããå®è¡ãããæéã20æã§ããã°ãå½æ¥ã®8æãã20æã¾ã§ã®ãã¼ã¿ãã確èªãã«è¡ãã¾ãã
ãã¼ã¿ãå
¥ã£ã¦ãããmyThingsã®ããªã¬ã¼1ã«ãã¼ã¿ãéä¿¡ã
ãã¼ã¿ãå
¥ã£ã¦ããªããã°ããªã¬ã¼2ã«ãã¼ã¿ãéä¿¡ã
ã¨ããæãã§ãã
5. myThingsã§ããã·ã¥éç¥ãåãã
myThingsã§ä¸è¨ã®ããã«è¨å®ããã¾ããã
ããªã¬ã¼1ã®æã¯ç¡äºã§ãããã¨ã®éç¥
ããªã¬ã¼2ã®æã¯ãã¼ã¿ãç¡ããã¨ã®éç¥
使ã£ã¦ã¿ãã»ææ³
ã½ã¼ã¹ã®æ¸ãæ¹ãä»çµã¿ã«ã¤ãã¦æªããé¨åã¯å¤ã
ãããã®ã®ããªãã¨ãåä½ãã¾ããã
便å©ãã©ããã§è¨ãã¨ãã¾ã å¾®å¦ã§ãã
æã®éç¥ã«é¢ãã¦ã¯ç¥æ¯ãèµ·ãã¦ãããã©ããããããã®ã¯ä¾¿å©ã§ãããæ¼ãå¤æ¹ã«é¢ãã¦ã¯å¤ã«ãªããªãã¨å®å¦ãããããªãã®ã§æ¹åãå¿
è¦ã ã¨æãã¦ãã¾ãã
ä»å¾
èªç¥çã«ãªã£ãæãèããæã®ã»ã³ãµã¼ã ãã§ãªã人æã»ã³ãµã¼ãªã©ã追å ãã¦é¨å±ã®ä¸ã«ãããã©ããã確èªã§ããããã«ãããã¨èãã¦ãã¾ãã
ã¾ãããã¼ã¿ãéç¥ã ãã§ã¯ãªããWebä¸ããè¦ããããã«ãã¾ãã
githubä¸ã§æ´æ°ãã¦ãã¾ãã®ã§ããããããã°ã覧ãã ããã
ããã§ã¯ãé·æãèªãã§ããã ããããã¨ããããã¾ããã