Twittering computer grow box

image

Well this is pretty much clichéd nerdiness but given it only required a couple of lines of C# I couldn’t resist.  I have updated my grow box software to “tweet” some sort of semi-humorous and not really witty comment appropriate to its current state and share its current temperature and moisture content every 2.5 hours.

For those who want to do something similar, this is how I did it.  I one of the many twitter C# libraries and for no specific reason I chose tweetsharp and after adding a reference to their DLL and just the few lines of code (below) you can be programmatically making updates via twitter.

private void UpdateStatus(string message)
{
    IFluentTwitter twitter = FluentTwitter.CreateRequest();
    twitter.AuthenticateAs("user_name", "password");
    twitter.Statuses().Update(message);
    twitter.AsUrl();

    string response = twitter.Request();
}

If you want to see it in action go to http://twitter.com/computergrowbox.

Right now I only have a handful of not so witty comments, so if you have some good zingers add them to the comments and if I like them I will add them to the list.

UPDATE: Grow box shares its own pictures

I get busy these days and sometimes can’t make it out to keep a close eye on my plants in the grow box.  Given I have everything automated the box basically takes care of them, though I thought it would be nice if I could see how they are doing so added photo sharing to the grow box’s twittering software.

I already have the software taking pictures every so often so all I really needed to do what send out the most recent file to twitter.  After a little looking I found that tweetsharp already supported this so yet again this was just a few lines of code to implement.

First I needed the logic to determine the last photo I have taken, fortunately I was carefully about my naming using a timestamp based name similar to “Photo_2008_10_01_090130.jpg”, so alphabetical sorting would work just fine.  I removed the error handling to keep things brief but here is the code to complete this logic:

string[] files = Directory.GetFiles(photoDirectory, "*.jpg");
Array.Sort<string>(files);
string fileToUpload = files[files.Length - 1];

Now you have your photo to upload just signup for one of the photo TwitPic using your twitter account and run the following code using your credentials.

IFluentTwitter twitter = FluentTwitter.CreateRequest();
twitter.AuthenticateAs("user_name", "password");
twitter.Photos().PostPhoto(fileToUpload,
                      SendPhotoServiceProvider.TwitPic);
twitter.Statuses().Update("My Picture").AsJson().Request();

Hopefully this, you too can make you own grow box (or other inanimate object) share its feelings on twitter.

2 Responses to “Twittering computer grow box”

  1. Chiot's Run Says:

    This is too funny, when geeks get into gardening. I'm afraid Mr Chiots may be doing this someday if he gets any free time to get into gardening 🙂


  2. The Cheap Vegetable Gardener Says:

    Always have time to combine multiple passions


Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

%d bloggers like this:
IKE