|
# samliu@'s Amazon Button Doorbell! |
|
# |
|
# OS X only. Uses AppleScript to play a track from Spotify and "say" tts to |
|
# inform you that someone's at the door. You should have Spotify installed. |
|
# |
|
# Based on example from: http://bit.ly/1WFAPAb |
|
|
|
# Your Button's MAC Address. |
|
BUTTON1_MAC_ADDRESS = "00:00:00:00:00:00" |
|
|
|
# Your name(s). |
|
NAMES = "Sam and Shanu" |
|
|
|
# This is "Knock Knock - Mac Miller" |
|
# Please suggest better doorbell songs... |
|
DOORBELL_SONG = "spotify:track:3uYm4MtU6jUQft2DtGqEoZ" |
|
|
|
# requirements.txt: scapy, pypcap, dnet |
|
from datetime import datetime |
|
from scapy.all import * |
|
import os |
|
|
|
def play_spotify_track(track_id): |
|
cmd = '''osascript -e 'tell application "Spotify"' -e 'play track "''' + \ |
|
track_id + '''"' -e "end tell"''' |
|
os.system(cmd) |
|
|
|
|
|
def arp_display(pkt): |
|
# who-has. |
|
if pkt[ARP].op == 1: |
|
# ARP Probe. |
|
if pkt[ARP].psrc == '0.0.0.0': |
|
if pkt[ARP].hwsrc == BUTTON1_MAC_ADDRESS: |
|
print "Someone's at the door! " + str(datetime.now()) |
|
play_spotify_track(DOORBELL_SONG) |
|
os.system('say "Hello ' + NAMES + ', someone is at the door!"') |
|
os.system('sleep 2') |
|
os.system('say "Did you get the door? Get the door!"') |
|
os.system('sleep 4') |
|
os.system('say "Welcome to our home!"') |
|
print "Hopefully you got the door. Waiting for next ring...\n" |
|
else: |
|
print "ARP Probe from unknown device: " + pkt[ARP].hwsrc |
|
|
|
if __name__ == "__main__": |
|
print "Listening for doorbell..." |
|
print sniff(prn=arp_display, filter="arp", store=0, count=0) |