Using Netduino to monitor Twitter
- Posted: Sep 19, 2011 at 6:00 AM
- 10,321 Views
- 1 Comment
Loading User Information from Channel 9
Something went wrong getting user information from Channel 9
Loading User Information from MSDN
Something went wrong getting user information from MSDN
Loading Visual Studio Achievements
Something went wrong getting the Visual Studio Achievements
This is a simple looking project, but it shows off a number of cool things, like adding networking to standard Netduino (not a Plus) and living with Twitter in the constrained world that is embedded device dev.
This blog post will introduce you to network communication with the Netduino. To demonstrate network connectivity I’ll have my Netduino make a request to the Twitter API to get a user’s last status update. Once the particular user I’m watching (the Netduino Team, of course) posts an update, the Netduino will let me know with a little blue LED. Sounds pretty simple, right?
The problem, of course, is that the regular Netduino lacks network connectivity as it has no Ethernet shield as does the Netduino Plus. At press time, the Netduino Plus is in high demand and is on back-order. What’s a geek to do? Borrow stuff from other geeks, obviously! I’ve borrowed a colleague’s Arduino Ethernet Shield and snapped it right on top of my Netduino, as you’ll see in this photo.
Given the fact that the original Netduino lacks support for the Arduino Ethernet Shield, drivers must be written or obtained to enable communication between the Netduino and the Ethernet Shield. Luckily some nice people from SecretLabs have put together some drivers for this and other Wiznet-compatible Ethernet shields. You can download a Visual Studio 2010 project containing the code for this communication on the Netduino forums site.
The difficult part of this code (in addition to losing the original version of it) is in that the Netduino has a much more limited amount of memory than does a typical computer. So, the grabbing of XML data, parsing it, and the rest of the process can cause the device some heartburn. One must use patience, but it is possible to make it work. The meat of the code just accesses the Twitter API to get a user’s status feed. Some specific querystring parameters are passed to the Twitter API, informing it that the client only wants one status update’s worth of information. Without this, Netduino tends to have memory problems, because it’ll download lots (and lots) of XML data from Twitter, run out of memory, and crash. After some testing and tinkering I found provision of the “count” parameter (and set to 1) as well as provision of the “trim_user” variable as set to 1 as well, results in the best behavior because the resulting XML data tends to be a much smaller payload. The IE screen shot to the left shows the XML output actually received from Twitter.
If you're thinking of adding some kind of Twitter integration in your next Netduino project, you should check this project out. It might save you a headache or two...
Here’s a few more links you might find interesting: