Making Amazon Dash Buttons Useful: By building a doorbell!

March 02, 2018 0 Comments

JSFeeds - Making Amazon Dash Buttons Useful: By building a doorbell!

 

 

A few years ago Amazon came out with the Amazon Dash Button, a small internet connected button that can be used to reorder common household items. Such a small, cheap and well-made internet connected button seems like a godsend for the IOT developer community – but they are not intended for use outside of product ordering. Amazon did release an IOT version of the Dash button, but at 4 times the price point it’s less attractive.

Could we intercept the network requests from Dash buttons and trigger our own custom events? An IOT doorbell, office coffee emergency button… That’s the challenge we set ourselves.

Connect the Dash Button to WiFi

Open up your Amazon app on IOS or Android, turn on Bluetooth and add the device. Be sure to quit the process once it’s connected to the internet but before you select a specific product!

Now your button is online.
Getting the MAC address of the button

The Dash Button is asleep most of the time, meaning when you press the button it must connect to the LAN over WiFi and then send its API request. Therefore it needs to acquire an IP address.

On an IPv4 network, Dynamic Host Configuration Protocol (DHCP) is used to get an address, and this process includes an Address Resolution Protocol (ARP) request. Our plan is to place a Raspberry Pi device on the LAN to watch for such ARP requests from our Dash buttons, allowing us to then trigger actions.

From our laptop on the same network, we can watch broadcast packets on the network using tcpdump.To watch for ARP request packets we can run:

tcpdump -ve arp | awk '{print $2} 

(on Mac)

  • the -v option gives us a verbose output
  • the -e option displays the MAC addresses
  • the awk script prints out just the MAC address column.

There will likely be many busy devices cluttering up your network so run this, press the dash button, wait 30 seconds and then look at the list of MAC addresses captured.

Part of the MAC address specification includes the manufacturers ID so we can go to an online tool such as macvendors.com and lookup each of the addresses we found. The one that has the manufacturer as Amazon Technologies Inc. is what you’re looking for. Make a note of the address in question, and if you’re looking to setup multiple devices use the same process.

If you have other Amazon devices on your network this process may take more trial and error.

Triggering an action

We can write a short bash script, using a similar approach to above, that will trigger an action whenever the button is pressed.

#!/bin/bash button='ENTER_THE_MAC_ADDRESS' tcpdump -l -n -i en0 | while read b; do if echo $b | grep -q $button ; then echo "Trigger Action" fi done 
  • button is the MAC address from the step above
  • tcpdump is passed an interface using the -i option. en0 or eth0 will likely work for you, but use ifconfig to find you LAN ethernet interface.
  • We’re piping into a while loop to get around some issues with evaluating our post grep action.

We can now trigger any action based on the pressing of the button. This could be an SMS using Twilio, an email, voice announcement using espeak, an AWS Lambda function… the world’s your limit!

Making a doorbell

If we want our doorbell to drop us an SMS we can sign up for Twilio’s programmable SMS service.

Then we can adapt our script to include a curl request as follows:

#!/bin/bash button='ENTER_THE_MAC_ADDRESS' tcpdump -l -n -i en0 | while read b; do if echo $b | grep -q $button ; then curl 'https://api.twilio.com/2010-04-01/Accounts/$YOUR_ACCOUNT_ID/Messages.json' -X POST \ --data-urlencode 'To=$YOUR_PHONE_NUMBER' \ --data-urlencode 'From=$YOUR_TWILLIO_PHONE_NUMBER' \ --data-urlencode 'Body=Let Me In! ' \ -u $YOUR_ACCOUNT_ID:$YOUR_TWILLIO_API_KEY echo "There is someone at the door" | say fi done 
  • $YOUR_ACCOUNT_ID you can get from the Twilio site.
  • $YOUR_PHONE_NUMBER is the number of the phone to be texted when the doorbell is rung.
  • $YOUR_TWILLIO_PHONE_NUMBER is the phone number given to you by Twilio.
  • $ YOUR_TWILLIO_API_KEY you can get from the Twilio site.

The Twilio getting started console can help you build such a request body.

Deploying to the Raspberry Pi

Pro Tip: You’ll have better performance regarding latency and reliability with a direct ethernet connection to the LAN router.

Resin.io is an amazing tool when it comes to IOT provisioning. Follow my steps in the article, ‘IOT Provisioning As A Service”, I wrote the day before the hackathon on setting up a Raspberry Pi without the headache. The next steps will assume you’re using resin.io with the docker image from that article.

Edit the Dockerfile.template to install tcpdump and curl by adding the following lines:

RUN apt-get update RUN apt-get install tcpdump curl 

Now change the run line at the bottom of the template to CMD [“./main.sh”] where “main.sh” is the name of the script.

We can now git add and commit to the master branch, and git push to your remote resin repository as discussed in the article from above.

On the resin.io dashboard we can watch the deployment and debug any issues (e.g. the interface name eth0 or en0 is wrong for the Pi environment).

Press the button…

And…

Get several notifying text messages.

Dealing with multiple notifications

Several ARP requests can be received when the button is pressed due to the nature of the DHCP handshake. You can use a sleeping period to prevent such issues, but for this proof of concept the repeats are fine for now. (Keep an eye on this space)

Getting chatty

Taking the concept further we can connect our Raspberry Pi to a speaker and use the espeak library to trigger text to speech notifications.

Once again edit the Dockerfiler.template to add:

'RUN apt-get install espeak' 

Now we can add the following to the main.sh:

'echo "There is someone at the door" | espeak -v en-sc -a 200' 

Coffee time ☕️

Taking the idea to another level let’s build a “coffee emergency button”.
In our office when the coffee runs out, it’s a big problem…

No coffee => slow devs => bad code. 

We’re going to build an internet connected coffee emergency button that will go on top of the emergency coffee tin, sending an audio alert to the office and a text message to the coffee buyer.

To do this we need to add another MAC address to our script for the new button and change our main.sh file as follows:

tcpdump -l -n -i en0 | while read b; do if echo $b | grep -q $button ; then curl 'https://api.twilio.com/2010-04-01/Accounts/$YOUR_ACCOUNT_ID/Messages.json' -X POST \ --data-urlencode 'To=$YOUR_PHONE_NUMBER' \ --data-urlencode 'From=$YOUR_TWILLIO_PHONE_NUMBER' \ --data-urlencode 'Body=Let Me In! ' \ -u $YOUR_ACCOUNT_ID:$YOUR_TWILLIO_API_KEY echo "There is someone at the door" | say fi if echo $b | grep -q $coffee_button ; then curl 'https://api.twilio.com/2010-04-01/Accounts/$YOUR_ACCOUNT_ID/Messages.json' -X POST \ --data-urlencode 'To=$YOUR_PHONE_NUMBER' \ --data-urlencode 'From=$YOUR_TWILLIO_PHONE_NUMBER' \ --data-urlencode 'Body=ORDER COFFEE ☕️' \ -u $YOUR_ACCOUNT_ID:$YOUR_TWILLIO_API_KEY echo "POTENTIAL COFFEE EMERGENCY AVERTED, BUYER NOTIFIED." | say echo "That was a close one." | say fi done 

Conclusion

This solution was built during a Theodo Hackathon and has room for improvement, yet it does serve as a fully functional doorbell in our office and we’ve not run out of coffee since!

Hopefully you learned some networking, have ideas for your own projects and will build your own buttons.

Please leave your ideas and results in the comments below.

The post Making Amazon Dash Buttons Useful: By building a doorbell! appeared first on Theodo.


Tag cloud