« »

Making light of the situation (virtual hosting)

php7XUKfW

I like it when people come over. Apparently in New York, you don’t just drop by someone’s house, not like you do in Shanghai at least. Everything here requires several weeks worth of planning, confirming, and elaborate bad wine bringing. I miss having people drop in for dinner or at least to talk for a bit. So I built myself a virtual hosting setup.

Now, this isn’t virtual hosting in any sort of technical sense. I’ve simply realized that people drop in on me unannounced all the time on the web. Looking through my server logs, I can see that people stop by all the time, and even though at least five percent of the time it appears they’re trying to hack my site, I’d still like for them to stay a while, to make themselves at home.

To this end, I repurposed the setup of my L.A.M.P. project to turn on a light and a radio any time my site has a visitor.

Here’s what it looks like (minus radio):


Before I get into a technical discussion, I wanted to note the pure visceral effect of having the light and the radio turn on when I’m sitting at home, reading quietly in the living room with a mug of soup. Because if I’m home and it’s not the middle of the night, that’s probably what is happening as you read this. It doesn’t exactly feel like a physical presence—it’s more like the feeling of unexpectedly receiving a letter from a really good friend or hearing the sounds of breakfast being made on a Sunday morning from your bedroom. It’s like the shadow of a presence rather than the presence itself. You don’t feel alone but neither do you feel like someone has invaded your personal space. After the first couple of times, once you’ve grown used to it and the startle wears off, it’s reassuring, almost warming, not feelings I’ve ever associated with my website before!

This conversion from virtual to real, from web to real world is a powerful and compelling trope of interactive design. It is a tangible interface, like where the surface of the ocean meets the air, one that is generally impermeable but one where it’s fun to play. People have become accustomed to weightlessness in cyberspace and these sorts of projects remind them of gravity. One of my favorite projects in this vein is Jonah Brucker-Cohen’s Alerting Infrastructure, a web hit counter that works by activating a drill that damages the foundations of a building every time someone visits a website. A sufficient volume of visits could in theory bring the building down!

Hollywood took this idea to its (il)logical extreme in 2008’s Untraceable, a film in which Diane Lane hunts a killer who connects his victims to a live web feed so that each hit on the site accelerates their demise—we are the murderers!

It should be noted in passing that this movie rivals the sublime technical absurdity of the fine collection of films/tv shows featured here:

How it works

flow chart

Though it is probably going to sound complicated, the basic setup is pretty easy (see the sketch at the top of this post for a diagram). The lamp and radio are plugged into an outlet just like this one, which is in turn connected to an Arduino and Ethernet shield. The Arduino queries a remote php script over the web about once every two seconds (the latency of the relay that turns the outlet on and off is close to one second, so there’s not much point in querying more frequently). The php script checks the first column of a single-row, two-column MySQL database that stores the state of the system (on or off) and a timestamp indicating when it was last updated. It then translates the response (0 or 1) into on or off.

But how does the MySQL database know when someone is visiting my website, I hear you ask? That was the tricky part. My initial impulse was to use the onUnload method in Javascript, until I realized that would mean that each separate page a visitor viewed would count as a visit. Chris Sung suggested a brilliant alternative: having a Javascript on each page in my domain hit a php script that records a timestamp every half second or so. Each time the php script runs, it first checks the last timestamp. If the last timestamp and the most recent timestamp are within a couple of seconds of each other, then there’s obviously someone viewing my page and the script will change the state of the system from off to on in the database. If not, then it simply replaces the last timestamp with the newest and leaves the system status off. This method has the added benefit of only triggering the light/radio in response to human visits. Because search engine robots and most spiders scrape the site rather than loading it in a browser, the Javascript is never executed!

Just for fun, I also added a TextMark that allows me to check if someone is home even when I’m not by texting “anybodyhome” to 41411 and a dashboard (pictured at the top of the post) to quickly check the visitor statistic that most matters to me as a host—the length of each visit.

Comments

Comments are closed.