At work, there’s a few Woot fanatics near my cube that get their panties in a tizzy when there’s a Woot-off, turning on their USB powered Woot lights getting all giddy. But why physically turn on the lights when this can happen automatically? When searching the interwebs, I came across Brett Inman’s blog which talked about his Arduino project which uses to Python to scrape a page and send an event to an Arduino with an ethernet shield. But why not just do this from a single device? This sounded like a perfect opportunity to utilize my Netduino Plus.
The Netduino Plus is a new beta version of the Netduino. The specs are the same as the original with the addition of onboard Ethernet and a micro-SD card slot. Given the richness of the .NET Micro Framework, it should be trivial to have the device itself scrape woot.com for the presence of the Woot off animated gif and then turn on the lights. This lead to a couple of challenges.
How to Feed 5v to the Woot Lights
Given that the Netduino pins only use 3.3v and can deal with a max of 8mA, how could I possibly drive the lights which require 5v and about 100mA? StackExchange to the rescue. After posting this question on electronics.stackexhange.com, I quickly got the answer I was looking for: logic-level N-channel MOSFET. Simply put, this is essentially a switch which doesn’t need much voltage as a trigger. Utilizing the 5v pin on the device itself and common ground, I can trigger a pin on the Netduino to close the connection on the gate.
How to Scrape a Web Page from the Device
Given the richness of the .NET Micro Framework, this proved to be pretty trivial. There are plenty of examples online and in MSDN for screen scraping. I’ll post my prototype code when I get a chance. But it’s as easy as:
HttpWebRequest hReq = (HttpWebRequest)WebRequest.Create("http://foo.com); HttpWebResponse hResp = (HttpWebResponse)hReq.GetResponse(); Stream webStream = hResp.GetResponseStream();
Those are the basics. Exactly as what you would do for the desktop.
So far, this is proving to be a lot easier than I thought it would be. I was able to play around with the MOSFET to turn the lights on an off from a signal on a pin. And the proof of concept code appears to correctly fetch and parse out the contents of a web page. I’m hoping to have a working end to end prototype this weekend (time permitting).