はじめに
弊社、コーヒーメーカーが1台あり、毎朝新人さん達がおいしいおいしいコーヒーを作ってくれます。
しかしそのおいしさ故結構な数の利用者がいるため、よく無くなってしまいます。
その都度新人さんたちに「ごめんコーヒー無くなっちゃった・・・」ってメッセージを送るのはめんどくさいですよね?
ならば、ボタン一つでコーヒー無くなりそう・・・を伝えられないかと思った次第でございます。
環境
- AmazonDashButton 500円くらい、コーラ買えるやつ
- RaspberryPi ModelB Amazonで買った3000円くらい
- MicroSDカード 32GB
- MicroUSBケーブル(電源)
- HDMIケーブル
- ディスプレイ(HDMI対応)
- Node.js v8.11.1
- Dasher v1.4.1
Dash Buttonのセットアップ
下記記事を参考にさせて頂きました。
手順は現在(2018/08/02)も変わっていないようです。
Amazon Dash ButtonをただのIoTボタンとして使う - Qiita
RaspberryPiのセットアップ
Raspberry Piのセットアップは下記のサイトを参考にさせて頂きました。
Raspberry Pi 初期設定 - Qiita
Wi-fiがステルス設定の場合についてですが、scan_ssid=1
を設定ファイルに追記したあと、再起動が必要でした。
設定ファイル編集後、
pi@raspberrypi:$ sudo reboot
して
pi@raspberrypi:$ ip addr
でIPアドレスが取得できていればOKです。
Node.jsインストール
最新版じゃなくてもよかったので、普通にapt-get installします。
pi@raspberrypi:$ sudo apt-get update
pi@raspberrypi:$ sudo apt-get upgrade
pi@raspberrypi:$ sudo apt-get install -y nodejs npm
Gitインストール
pi@raspberrypi:$ sudo apt-get install -y git
libpcapのインストール
Dasherを動かすにはパケットキャプチャのライブラリ「libpcap」が
必要です。
pi@raspberrypi:$ sudo apt-get -y install libpcap-dev
Dasherのclone
pi@raspberrypi:$ git clone https://github.com/maddox/dasher.git
pi@raspberrypi:$ cd dahser
pi@raspberrypi:~/dasher$ npm install
DashButtonのMACアドレス捜索
pi@raspberrypi:~/dasher$ ./script/find_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.'
といったメッセージが表示されたらDashButtonを押します。すると・・・
Possible dash hardware address detected: xx:xx:xx:xx:xx:xx Manufacturer: unknown Protocol: udp
Possible dash hardware address detected: xx:xx:xx:xx:xx:xx Manufacturer: unknown Protocol: arp
これがDashButtonの情報ですので、MACアドレス(「xx:xx:xx:xx:xx:xx」となっている部分)を控えておいてください。
configファイルの編集
/config/config.json
を編集していきますが、/config/config.example.json
というサンプルが既にあるかと思います。
これをコピーして編集していくと楽ちんですね。
cp config/config.example.json config/config.json
vim config/config.json
今回は単純にパラメーター無しのHTTPリクエストを送信できればいいので、下記のような感じに編集します。
address: 「DashButtonのMACアドレス捜索」で取得したMACアドレスを入力します。
url: 後ほど記述する「Office365 Flow セットアップ」で発行するHTTP要求先URLを入力します。
{"buttons":[
{
"name": "Debug Dash Button",
"address": "xx:xx:xx:xx:xx:xx",
"url": "https://hogehogehogehoge...",
"method":"GET"
}
]}
これでDasherのセットアップは完了です。
Office365 Flow セットアップ
別記事にまとめました!
Office365 Flow -> Yammerに投稿する
Dasher起動!
pi@raspberrypi:~/dasher$ sudo npm start
ボタンを押す!
参考情報
Raspberry Pi 初期設定 - Qiita
Microsoft Flowのドキュメント | Microsoft Docs
Amazon Dash ButtonをただのIoTボタンとして使う - Qiita