I got two of Amazon’s newly-available dash buttons with the intention of playing with them to see what they were capable of. They’re a $5 button that when pressed, wakes up, connects to your Wi-Fi, and then turns off. I got the Olay buttons since it’s easy to Sharpie out the logo. Amazon seems to only let you buy two buttons per brand right now, so if you want more black buttons, try Gatorade or look through the selection.
The Button Itself:
- The CPU is a STM32F205RG6 processor which is an ARM Cortex-M3 that can run up to 120mhz and has 128 kilobytes of RAM and 1 megabyte of flash memory for program storage.
- The WiFi module is a BCM943362 module which in combination with the CPU make it a platform for Broadcom’s WICED SDK.
- There’s a 16 megabit SPI flash ROM which is typically used in conjunction with the WICED SDK for storing application data.
- An ADMP441 microphone is connected to the CPU and used by the Dash iOS application to configure the device using the speaker on a phone/tablet.
- There’s a single RGB LED and a button.
Setup is extremely simple. You download the Amazon Shopping app on iOS or Android, go to Menu > Your Account and hold the button down on the Dash Button for 6 seconds to put it into a blue blinking “pairing” mode. From there, your phone can find it, and you can input your network credentials on your phone which will be sent to the button. After that, just close out of the Amazon app before you select anything for the button to purchase, and you’re ready to go. You will probably also want to disable notifications in the Amazon Shopping app settings, as it will prompt you on your phone to finish button setup every time you click it if you don’t.
Detecting Button Presses and Acting on Them:
For this tutorial, I used Python 3.5.1. We’re going to need to install a few libraries, all with “pip install [name]”
Make sure when you type “python” at a command prompt, it shows 3.5.1. After that, pip install the following:
- scapy-python3 (allows us to sniff for the ARP packets the buttons send.)
- requests (if we want to use the Maker Channel on IFTTT, which is an easy way to get things acting on the button presses.)
- phue (if we want to use the button to control Philips Hue lights.)
- We’ll also need to get and install the winpcap installer from: http://www.winpcap.org/install/default.htm
The Python Code:
This is relatively simple. This example triggers the “dashButton1” event on my IFTTT Maker Channel. It also turns all ten of my Hue bulbs off. You’re more than welcome to strip either of those bits of code from the example if you aren’t going to be using those features.
from phue import Bridge # for hue import logging # for the following line logging.getLogger("scapy.runtime").setLevel(logging.ERROR) # suppress IPV6 warning on startup from scapy.all import * # for sniffing for the ARP packets import requests # for posting to the IFTTT Maker Channel # setting up and connecting to Hue bridge b = Bridge('192.168.1.243') b.get_api() # it takes a minute for the scapy sniffing to initialize, so I print this to know when it's actually ready to go print('Init done.') def arp_display(pkt): if pkt[ARP].op == 1: #who-has (request) if pkt[ARP].psrc == '0.0.0.0': # ARP Probes will match this if pkt[ARP].hwsrc == '74:75:48:a5:33:be': # this is the first button MAC address # [Black Button 1] print("Pushed Black Button 1") # trigger IFTTT Maker Channel Event "dashButton1" requests.post("https://maker.ifttt.com/trigger/dashButton1/with/key/VnQ2CMKQEU") b.set_light([1,2,3,4,5,6,7,8,9,10],'on', False) # hue lights off elif pkt[ARP].hwsrc == '10:ae:60:64:04:95': print("Pushed Black Button 2") else: print("ARP Probe from unknown device: " + pkt[ARP].hwsrc) print(sniff(prn=arp_display, filter="arp", store=0))
This code sniffs your network for ARP packets which are sent by devices when they are trying to connect. The buttons will send one every time they are pressed, so we can listen for said packets and then check the MAC address sent by the device that’s trying to connect to see if it is a button that we want to act on. If we haven’t already put the MAC address into an if or elif, then it will fire the else at the bottom so we can copy and paste it into a new elif. You can see my requests.post that activates an event in my IFTTT Maker Channel, and you can put any Python code that you want to in here, it will run when that particular button is pressed.
Hopefully this helps you get your new, $5 networked button up and running and doing cool things! I’ve seen this used for everything from logging events (how often and when) to resetting a timer when pets are fed, to turning lights on and off. Let me know what you do with it in the comments!
Dash Button specs from: https://learn.adafruit.com/dash-hacking-bare-metal-stm32-programming/connections
Original Python code from: http://www.networkworld.com/article/2994131/internet-of-things/inside-the-amazon-dash-button-hack-and-how-to-make-it-useful.html