Using an Amazon Dash Button with NodeJS
I finally picked up an Amazon Dash Button to see how they can be used. Here's how to interact with one via node.js
.
This post has been tested with the
JK29LP
model - if you have another model that does/doesn't work let us know in the comments
First, you'll need to install libpcap
to monitor your network for traffic. This is required as the dash button can't be customised so we just watch for any traffic being sent and trigger our own events when it happens. I'm on OSX so I install libpcap
with Homebrew. If you're on another OS, you'll need to install it via your package manager.
bash
brew install libpcap
Once this is installed, we need to find the MAC
address of the button. This so so that our script knows which device we're watching for network traffic. The library we'll be using provides a great little script for this. Install the library and run the script now (it needs sudo
as libpcap
accesses network devices)
bash
npm install node-dash-buttonsudo ./node_modules/node-dash-button/bin/findbutton
It should welcome you with the following message:
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.'
Don't trust it! There's an issue identifying dash buttons so it'll always say Manufacturer: unknown
. Go ahead and press your dash button now.
You're expecting to see something like this:
Possible dash hardware address detected: 84:dd:a8:42:1e:0c Manufacturer: unknown Protocol: udp
Possible dash hardware address detected: 84:dd:a8:42:1e:0c Manufacturer: unknown Protocol: arp
You might see lots of arp
responses - you're looking for the address that has both a udp
and an arp
entry. This is your dash button, so make a note of the MAC
address (84:dd:a8:42:1e:0c
). Make sure to ctrl+c
the script after capturing your MAC
address
Now you have everything you need to write some code! Create index.js
with the following contents, swapping out the MAC
address for your button's address:
javascript
var dash_button = require("node-dash-button");var dash = dash_button("84:dd:a8:42:1e:0c", null, null, "udp");dash.on("detected", function () {console.log("Pushed the button!");});
Run sudo node index.js
then press your button - you should see a message logged to the console.
That's all there is to it! So in summary:
brew install libpcap
npm install node-dash-button
sudo ./node_modules/node-dash-button/bin/findbutton
Press your dash button
Make a note of your
MAC
addressctrl+c
thefindbutton
scriptCreate
index.js
usingnode-dash-button
sudo node index.js
Press your dash button