loading

The Amazon Dash button is a great new device that can be bought for only $5. Very shortly after the release of it the first working hack of it was published online. It showed you how to detect when the button was pushed on your computer and to launch a program in response to it using a few lines of python code. I was very impressed with the hack and I wondered if I could make it run something on hardware instead. My first thought was the Raspberry Pi.

In this tutorial I will show you how to use a Raspberry Pi with the Dash Button to control a lamp or any other electronic device.

Step 1: Materials

Material List:

1.Raspberry Pi-I would recommend using the new Raspberry Pi 2 or you could use the B/B+.You will also need the basics for it such as a mouse,keyboard, power supply, and display.

2.Amazon Dash Button-Any product button will do, just make sure to not set it up when you get it.

3.PowerSwitch Tail II-This is used by the Raspberry Pi to turn on and off any AC electronic device.

4.SD Card-You will need to install a fresh copy of Raspbian onto it. Make sure that it is 4GB or more.

5.Wifi Adapter-This is to make sure that your Raspberry Pi can connect to the internet to recieve an ARP probe any time the button is pushed.

6.Raspberry Pi ribbon cable-this is not needed if you want to solder or use alligator clips to connect the PowerSwitch Tail to your Raspberry Pi's GPIO connectors.

7. Any AC Device- this is up to you to decide what device you want to turn on. I will use a my bedroom lamp for this experiment.

Step 2: Raspberry Pi Setup

To start off you will need a SD card with Raspbian installed. I would highly reccomend using this Instructable from Beta Mode on how to do this-Link

Once it is setup boot up your Raspberry Pi and go through Raspi-config to make sure all your settings are set to the default. Then type startx to launch the desktop. You will need to connect to the internet. You can find the network manager in the Acessories pane of the start menu. Once you connect to wifi we will need to log off and go back to the terminal view. We will then need to download the necessary packages:

Scapy:

This is a python library that allows you to scan for ARP signals from the Amazon Dash button.

To install scapy use the following command:

sudo apt-get install scapy

GPIO Library:

This is a python library that allows you to control the gpio pins of your Raspberry Pi.

To install it use the following commands:

wget http://pypi.python.org/packages/source/R/RPi.GPIO...

tar zxf RPi.GPIO-0.1.0.tar.gz

cd RPi.GPIO-0.1.0

sudo python setup.py install

Once we finish this we will have the ability to use our Raspberry Pi to respond to the Amazon Dash Button.

Step 3: Setup the Amazon Dash Button.

To enable our Dash button to communicate we will need to set it up first.

To start off download the Amazon App on your phone and login to your Amazon account.

On the app click the menu button in the upper right corner. Then click the Your Account option and scroll down to the Dash Devices group. Click the "Set up a new device" button.

Follow the below steps to setup your button:

  1. Click the Get Started button.
  2. It will then ask you to type in the Network name and Password of your network. Enter this and click continue.
  3. Hold your dash button until the light on it starts to flash blue.
  4. Turn up the volume on your phone and set the Dash button next to your phones speaker and click the next connect button.
  5. Once it connects, it will ask you for a product do not select a product instead close the app out.

Great! Your button is now hacked!

We will then need to program your Raspberry Pi.

Step 4: Program Your Raspberry Pi

To start off we have to scan for our Amazon Dash button's IP Adress.

We will have to use the code from the original hack of the Dash Button:

from scapy.all import *

def arp_display(pkt):

if pkt[ARP].op == 1: #who-has (request)

if pkt[ARP].psrc == '0.0.0.0': # ARP Probe

print "ARP Probe from: " + pkt[ARP].hwsrc

print sniff(prn=arp_display, filter="arp", store=0, count=10)

This will scan for the Amazon Dash Button's ARP Signals on the network and return the MAC Adress of our button.

After running this program we will copy the MAC address and add it to a modded version of the original hack.

Save this as scan.py

Open a new terminal and use the "cd" command into the directory where you saved scan.py

To run the program type sudo python scan.py

When the program is finished copy the MAC address into the next program.

from scapy.all import *

import RPi.GPIO as GPIO

GPIO.setup(18, GPIO.OUT)

def arp_display(pkt):

if pkt[ARP].op == 1: #who-has (request)

if pkt[ARP].psrc == '0.0.0.0': # ARP Probe

if pkt[ARP].hwsrc == 'MAC Address': # Button MAC Address

GPIO.output(18, True)

else:

print "ARP Probe from unknown device: " + pkt[ARP].hwsrc

print sniff(prn=arp_display, filter="arp", store=0, count=10)

This program will allow you to turn pin 18 on when the button is pushed.

Save this as button.py

Proceed to the next step.

Step 5: Run the Program.

To sucessfully run the program we need to hook up our PowerSwitch II. Connect your GPIO ribbon cable to the connector on your Raspberry PI. Connect a wire from pin 18 on the GPIO Cable to the PowerSwitch tail to the + wire of the PowerSwitch Tail and the ground to one of the ground pins on the GPIO connector. Connect your PowerSwitch tail to an AC outlet on your wall and connect the other side to your AC Device.

Start the program on the Raspberry Pi just like the scan program. Once it is running, push the button on your Amazon Dash Button and watch the device turn on!

Thank you for reading my Instructable and please vote for it in the Raspberry PI Contest!

Step 6:

<p>Benlabs, <br>This is so cool, but I'm worried that Amazon will/has lock us out of this sort of functionality, e.g. by not enabling the button unless a product is associated or by changing how the buttons deal with a DHCP server in some way. I know if *I* were selling tiny embedded internet computers for $1 (the buttons) as a loss leader, I'd be seriously irked by this application. :) That's not a reason we shouldn't do it, but I'm worried they have every reason to rain on our parade if they can. Thoughts? </p>
<p>Could I run this script on any device attached to the network (without GPIO of course) or does the dash button connect to the PI? I'm unsure how ARP probes work, do they just get sent to every device on the network?</p>
<p>I'm having trouble with the basics on connecting the powerswitch tail to the raspberry pi. I have a ribbon GPIO connector, do I insert the male end of a jumper cable into the correct GPIO and then strip the female end of the cable and shove it into the powerswitch tail?</p>
Yes that should work fine.
<p>I'm trying to setup a similar thing at home except I have it controlling a wemo switch. How do you get the button.py program to run in the background and be monitoring for a button push all the time. I can only get it to run manually and it only scans for 30 seconds or so. </p>
Try adding a basic python loop.
Yeah, you say that like I know how to do that! Not got the first clue about python.
<p>can't get this to work &quot;ImportError: No module named pcapy&quot;</p>
Try this command<br>sudo apt-get install python-pcapy
<p>Such a cool idea! </p>

About This Instructable

20,312views

35favorites

License:

More by Benjamin E.B:Amazon Dash Button Lamp Control 
Add instructable to: