I’m not an Amazon Prime member but I did receive a Dash button as a gift from a work colleague. He was aware that I was interested in attempting to hack one of these and force it to do my bidding. I wasn’t sure if I would be able to without a Prime membership but I thought that there must be a way around that.

01 Amazon Dash button

Dive in

My dash button is a simplehuman button. We had joked about getting a durex button but, in the end, this seemed like the least offensive to me. Take a note of the date of this post, it seems that there are different models of the dash button and I’m working with one that was purchased around the date of this post.

I’m planning on having my dash button switch off my smart lights (I have a post in the works for this one and it’s been a long time coming) as an initial test, with a view to using it as a “before bed” switch whereby everything is turned off before I go to bed. Right then, let’s dive in:

  • Unbox and press and hold the button for around 6 seconds

  • When the blue light starts to blink it should be broadcasting on “Amazon ConfigureMe”

  • Connect your computer to that wifi network and open 192.168.0.1 in your browser

  • You should see some details about your Dash button. Make a note of the MAC address.

02 Dash details

  • Disconnect from the Wifi network.

  • Download the Amazon app from the app store for your phone (if you don’t already have it)

  • By now your Dash button has probably stopped broadcasting so press and hold the button for around 6 seconds again

  • Open the Amazon app on your phone

  • Go to Account > Dash buttons and setup the device to connect to your Wifi but don’t select a product (quit the app when the products screen is shown).

03 04

  • Follow the on screen instructions to connect it to your network but make sure you don’t select a product from the product page as this will order that product every time you press the button. Simply quit the app at this point.

Onto the Pi

Back into more familiar territory, except for the fact that I’m something of a python noob. Anyway, from here we will try to sniff our network traffic to watch for the Amazon dash button.

ssh onto your pi and run the following:

sudo apt-get update && sudo apt-get -y dist-upgrade

Now we can continue installing the packages we need:

sudo apt-get install python-scapy

Scapy is the program we will use to sniff for the Dash button MAC address.

Now we can write a script to test the button. Create a new file (I’ve called mine dash_trigger.py) and put the following code into it. Replace the xx:xx:xx:xx:xx:xx with your own MAC address and make sure the mac address is in lower case for the letters:

#!/usr/bin/env python

from scapy.all import *

def arp_detect(pkt):
if pkt.haslayer(ARP):
    if pkt[ARP].op == 1: #network request
        if pkt[ARP].hwsrc == 'xx:xx:xx:xx:xx:xx':
                print ("button press detected")

print (sniff(prn=arp_detect, filter="arp", store=0))

Now we can run this script (don’t forget to sudo it):

sudo python dash_trigger.py

Now press your Dash button and you should see the “button press detected” pop up in your terminal.

I ran this script where it dumped all of the MAC addresses out:

#!/usr/bin/env python

from scapy.all import *

def arp_detect(pkt):
  if pkt.haslayer(ARP):
    if pkt[ARP].op == 1: #network request
        // note the new line below
        print pkt[ARP].hwsrc
        if pkt[ARP].hwsrc == 'xx:xx:xx:xx:xx:xx':
                print ("button press detected")

print (sniff(prn=arp_detect, filter="arp", store=0))

This seemed to show that the dash button shows twice on the button press. I guess this means we should drop any requests that are within a few seconds of each other. This is something to keep in mind for the further development of this project in case running things twice would be a problem for your choice of use for the button.

Note, this only seems to work if you have the pi connected via the ethernet. After much confusion and version checking it seems as though you can’t use the ARP filter over WiFi. This may not be news to some people, but it was to me. So if you happen to see a “ScapyException” of the “filter” variety, this may be your issue too.

From here you can change the project to do what you would like to do. I’m planning on turning my lights off using this button just for a test. I have my lights exposed on a web service so I will be firing a GET request to this service to switch them off.

#!/usr/bin/env python

import requests

from scapy.all import *

def arp_detect(pkt):
    if pkt.haslayer(ARP):
        if pkt[ARP].op == 1: #network request
            if pkt[ARP].hwsrc == 'xx:xx:xx:xx:xx:xx':
                    print ("button press detected")
                    r = requests.get("https://mygetrequest.com")
                    print (r.status_code)

print (sniff(prn=arp_detect, filter="arp", store=0))

After this I created a service to run in /etc/init.d

#! /bin/sh
# /etc/init.d/example

case "$1" in
  start)
    echo "Starting example"
    # run application you want to start
    python /home/pi/dash_button.py &
    ;;
  stop)
    echo "Stopping example"
    # kill application you want to stop
    killall python
    ;;
  *)
    echo "Usage: /etc/init.d/example{start|stop}"
    exit 1
    ;;
esac

exit 0

Then I fired it up:

sudo service testdash start

After this I tested my button and it was working. All done for now I guess, at least until I figure out what else I want this button to do.

One final note (rogue push notifications)

I noticed that, every time I pressed the button, I received a push notification on my phone about “completing the setup”. To stop this from continuing for every button press, open the Amazon app and go to settings -> notifications and switch off the “Dash Button Updates” notification. Alternatively, you can uninstall the app if you don’t use it for anything else.