LoginSignup
20
17

More than 5 years have passed since last update.

MacOSX&Node.jsでAmazon Dash Buttonを制御する

Last updated at Posted at 2016-12-08

概要

Mac OS X環境で Amazon Dash Button のボタンクリック時の動作を Node.jsから制御できるようにしてみます。

Dash Buttonの初期設定

Wifiアクセスポイントを設定して、最後の製品を選ぶところまでステップを進めます。
製品は選択せずに、右上の☓ボタンから設定を終了してください。

環境構築

Node.jsをセットアップしていない場合はインストールしてください。

$ mkdir dash-button // 任意のディレクトリを作成
$ npm init
$ npm install node-dash-button --save

Dash Buttonを探す

以下のコマンドを実行するとWifiに繋がっている端末がScanされるので、該当する端末のMACアドレスをコピーしておきます。
Manufacturer: Amazon Technologies Inc. が正解らしいのですが、自分の環境では Manufacturer: unknown が Dash Buttonでした。

$ cd cd node_modules/node-dash-button
$ sudo node bin/findbutton

app.jsを作成

const dash_button = require('node-dash-button');
const execSync = require('child_process').execSync;
// Dashボタンのアドレス(コピーしたMACアドレスをここに入力)
const dash = dash_button('aa:bb:cc:dd:ee', null, null, 'all');

// ボタンをクリックしたときのアクション
// クリックしてから数秒遅延します。
dash.on('detected', () => {
  const text='こんにちは世界';
    // sayコマンドで声を出力
    execSync(`say ${text}`);
    console.log(text);
});

app.js を実行

$ sudo node app.js
// Dash Buttonクリックで以下が表示されて声が出ればOK
こんにちは世界
20
17
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
20
17