Skip to content

Instantly share code, notes, and snippets.

@justinribeiro
Created July 25, 2013 02:36
Show Gist options
  • Save justinribeiro/6076466 to your computer and use it in GitHub Desktop.
Save justinribeiro/6076466 to your computer and use it in GitHub Desktop.
This is startup script that runs on dd-wrt, pings my local api end point, which bridges out to Mirror API and sends things to Glass. This is actually a really old script (I used to have this script doing other things), but it's basically a proximity hack (without the GPS). The Mirror API hook basically does location based things (house M2M tasks…
#
# Ping me when Glass connects / DD-WRT start up script
#
# Pings service on connect based on MAC, then pings endpoint which handles Glass talking
#
# Based on some older scripts that I was pretty sure used to be at http://www.dd-wrt.com/wiki/index.php/Script_Examples
# but for the life of me, I can't recall which ones
#
# Setup some devices based on MAC address
glassmac="00:00:00:00:00:00" # My Glass MAC
glassdev="justin-glass" # My device service name
glassstate=0 # defaults to not connected on startup, resets on loop
connected_wait=10
disconnected_wait=5
#run forever and ever and ever...and then stop. I'm kidding.
while true; do
# Get the Mac Address list currently connected
# JDR: swapping out wl for wl_atheros (no wl on WZR-HP-G300NH)
devicesmaclist=$(wl_atheros -i $(nvram get wl0_ifname) assoclist | cut -d" " -f2)
# check check
glassup=0;
# technically we could have multiple devices here...you could do different things
for devicemac in $devicesmaclist; do
case $devicemac in
"$glassmac") glassup=1
;;
esac
if [ $glassstate -ne $glassup ]; then
# ping the endpoint and do some things (ala, send me a bundle or a card to Glass)
wget -q http://services.xfiles.local/v2/devices/$glassdev/state/$glassup
fi
glassstate=$glassup;
# take a nap for longer checks if connected, otherwise check more often
if [ $glassstate -gt 0 ]
then
sleep $connected_wait
else
sleep $disconnected_wait
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment