Introduction: Turn Your Amazon Button Into a Phone-Finder
This is a simple tutorial for hacking your Amazon dash button to call a phone number when pressed. I made it so I can call my phone when I use it, please comment with what cool innovative projects you make out of it (doorbell, paging system, etc).
There are 6 simple steps:
- Setting up the Amazon Dash button
- Installing the Raspbian OS on your Raspberry Pi
- Creating a sniffer using the Scapy Python library
- Automating an outgoing call over the World Wide Web using Twilio
- Keeping your sniffer running with supervisordand finally
- Using supervisord to automatically start your sniffer program upon reboot.
For those unfamiliar with the Amazon Dash, it’s a cute little widget for easy ordering of recurring essentials. Ted Benson’s Medium post inspired me to hack the button and use it for making calls instead of ordering Tide.
Step 1: The Dash Button
The first step is setting up your Amazon Dash Button. All you need is a smartphone (either an iPhone, an Android phone, or an Amazon Fire phone), the button, and your Wi-Fi network information (username and password). Excluding the last step of selecting your product, follow the instructions Amazon provides for you. I repeat, do not complete the last step of choosing the product. This will prevent the dash button from placing the order and palettes of Tide from piling up on your doorstep. Simply exit out of the app instead; you have given the dash button the Wi-Fi information it needs.
Step 2: The Raspberry Pi
The Raspberry Pi doesn’t come with an OS pre-installed, the easiest one to install is the Rasbian OS. If you’re reusing an existing raspberry pi you can continue forward with whatever OS you have.
The easiest way to step up Raspbian OS is using the NOOBS installer. The guys who made the Raspberry Pi have a great write up on it.
Step 3: The Scapy Sniffer
A quick bit of background on the Amazon Dash: in order to conserve battery the Amazon Dash Button only turns on when pushed. Upon starting up, the button attempts to connect to the Wi-Fi network specified during its setup. The first step of attempting to connect to the network is sending out an ARP Probe. What we’re going to do now is sniff the Wi-Fi network for those messages.
For this step, you’ll need to install the Scapy library. Follow the instructions on the Scapy website.
Our first step in sniffing the Wi-Fi network is obtaining the MAC address of the Amazon Dash Button, because you don’t want register a button-press every time your friend comes over and connects to your Wi-Fi. Make a new text file called “SmallMACs.py” in your Desktop and copy and paste this code. Now open up your command line and type in “cd Desktop” and “python SmallMacs.py”, which runs the python script looking for the MAC address. Then press the button. In a few seconds your commandline should respond with “ARP Probe from” and then a string of numbers and letters separated into pairs by colons. That’s your button’s MAC address.
Now that you have your button’s MAC address, you can copy and paste this code into a file in your Desktop called “BigMACs.py” (Make sure to modify it by replacing “RE:PL:AC:E_:TH:IS” with the MAC address you just acquired.)
In your command line, and type in “sudo python BigMACs.py” (this will run the Python script we . Press the button and wait; the command line should respond with "My BigMACs bring all the boys to the yard". If it instead responds with "My BigMACs weren't big enough" try running the script and pressing the button a few more times, sometimes the timing just isn’t right.
Step 4: The Twilio Call
So now every time we press the button, while the script is running, we get a message printed on the commandline. Pretty cool, but let’s step it up a notch with Twilio.
Twilio is an online service which allows you to automatically make calls to verified numbers from the web for free. Sign up for an account, verify the number you wish to receive calls on, and track down your AccountSID and AuthToken. You’ll need them in a minute. Also be sure to follow Twilio’s instructions for downloading the twilio-python library ( https://www.twilio.com/docs/quickstart/python/devenvironment ); you’ll need it.
Next you’ll want to create a new file on your Desktop named “CallMeMaybe.py”. Into that file paste the code you find here. Be sure to edit your AccountSID, AuthToken, phone number you wish to call, and the phone number Twilio assigned to you into the code.
Test to make sure this works by typing “sudo python CallMeMaybe.py” into your commandline and verify thatyou get a call. If you don’t, open the file again and make sure that you have your AccountSID and AuthToken properly copied, that you have verified the number you wish to call with Twilio, and that your phone is on.
Now you’ll want to go back and edit the BigMACs.py file and replace “print "My BigMACs bring all the boys to the yard"” with the code in your CallMeMaybe.py file. This way, instead of printing “My BigMACs bring all the boys to the yard” when the sniffer has detected your button push, it will instead contact the Twilio server to give you a call.
Now run BigMACs in your commandline again, press the button, and make sure that you get a call. If it doesn’t work, try running BigMACs again and pressing the button at a different interval; timing is key.
Step 5: The Supervisord Refresher
At this point you can send a call by running a script and pushing the button. Which is great, except you can make your life even easier by not having to manually run the sniffer script every time you want to press the button. That’s where supervisord comes in.
Launch this script by typing “sudo supervisord -c supervisord.conf” into your commandline. To make sure that supervisord is up, navigate to 127.0.0.1:9002 in your browser. Then simply click the button; you should receive a call (allow for some delay time; supervisord has a set refresh rate).
Step 6: The Auto Launch
Plugging a Raspberry Pi into a monitor and keyboard can be annoying, so let’s have supervisord start up our sniffer every time the Raspberry Pi is plugged in.
Paste the enclosed code into a file named “catapult.sh”.
Next you make the launcher script executable by typing “chmod 755 catapult.sh” into your commandline. The command “sh catapult.sh” should now launch supervisord.conf.
Then we want to use crontab, which allows you to execute scripts at a specified time. In this case, the time we want to specify is at startup. Simply type “sudo crontab -e” in the command line and press enter. This should pull up the crontab window. Once you see the crontab window, enter “@reboot sh /home/pi/Desktop/catapult.sh &”.
Lets break down the command:
- The “@reboot” represents that we want our file to launch at reboot;
- the “sh” command tells the Pi which program to use to launch the script;
- /home/pi/Desktop/catapult.sh clarifies the path that the Pi needs to follow to get to the file that we want to launch at startup;
- “&” allows the boot up to continue as normally planned.
The final test is to reboot your Pi (type “sudo reboot” into your commandline), wait for the Pi to finish starting up, and then press your button. You should now get a call.
Step 7: Conclusion: and That's It!
You now have your very own phone calling button, which you can set up anywhere in your house. Make sure you put the Pi somewhere where it can connect to your home network, and then simply press the button whenever you need to find you phone.
If you have any questions, bugs, issues, concerns, or other comments please shoot me an email at email@example.com. Thank you for reading and let me know what awesome things you build.
We have a be nice policy.
Please be positive and constructive.