前回、Amazon Dash ボタン を押した時のイベントを取得することができたので、
そのタイミングで、Google Home mini に喋らせてみました。
以前にもやった通り、Firebase 経由 で通信します。
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:e:ee', null, null, 'all');
const text='Dash Server Start!';
console.log(text);
// ボタンをクリックしたときのアクション
// クリックしてから数秒遅延します。
dash.on('detected', () => {
var request = require('request');
var options = {
uri: "https://fir-XXXXX.firebaseio.com/googlehome.json",
headers: {
"Content-type": "application/json",
},
json: {
"msg": "ボタンが押されたよ!"
}
};
request.put(options, function(error, response, body){});
});
Amazon Dash ボタンが押される
↓
Firebase のデータが更新
↓
ローカルマシンで起動している node.js がイベントを拾う
↓
Google Notifier でメッセージを送信
↓
Google Home mini が 「ボタンが押されたよ!」と喋りました。