ããã¯é¦¬å ´åã«ç¼ããã°ãã³ãè²·ãã«è¡ã£ã¦ããããããªãã
ããæã£ãã®ã§ããã
çµç·¯
amazon dash ãã¿ã³ã£ã¦ããã¾ããããããããã¡ã«å±ãããã§ãã
Amazon dash å±ããï¼ï¼ pic.twitter.com/Nkah1VhmTl
— tsujimotter (@tsujimotter) December 8, 2016
ãã¿ã³ãæ¼ã㨠Amazon ãããã·ã¥ãã¦ååãå±ãã¦ããããã¾ãã« Internet of Things (IoT) ã®ä¸çããã£ã¦ããã¨ããæãããã¾ãã
ãã¦ããã£ãããã¿ã³ãå±ãããã ãããããã¯ãããã§ãããã
æè¿ã§ã¯ amazon dash ãåã«ãIoT ãã¿ã³ãã¨ãã¦ä½¿ãæè¡ãç´¹ä»ããã¦ãã¾ãã
qiita.com
ããã¿ã³ãä½ã«ã¤ãªãããé¢ç½ãããã¨èããã¨ãã«ãç§ã¯ãããæãåºãã¾ããã
Babascript ã¨ã¯ãé¦¬å ´å è¦ããæ©æ¬ç¿ããããéçºããããã°ã©ãã³ã°è¨èªã§ããé常ã®ããã°ã©ãã³ã°ã³ã¼ãã®ä¸ã«ã人éãå¦çã代è¡ããã人åå¦çããè¨è¿°ãããã¨ãã§ããã¨ãããã®ã§ã人åå¦çã®ãã¼ãããé¦¬å ´åããå®è¡ãããã¨ãããBabascript ã®å称ãã¤ãããã¦ãã¾ãã
WISS2014 ã§ãçºè¡¨ããã¦ããã
ãé¦¬å ´åããã¹ã¦ãã£ã¦ãããã
ã®åè¨ï¼è¿·è¨ï¼ï¼ã¯çç¬ãèªãã ã®ãè¦ãã¦ãã¾ãï¼ç§ããã³çã§è¦ã¦ããï¼ãå稿ã¯ãã¡ãã
Babascript: 人ã¨ã³ã³ãã¥ã¼ã¿ã®å調ã«ããå¦çå®è¡ç°å¢ - WISS2014
https://www.wiss.org/WISS2014Proceedings/oral/039.pdf
ãè¨ç®ãªã©ã³ã³ãã¥ã¼ã¿ãå¾æãªé¨åã¯ã³ã³ãã¥ã¼ã¿ãæ å½ããåµé çãªé¨åã¯äººéãæ å½ãã¹ããã¨ããã人ã¨ã³ã³ãã¥ã¼ã¿ã®å ±åµã®éè¦æ§ãã訴ããç 究ã§ãã¨ã¦ãèå³æ·±ãã³ã³ã»ããã ãªã¨æå¿ãã¦ããã¾ããã
以ä¸ã®ãã¼ã¸ã§ã¯ã³ã¼ããå
¬éããã¦ãã¦ããã¤ã使ã£ã¦ã¿ããã¨æã£ã¦ãã¾ããã
github.com
é¦¬å ´åã¸ã®æ示ã¯ã¯ã³ã©ã¤ãã¼ã§ä»¥ä¸ã®ããã«ããã¾ãã
baba -e "ç¼ããã°ãè²·ã£ã¦ãã¦ãã ãã"
ä½ã£ã¦ã¿ã
ã¨ããããã§ãBabascript ã amazon dash ãã¿ã³ã¨é£åããã¦ãæ¼ãã¨é¦¬å ´åãç¼ããã°ãã³ãè²·ã£ã¦ããããã¿ã³ãä½ãããã¨ããã®ãæ¬è¨äºã®ç®çã§ãã
ä¸æ¹ã§ãæ®å¿µãªããç§ã¯é¦¬å ´åã¨ã¯ç¥ãåãã§ã¯ããã¾ããã
è¦ãç¥ããã®ç§ããçªç¶é¦¬å ´åã«ç¼ããã°ãã³ãè²·ãã«è¡ãããããã«ã¯ãããªãã®ã§ å½ä»¤ã®æ示ã¯ç§å®ã«éãããã«ãã¾ãã
ã§ãã§ããã®ããã¡ãã
ãã£ãï¼ï¼ï¼ã§ããï¼ï¼ï¼ pic.twitter.com/dQ7V9y7AVo
— tsujimotter (@tsujimotter) December 8, 2016
ãã£ã¦ãããã¨ã¯ç°¡åã§ãDash Button for Node ã¨ããã¢ã¸ã¥ã¼ã«ã使ã£ã¦ Amazon dash ãã¿ã³ã®æ¼ä¸ã¤ãã³ããå¾ ã¡åãã¦ãã¤ãã³ããçºçãããä¸è¨ã® Babascript ã¯ã³ã©ã¤ãã¼ãå®è¡ããã ãã§ãã
ã¡ã¤ã³é¨åã¯ã以ä¸ã®ãããªã³ã¼ãã ãã§å®è¡ã§ãã¾ãã
// test.js // sudo node test.js ã§å®è¡ const DashButton = require("dash-button"); // ã¢ã¸ã¥ã¼ã«èªã¿è¾¼ã¿ const PHY_ADDR = "xx:xx:xx:xx:xx:xx"; // ããã§ãã£ã¸ã«ã«ã¢ãã¬ã¹ãæå® let button = new DashButton(PHY_ADDR); // ãã¿ã³ã®ã¢ãã¬ã¹ãå¼æ°ã«æ¸¡ãã¦DashButtonã¯ã©ã¹ãå¼ã³åºã console.log("I'm listening'") // ãããã°ã£ã¦ã¾ããã主張 /* 以ä¸ãçºç«ããã¤ãã³ãã®æå®é¨ã */ button.addListener(() => { // ã¯ã³ã©ã¤ãã¼ã³ãã³ããå®è¡ const exec = require('child_process').exec; exec('baba -e "ç¼ããã°ãã³ãè²·ã£ã¦ãã¦ãã ãã"', (err, stdout, stderr) => { if (err) { console.log(err); } console.log(stdout); }); });
ä¸è¨ã®ã³ã¼ãã¯ã以ä¸ã®ãµã¤ãã§ç´¹ä»ããã¦ãããµã³ãã«ã³ã¼ããã»ãã®å°ãã ãå¤ãããã®ã§ãã
qiita.com
ä½ãæ¹
ã¾ããamazon dash ãã¿ã³ã¨ Mac Book Air ãé£åããä»çµã¿ã§ããã以ä¸ã®è¨äºãåèã«ãã¾ããã
qiita.com
qiita.com
çµæ§é¢ç½ãäºããã£ã¦ããããã§ãã
amazon dash ãã¿ã³ã¯ãé常ã¯é»æºããªãã«ãªã£ã¦ãã¾ãããã¿ã³ãæ¼ä¸ãããã¨ãé»æºãå ¥ãç»é²ããã¦ãã Wi-Fi ãæ¢ãã«è¡ãã¾ããWi-Fi ã«ç¹ãéã«ãIP ã¢ãã¬ã¹ã®éè¤ã確èªããããã« "ARP Probe" ã¨ãããã±ãããããã¼ããã£ã¹ããã¦ããã¨ã®ãã¨ããã®ãã±ããã Mac å´ã§ããã¯ããã°ããã®ã§ãããMacå´ã«ã¯ node.js ã§æ¸ãããµã¼ããç«ã¦ã¦ãARP ãã±ãããå¾ ã¡åãã¾ãã
amazon dash ãã¿ã³ããããã¯ã¼ã¯ã«æ¥ç¶ãããã¨ãHTTP ãªã¯ã¨ã¹ããã¢ãã¾ã³ã«å¯¾ãã¦éããã注æå¦çãè¡ããã¾ãããã®ã¾ã¾ã§ã¯ãã¿ã³ãæ¼ããã³ã«è³¼å ¥ããã¦ãã¾ãã¾ãããåé¿ããæ¹æ³ãããã¾ãã
åæç»é²ã®æå¾ã«ååã¨ãã¿ã³ãç´ä»ããè¨å®ãè¡ããã¾ãããããã§Ããã¿ã³ãæ¼ãã¦è¨å®ãä¸æãã¦ãã¾ãã®ã§ãããã»ããã¢ãããå®äºãã¦ããªããçã®è¦åãåºã¾ããç¡è¦ãã¦ãã¾ãã¾ããã
ããã§æ°ã«ãªãã®ããä¸åº¦è¨å®ãä¸æãã¦ãã¾ã£ã amazon dash ãã¿ã³ã¯ããé常éã使ããªãã®ããã¨ããç¹ã§ãããã¡ããåè¨å®ãããã¨ã§ä½¿ããããã«ãªãã¾ãï¼å®å¿ãã¦ããã¯ã§ãã¾ããï¼ãè¨å®ç»é¢ã«ããã® Dash Button ãç¡å¹ã«ãããã¨ãããã¿ã³ãããã¾ããå°ãæã表ç¾ã§ããããã®ãã¿ã³ãæ¼ãã¨ä½¿ç¨å¯è½ãªãã¿ã³ä¸è¦§ããåé¤ããã¦ãå度ãæ°ãã Dash Button ãã»ããã¢ãããããè¨å®å¯è½ã«ãªãã¾ãã
ç¶ãã¦ãdash button ãæ¤ç¥ãã node ãµã¼ãã®ã»ããã¢ããããã¾ããããç§ã¯ Mac Book Air ã使ã£ã¦ããã®ã§ããã®ç°å¢ã«åããã説æã¨ãªãã¾ãã
注æãã¦ã»ããã®ã¯ãMac ãæ¥ç¶ããWi-Fi㯠dash button ã«åæè¨å®ãã Wi-Fi ã¨åããã®ã«æ¥ç¶ãã¦ãã ãããï¼ç§ã¯ééã㦠g 㨠a ãç°ãªã SSID ã«æ¥ç¶ãã¦ãã¾ã£ã¦ãã¤ãªãããªãã¤ãªãããªãã¨ç¦ãã¾ãããï¼
ã¾ãï¼node 6 ãã¤ã³ã¹ãã¼ã«ãã¾ããå¤ããã¼ã¸ã§ã³ã ã¨å¯¾å¿ãã¦ããªãããã§ãã
次ã«ããã¸ã§ã¯ãã®ãã£ã¬ã¯ããªãä½ã£ã¦ãããã« Dash Buton for Node ãã¤ã³ã¹ãã¼ã«ãã¾ãã
$ mkdir node-button $ cd node-button $ npm init $ npm install --save dash-button
ä¸è¨ã®ã¹ãããã§ã¨ã©ã¼ãåºã人ã¯ï¼ã¤ã³ã¹ãã¼ã«ããã¦ãã Python ã®ãã¼ã¸ã§ã³ã«æ°ãã¤ãã¦ãã ãããPython㯠2 ç³»åã§ãªãã¨ãããªããããªã®ã§ãããç§ã® mac ã«ã¯ 3.5.11 ãå ¥ã£ã¦ãã¦ã¨ã©ã¼ãèµ·ãã¾ããã
ãã¼ã¸ã§ã³ã®ç°ãªã Python ãåå±
ããã¦ã使ãåãããã¨ãã¯ãpyenv ã便å©ã§ãã
qiita.com
qiita.com
pyenv ãã¤ã³ã¹ãã¼ã«ããã¨ãå ã å ¥ã£ã¦ãã Python 㯠system ã¨ãã¦æ±ããããããã¢ã³ã¤ã³ã¹ãã¼ã«ã®å¿ è¦ã¯ããã¾ããã
Pypcap ã¨ããã¢ã¸ã¥ã¼ã«ãå¿ è¦ããããã¾ãããpip ã使ã£ã¦ã¤ã³ã¹ãã¼ã«ãã¦ããã¾ãã
pip install --upgrade pip pip install pypcap
Dash Buton for Node ãã¤ã³ã¹ãã¼ã«ã§ããããpackage.json ã® "script" ã®ç®æã以ä¸ã®ããã«æ¸ãæãã¾ãã
{ "scripts": { "scan": "dash-button scan" } }
ãã®ããã«å¤æ´ãããã¨ã§ã以ä¸ã®ã³ãã³ã㧠ARP scan ãå®è¡ã§ãã¾ãã
sudo npm run scan
sudo ãã¤ããã®ãå¿ããªãã§ãã ããã
dash button ãæ¼ãã¦ã¿ã¦ãã ããããã¾ãããã°ãæ°ç§å¾ï¼è¥å¹²ã©ã°ãããï¼ã«ãã¿ã³ã® MAC ã¢ãã¬ã¹ã表示ããã¾ããç§ã®ãã¿ã³ã¯ ac ããå§ã¾ã MAC ã¢ãã¬ã¹ã§ããã
ãã® MAC ã¢ãã¬ã¹ãæ§ãã¦ããã¦ãæåã«ç´¹ä»ãã test.js ã®ã³ã¼ãã«æ¸ãè¾¼ã¿ã¾ãã
sudo node test.js
ãå®è¡ããã¨ãããã°ã©ã ãå®è¡ãããã¿ã³ãå¾ ã¡åãã¾ãããã®ã³ã¼ãã§ã¯ããã¿ã³ã«åå¿ãã¦
baba -e "ç¼ããã°ãã³ãè²·ã£ã¦ãã¦ãã ãã"
ãå®è¡ããã¾ãã
Babascriptãåããªãï¼ï¼ï¼
ãã¨ã¯ãBabascript ãã¤ã³ã¹ãã¼ã«ãã¦é£åãããã ãã§ããã
ã¤ã³ã¹ãã¼ã«ã¯ç°¡åã§ãã
gem install babascript
babascript ã¨ããã¤ã¤ãä¸èº«ã¯ Ruby ã§æ¸ããã¦ããã¿ããã§ãã
ãããã«ï¼baba -e "ãã¹ã" ã¨æã£ã¦ã¿ãã¨ã
$ baba -e "ãã¹ã" ãã¹ã dyld: lazy symbol binding failed: Symbol not found: _clock_gettime Referenced from: /Users/tsujijunpei/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/extensions/x86_64-darwin-15/2.2.0-static/eventmachine-1.2.1/rubyeventmachine.bundle (which was built for Mac OS X 10.12) Expected in: /usr/lib/libSystem.B.dylib dyld: Symbol not found: _clock_gettime Referenced from: /Users/tsujijunpei/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/extensions/x86_64-darwin-15/2.2.0-static/eventmachine-1.2.1/rubyeventmachine.bundle (which was built for Mac OS X 10.12) Expected in: /usr/lib/libSystem.B.dylib Trace/BPT trap: 5
ãªãã ãã®ã¨ã©ã¼ã»ã»ã»ã
ãã®ãã¨ãããã調ã¹ã¦ã¿ãã®ã§ãããæ®å¿µãªãããã¾ããããã
ï¼ãï¼ãï¼
ä»æ¹ãªãã®ã§ãåãä½è ã®ä½ã£ã tw ã¨ãããã¼ã«ã使ã£ã¦ãè¶ãæ¿ããã¨ã«ãã¾ããtw ã«ã¤ãã¦ã®æ å ±ã¯ä»¥ä¸ã®ãã¼ã¸ã«è¼ã£ã¦ãã¾ãã
ã¤ã³ã¹ãã¼ã«ã¯ç°¡å
gem install tw
"hoge" ã¨ãã¤ã¼ãããããã¨ãã¯ä»¥ä¸ã®ã³ãã³ãã§ãªã¼ã±ã¼ã便å©ã§ãã
echo 'hoge' | tw --pipe
tw ãå®è¡ããã¹ã¯ãªãããæ¸ã㦠baba ã¨ååãä»ãã¦ããã¾ãã
#! /bin/sh echo "@tsujimotter ç¼ããã°ãè²·ã£ã¦ãã¦ãã ãã" | tw --pipe
ããã¦å®è¡æ¨©éãã¤ãã¦ããã
chmod 701 baba
ããã«ï¼/usr/local/bin ã«
ln -s /path/to/baba /usr/local/bin/baba
ã¨ãã¦ã·ã³ããªãã¯ãªã³ã¯ãè²¼ã£ã¦ããã¾ããï¼/path/to ã®ã¨ããã«ã¯ baba ã®ç½®ãã¦ãããã£ã¬ã¯ããªãæå®ï¼
ããã¨ï¼
baba
ã¨ã³ãã³ããå®è¡ããã ãã§ãã¤ã¼ãããã¾ãã
ãã¤ãã¿ã¼ã®ä»æ§ä¸ãåããã¤ã¼ãã®é£ç¶æ稿ã¯ç¡è¦ããããããªã®ã§ããã¤ã¼ãã®å¾ãã«æ¥ä»ãªã©ããããã¨è¯ãããããã¾ããã
課é¡
ãã±ããã¹ãã£ã³ã®å®å®æ§
åç»ã§ã¯ããä¸çºã§æåãããã®ããã«æ®ã£ã¦ãã¾ããããããããªãå®å®ãã¾ããã
ä½åæ¼ãã¦ãåå¿ããªãããã¾ã«ãããã¯ã¼ã¯ã«ç¹ãç´ãã¨åå¿ãããã¨ãããã
Dash Button for Node ã§ã¯ ARP ã®ããã¼ããã£ã¹ããã±ãããç£è¦ãã¦ãããããªã®ã§ããããã£ãã·ã¥ãä½ããåãã¦ãã¾ã£ã¦ãã¾ããã£ããã§ããªãã®ã§ããããã
ã¨ããããç§ã¯ãMac ã® Wi-Fi ã®æ¥ç¶å ããã£ããåãæ¿ãã¦ããæ»ããã¨ããããªãã ãããããããªã解決æ³ã«ãã£ã¦ãªãã¨ãåããã¦ãã¾ãã
ã§ããããããç¼ããã°ãã³ãã»ããã¨ãã«ããã¿ã³ãæ¼ãåã«ãµã¼ãã¼ã®ãããã¯ã¼ã¯ãæ¥ç¶ããªãããªããã°ãªããªããä½ã¨ããããã¨ããã§ãã
Babascript ã¨ã®é£å
ã¾ããã® Babascript ã使ããªããã¨ããé常ã«æ®å¿µãªçµæã¨ãªãã¾ããã
ã¨ã©ã¼ã®åå 㯠Ruby ã®ãã¼ã¸ã§ã³ã®åé¡ãªã®ããã¯ãã¾ãã¤ã³ã¹ãã¼ã«è¶³ããªããã®ãããã®ãã»ã»ã»ãåå ã調ã¹ã¦è§£æ±ºãããã§ãã
éç¥å
ã®ãµã¼ãã¼ãè½ã¡ã¦ããã¨ããå¯è½æ§ããã£ã¦ãåé¡ã¯æ ¹æ·±ãããããã¾ããã
ãããã«
Amazon dash ãã¿ã³ãå±ããã®ã§ãå¢ãã§æ¸ãã¾ããããããããã¾ããããªããã¨ãããã¾ããã触ã£ã¦ã¿ã¦æ¥½ããã£ãã§ãã
使ã£ã¦ã¿ã¦ããã£ããã¨ã§ãããããã¯ããã«ã¯ãã®ãã¿ã³ã¯çµæ§ä½¿ãåæãæªãã§ããããã¿ã³ãæ¼ãã¦ããåå¿ã¾ã§ã®ã©ã°ãããã¾ããããã¿ã³ãç£è¦ããããã«ã¯ä½ããã®ãµã¼ãã«ç¸å½ãããã·ã³ï¼ã©ãºããªã¼ãã¤ã¨ãï¼ã常æç½®ããªããã°ãªãã¾ããã
æ¢ã« Amazon ã§ã¯ IoT ãã¿ã³ã¨ã㦠Developer åãã®ãã®ã売ã£ã¦ããã¿ããã§ãããæ¥æ¬ã§ã¯ã¾ã 使ããªãã¿ããã§ãããããã使ããããã«ãªã£ãã便å©ããããã¾ãããHTTPãªã¯ã¨ã¹ããç´æ¥éããã¿ããã§ããã
ãã£ãããªã®ã§ãã®è¨äºãããã¡ããã¯ã¢ããã³ãã«ã¬ã³ãã¼ã«å¯ç¨¿ãããã¨æã£ãã®ã§ãããä»å¹´ã¯ããåã¾ã£ã¦ãã¾ã£ãã¨ã®ãã¨ãæ®å¿µããã
qiita.com