Last active
November 7, 2019 05:44
-
-
Save takustaqu/e54eeaf630c2c7056651c8da8449c0fb to your computer and use it in GitHub Desktop.
Amazon Dash Buttonを(正しくない方向で)使ってみた ref: https://qiita.com/takustaqu/items/8539b33780c9675c8657
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ npm init | |
$ npm install --save dash-button | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"scripts": { | |
"scan": "dash-button scan" | |
} | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ sudo npm run scan | |
// この間で普通にDashボタンのセットアップをiPhone/AndroidのAmazonAppを用いて行います。 | |
// 商品選択を×ボタンで抜ければ注文はせずネットワークにシグナルだけを流してくれる状態になります。 | |
Scanning for DHCP requests and ARP probes on en0... | |
Detected a DHCP request or ARP probe from xx:xx:xx:xx:xx:xx // ←こいつがDashボタンをフィジカルアドレス。 | |
// 出てこなければセットアップ後に1回ボタンをポチっとしてみてください。 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'") // 「がんばってます」を主張 | |
let i = 0; // カウントしたかったのでとりあえずカウント用の変数を置いときます。 | |
/* | |
以下が発火するイベントの指定部。 | |
*/ | |
button.addListener(() => { | |
console.log("["+(i++)+"] It works."); // 今回はシンプルに呼び出し回数を併記してコンソール出力 | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment