Skip to content

Instantly share code, notes, and snippets.

@hagope
Forked from courtsimas/dash-listen-3.py
Last active November 21, 2015 20:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hagope/c8b1a9594de359a2bb01 to your computer and use it in GitHub Desktop.
Save hagope/c8b1a9594de359a2bb01 to your computer and use it in GitHub Desktop.
listen on network for push of Amazon dash button; this version uses arp-scan instead of scapy
import subprocess
import requests
import time
import os,sys
MAGIC_FORM_URL = 'http://api.cloudstitch.io/...your_url'
def record_wake():
data = {
"Timestamp": time.strftime("%Y-%m-%d %H:%M"),
"Measurement": 'woke'
}
requests.post(MAGIC_FORM_URL, data)
def record_sleep():
data = {
"Timestamp": time.strftime("%Y-%m-%d %H:%M"),
"Measurement": 'sleep'
}
requests.post(MAGIC_FORM_URL, data)
red_btn = '14:35:18:91:30:68'
green_btn = '64:c8:46:4c:ad:a2'
buttons = [red_btn, green_btn]
sleep_time=15
while True:
for button in buttons:
cmd = ['arp-scan', '--interface=en0','10.0.1.0/24', '--retry=1', '-T', button]
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out, err = proc.communicate()
if red_btn in out:
print time.strftime("%Y-%m-%d %H:%M:%S") + ",wake"
record_wake()
time.sleep(sleep_time)
break
if green_btn in out:
print time.strftime("%Y-%m-%d %H:%M:%S") + ",sleep"
record_sleep()
time.sleep(sleep_time)
break
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment