Amazon Dash ボタン を押して イベントを取得してみる

↓こちらのサイトを参考に、Dash Buttonを押したイベントを取得したいと思います。

npm install をする際、python 3.x を使っているとエラーが出るみたいです。

なので、python2.7 を使います。

npm install --python=python2.7

↓こちらのサイトを参考に、DashButtonのMACアドレスを取得します。

./script/find_button
Password:

パスワードを入れてから Dash Button を押すと、

Watching for arp & udp requests on your local network, please try to press your dash now
Dash buttons should appear as manufactured by 'Amazon Technologies Inc.'
Possible dash hardware address detected: ee:ee:ee:ee:ee:ee Manufacturer: unknown Protocol: udp
Possible dash hardware address detected: ee:ee:ee:ee:ee:ee Manufacturer: Apple Protocol: arp

と出力されます。

「Manufacturer: unknown」と表示されていました。

次に、app.js を 作ります。

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

const text='Dash Server Start!';
console.log(text);

// ボタンをクリックしたときのアクション
// クリックしてから数秒遅延します。
dash.on('detected', () => {
const text='Hello World!';
console.log(text);
});

ターミナルで、

sudo npm start

これでDash の node.js のサービスが立ち上がりました。

この状態で、Dash Button を押すと、イベントが取得でき、

Hello World

と表示されました。

関連記事

返信を残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です

CAPTCHA