-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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