10
11

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Amazon Dash Button + Raspberry Pi + Office365で社員が幸せになれる

Last updated at Posted at 2018-08-01

はじめに

弊社、コーヒーメーカーが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を設定ファイルに追記したあと、再起動が必要でした。

設定ファイル編集後、

terminal
pi@raspberrypi:$ sudo reboot

して

terminal
pi@raspberrypi:$ ip addr

でIPアドレスが取得できていればOKです。

Node.jsインストール

最新版じゃなくてもよかったので、普通にapt-get installします。

terminal
pi@raspberrypi:$ sudo apt-get update
pi@raspberrypi:$ sudo apt-get upgrade
terminal
pi@raspberrypi:$ sudo apt-get install -y nodejs npm

Gitインストール

terminal
pi@raspberrypi:$ sudo apt-get install -y git

libpcapのインストール

Dasherを動かすにはパケットキャプチャのライブラリ「libpcap」が
必要です。

terminal
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アドレス捜索

terminal
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を押します。すると・・・

terminal
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というサンプルが既にあるかと思います。
これをコピーして編集していくと楽ちんですね。

terminal
cp config/config.example.json config/config.json

vim config/config.json

今回は単純にパラメーター無しのHTTPリクエストを送信できればいいので、下記のような感じに編集します。
address: 「DashButtonのMACアドレス捜索」で取得したMACアドレスを入力します。
url: 後ほど記述する「Office365 Flow セットアップ」で発行するHTTP要求先URLを入力します。

config.json
{"buttons":[
  {
    "name": "Debug Dash Button",
    "address": "xx:xx:xx:xx:xx:xx",
    "url": "https://hogehogehogehoge...",
    "method":"GET"
  }
]}

これでDasherのセットアップは完了です。

Office365 Flow セットアップ

別記事にまとめました!
Office365 Flow -> Yammerに投稿する

Dasher起動!

terminal
pi@raspberrypi:~/dasher$ sudo npm start

ボタンを押す!

参考情報

Raspberry Pi 初期設定 - Qiita
Microsoft Flowのドキュメント | Microsoft Docs
Amazon Dash ButtonをただのIoTボタンとして使う - Qiita

10
11
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
10
11

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?