├── .gitignore ├── README.md ├── detect-button.py ├── distance.py └── text.py /.gitignore: -------------------------------------------------------------------------------- 1 | __pycache__ 2 | keys.py 3 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | A python 3 script to detect an Amazon Dash Button press and send a text message containing an arrival time. Uses Google Maps distance matrix to calculate travel time between two locations and Twilio to send the text. Works with the newer Dash Button model JK29LP. 2 | 3 | https://media.giphy.com/media/l1J9ReoGVd2BaUKxa/giphy.gif 4 | 5 | ### Steps 6 | 7 | #### Find the MAC address 8 | 9 | 1. Press and hold the Dash Button for about 5 seconds (the light will pulse blue) 10 | 2. Connect to the SSID 'Amazon ConfigureMe' with any device 11 | 3. Navigate to http://192.168.0.1 and copy down the MAC address 12 | 13 | #### Set up the Dash Button 14 | 15 | 1. Install the Amazon app on any device 16 | 2. Open the app and go to Your Account > Dash Buttons & Devices 17 | 3. Follow the instructions to connect the button to your network 18 | 4. Don't select a product for the button, just quit the app 19 | 20 | Now if you press the button it will connect to the network but since you haven't selected a product it won't order anything. You will get a notification on your device every time you press the button prompting you to finish setting up your button. If you really hate this you can go into your router and blacklist the buttons MAC address so that it never actually connects to the internet, thereby preventing notifications being triggered. 21 | 22 | #### Set up your Raspberry Pi 23 | 24 | 1. Connect your pi to the router via ethernet cable. Wifi is not reliable enough to detect the ARP requests from the button. 25 | 2. Clone this repo 26 | 27 | #### Set up the script 28 | 29 | 1. `pip3 install scapy-python3 googlemaps twilio` 30 | 2. `touch keys.py` 31 | 3. Add your API keys to keys.py like so: 32 | ```python 33 | mac_address = "xx:xx:xx:xx" # add the mac address of your dash button in lower case 34 | maps_key = 'XXXXX' 35 | twilio_keys = { 36 | 'account' : 'XXXXX', 37 | 'token' : 'XXXXX', 38 | 'recipient' : '+12345678900', # recipient's phone number formatted like so 39 | 'twilio_phone' : '+19876543210', # the phone number twilio gives you 40 | } 41 | ``` 42 | 4. `python3 detect-button.py` 43 | 5. Press the button! 44 | 45 | You'll likely need to run the script as root. You also might need to `apt-get install tcpdump`. On my Raspberry Pi I had to update some existing packages to fix some conflicts, but that will vary. 46 | -------------------------------------------------------------------------------- /detect-button.py: -------------------------------------------------------------------------------- 1 | from scapy.all import * 2 | from keys import * 3 | from distance import get_travel_time 4 | from text import send_text 5 | import math 6 | import datetime 7 | 8 | def get_times(): 9 | travel_time = get_travel_time() 10 | now = datetime.datetime.now() 11 | arrival = now + datetime.timedelta(seconds = travel_time) 12 | return datetime.datetime.strftime(arrival, '%I:%M %p') #formats to 06:30 PM 13 | 14 | def arp_display(pkt): 15 | if pkt[ARP].op == 1: 16 | if pkt[ARP].hwsrc == mac_address: 17 | print ('dash button pressed!') 18 | send_text(get_times()) 19 | 20 | print (sniff(prn=arp_display, filter='arp', store=0, count=0)) 21 | -------------------------------------------------------------------------------- /distance.py: -------------------------------------------------------------------------------- 1 | import googlemaps 2 | from datetime import datetime 3 | from keys import maps_key 4 | 5 | def get_travel_time(): 6 | gmaps = googlemaps.Client(key=maps_key) 7 | matrix_response = gmaps.distance_matrix('Provo, Utah', 'Salt Lake City, Utah') 8 | return matrix_response['rows'][0]['elements'][0]['duration']['value'] 9 | -------------------------------------------------------------------------------- /text.py: -------------------------------------------------------------------------------- 1 | from twilio.rest import Client 2 | from keys import twilio_keys 3 | 4 | def send_text(time): 5 | text_body = "Leaving work now. I'll be home at " + str(time) 6 | client = Client(twilio_keys['account'], twilio_keys['token']) 7 | message = client.messages.create(to=twilio_keys['recipient'], from_=twilio_keys['twilio_phone'], body=text_body) 8 | print('Message Sent: ' + text_body) 9 | --------------------------------------------------------------------------------