wifiPresence

I run two WRT54Gs that can take the Tomato firmware. Tomato includes a web server with some nice web pages (one screenshot), and they happen to do a lot of their rendering in your browser. This means the pages either contain or fetch more pages containing JSON data.

To gather the wifi users around my house, therefore, I just do simple web page fetches with restkit and pull out the JSON. My source code is here. It's about 30 lines too long because of the way I share some of my configuration between this system and my web security system. The communication to the routers is in getPresentMacAddrs:

def getPresentMacAddrs(routers):
    addrs = [] # (addr, signalStrength, name)
    macName = {}
    for router in routers:
        data = router.get().body
        for (name, ip, mac, lease) in jsValue(data, 'dhcpd_lease'):
            macName[mac] = name
        for _, mac, signal in jsValue(data, 'wldev'):
            addrs.append((mac, signal, macName.get(mac, None)))
    return addrs

I stick any changes in who's around in a mongodb store for display on my web dashboard and for future data mining. I'm not currently using the signal strength numbers, but it would be neat if I had enough APs to estimate where someone was. Changes are also broadcast to an announcement system that plays entrance music and speaks the device names.