Archive for the 'Understanding Networks' Category


Web app screen shot

I like word games, I won’t lie, so I was pretty chuffed when I came up with the idea of creating a lamp that runs LAMP (Linux, Apache, MySQL, and PHP—one of the predominant acronyms behind the scenes on the web, both because of its robustness and its appealing freeness).

Puns aside, the idea is simple: I wanted to give people (especially strangers) remote control over a physical object in my house. My initial goal was to implement a RESTful interface for as many different channels of user interaction as possible, and to that end, I built a PHP script that will accept input from as many sources as I could think of and a single web front-end that displays the results.



1) Scenario: You're in my house
     Use the light switch!

2) Scenario: You're on the internet
    -Run the Processing sketch that
      allows you to switch the light.
    -Use the web interface directly.
    -Send dengdengalex[at]gmail an
     email with 0, 1, or 2 in the body.
          0 turns the light off,
          1 turns the light on,
          2 tells you the light's status

3) Scenario: You're on a mobile device
     -Send an email as above.
     -Text "alexlight" followed by a:
          0 to turn the light off,
          1 to turn the light on,
          2 to get the light's status

Following this fabulous tutorial, I built an Arduino-controllable power outlet. Though I chose a lamp, the system can accommodate anything that can be controlled either with an on/off switch or a relay.

There is a php script that is triggered every couple of seconds by the Arduino which records the state of the switch connected to the outlet and another script that changes that state when it receives input (via web, text message, Processing, or email) and displays the state information on a web page. The final script runs in the background on the server polling for new email.

There are a couple of little fixes that I probably won’t get around to but I will mention so I won’t forget them, the most significant being the meta refresh method I’m currently using to check for the light’s status on the web page. I know I could call a php script in the background using AJAX, I just haven’t figured out how yet, so in the interim, I’m reloading the whole page every two seconds. Because it’s so small, the user probably won’t notice, at least not until his browser crashes.

The other major problem is email. There’s a bit of a lag. If it weren’t for my sucky hosting company, I’d be able to run a cron job on the server to check for new email every five seconds or so, but my host limits me to running jobs every fifteen minutes or on a specific minute of each hour. I tried several workarounds (putting fifteen minutes-worth of looping in the script so that it runs the entire time before it is next called => crashed the server; adding the same job 60 times, one for each minute => the server ends up synchronizing the jobs and calling about a quarter of them every fifteen minutes).

How Data Gets to Asia

Asian Crossing (Click to enlarge)
Asian Data Routes Visualization (Click to enlarge)

Regardless of where I start, it always takes me forever to get to Asia, though given a choice, I prefer flying overland from Western Europe. Data packets seem to make the same trip pretty effortlessly, so I was curious to see what route they take.

I selected thirty Asian websites and traced the route the data took from my computer in New York to get to them using’s handy traceroute script (I’m behind an NYU firewall that makes tracerouting pretty difficult). The results were pretty crappy. Half the time, the trace timed out before it even reached Asia.

Show/hide raw traceroute data

I ended up using this nifty visual traceroute tool which uses Google maps to plot an approximate route to figure out how packets got from here to there. I discovered a number of interesting things:

  • Most data heads to China from the Los Angeles area, though interestingly enough, Baidu always seems to go through Mexico. I’m guessing this has something to do with the wires it favors.
  • The latency between hops once the data reaches China jumps from between 4 and 40ms to well over 200ms (an effect of the Great Firewall, I assume).
  • Because of this, most data that is bound for Asian destinations other than China tends to avoid China, with the notable exception of SK Telecom’s website which is routed through Suide, a Chinese city I’d never heard of.
  • The majority of the data lines belong either to Verizon or to AT&T, though there are other providers, such as Cogentco also pop up occasionally.
  • Many of the Indian and Vietnamese sites I looked up are hosted in the US so they didn’t make it onto my visualization.
  • Traceroutes are not all that reliable.

Interesting stuff. I’ll do the same exercise from Shanghai the next time I’m in China just for comparison’s sake.

Painting Pong


For my networked pong game controller, I thought I’d have a go at using an accelerometer and a paint roller. Instinctively, everyone knows how to use a roller, so it seemed like a natural interface for a paddle that moves either up and down or left and right. I initially thought I was going to be using the accelerometer to measure movement. Turns out that accelerometers only measure movement with respect to gravity, which makes them kind of sucky for anything but determining orientation in space. Plan B was to use a photo sensor, an LED, and some black tape to make a rotary encoder.


To get my encoder working, I counted the transitions from light to dark and dark to light and timed them, figuring that the longer of the two would represent the larger piece of tape and thus tell me which direction we were moving in. It sort of works.

The Arduino Code

I need to sit on this for a while. I'm sure there are plenty of documented ways of doing this (Tom Gerhardt used this method with his awesome spinning plates synthesizer) but I sort of want to figure it out on my own. I can easily get the orientation of the roller using the accelerometer but I might not be able to get the direction of its rolling using the method I'm using. Some sort of rotary switch attached along the actual axis of rotation would probably do the trick. I like the idea of doing it with light, though, so I'm going to keep on thinking about this, though I may give in to the Google soon.