If you’re like me you constantly lose your phone. And if you’re even more like me you’re constantly asking your friends to call your phone for you. And if you’re my long lost twin then you hacked yourself a solution using a Raspberry Pi and the new Amazon Dash Button. Now there’s a button in my kitchen, and whenever I need to find my phone I just press it and get a call.
For those that may not be familiar, the Amazon Dash Button is a cute little widget that Amazon released so that you can get everything from diapers to razors to mac n cheese delivered to your front door with the click of a button. Ted Benson’s brilliant Medium post inspired me to hack the button and put it to a better use.
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 is set up our Raspberry Pi so that when it detects an ARP Probe, Twilio will make a call to your phone. All you’ll need for this is a Raspberry Pi, an internet connection, and an Amazon Dash Button. I managed to simplify the process down to 6 easy steps:
- setting up the Amazon 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
- making your sniffer automatically refresh via supervisord
- getting your Raspberry Pi to automatically launch supervisord whenever it reboots.
Step 1: The Amazon Button
The first step is setting up your Amazon Dash Button. All you’ll need is a smartphone (either an iPhone, an Android phone, or an Amazon Fire phone), the button, and your Wi-Fi network information. Follow the instructions that Amazon provides for you BUT don’t complete the last step. That means don’t select any product to be ordered. Simply exit out of the app instead; the Wi-Fi information that your Dash Button needs will have been transferred, without the pesky disadvantage of piles and piles of Huggies Diapers piling up on your doorstep.
Step 2: The Raspberry Pi
The Raspberry Pi doesn’t come with an OS pre-installed, so you’ll want to install the Raspbian OS using the NOOBS installer. Thankfully, the guys that brought the Raspberry Pi have written a great, easy-to-follow setup guide.
Step 3: The Scapy Sniffer
For this step, you’ll need to install the Scapy library. Follow the instructions on the Scapy website and you’ll be good to go.
You don’t want register a button-press every time your friend comes over and connects to your Wi-Fi, so our first step in sniffing the Wi-Fi network is obtaining the MAC address of the Amazon Dash Button. Make a new text file called “SmallMACs.py” on the Desktop of your Raspberry Pi and copy and paste the following code into it:
Open up your command line and type in “cd Desktop” and “sudo python SmallMacs.py”. 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, copy and paste it into the following code:
and copy and paste that code into a file called “BigMACs.py”
(Make sure to modify it by replacing “RE:PL:AC:E_:TH:IS” with the MAC address you just acquired.)
Now open up command line, and type in “cd Desktop” and “sudo python BigMACs.py”. 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. You’ll need to install the twilio-python library.
Next you’ll want to create a new file named “CallMeMaybe.py”. Into that file paste the following code:
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 “python CallMeMaybe.py” into your commandline and see if you 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. Replace “print “My BigMACs bring all the boys to the yard”” with “import CallMeMaybe”. This way, instead of printing “My BigMACs bring all the boys to the yard” when the sniffer has detected your buttonpush, 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.
You’ll want to start by following the instructions for installing supervisord. Then copy and paste the following code into a new file called “supervisord.conf”:
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
When I was setting up my Raspberry Pi for the first time I was sprawled out on the floor of my living room; Pi hooked up to the TV via an HDMI, micro-USB connecting it to my laptop. But leaving the Pi in the living room indefinitely wasn’t an option; I needed to be able to plug it in anywhere in my house (without having to plug in a monitor, keyboard, and mouse into it) and let it run on its own. To do this, you need to configure your Pi to launch supervisord.conf on startup.
Paste the following 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 commandline and press enter. This should pull up the crontab window. Once you see the crontab window, enter “@reboot sh /home/pi/Desktop/catapult.sh >/home/pi/logs/cronlog 2>&1”.
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.
Conclusion: And That’s It!
You now have your very own phone finding 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, comments, or other potential applications of the Dash Button+Raspberry Pi combination, feel free to comment here or shoot me an email at firstname.lastname@example.org. Thanks for reading and have a great day!