Wednesday, February 5, 2014

Tweet, tweet!

I've relied heavily upon SSH to program and monitor the weather station, but that isn't a very elegant solution and isn't visible to anyone else. Moreover, I can't monitor the station (or even see the data) when I'm away from my home network.

I considered setting up a static IP address for the Pi and essentially having it act like a server, but I was afraid that the extra network traffic (both intended and unintended) could hamper the Pi's performance. I also thought of building a website where the Pi could send its data and then be viewed by anyone online, but I didn't want to pay for the domain, hosting services, etc. For now, I'd just rather have some 3rd party website manage and disseminate my data. That's where Twitter comes in.

I found Twython, which is a Python library for managing a Twitter account. It allows you to post text, pictures, and videos and probably do a bunch of other things that I didn't take time to learn about since I will be just posting text (maybe a webcam later though...).  I signed up for a new Twitter account so that I don't spam my current followers.  Twython requires you to set up a new Twitter application at dev.twitter.com and record the consumer and access keys in your script.  There is a good tutorial HERE. After that, you can compose a Tweet with a single Python command.

The tweet.py script that I wrote ingests the current conditions from current.txt and outputs them (nicely formatted) to Twitter.  It serve a few other functions like converting to Fahrenheit, calculating relative humidity, converting to sea-level pressure, and converting wind speeds from rpm to mph.  The script is run every 10 minutes with Cron.
Here's the output. "The View" is the name of my apartment complex. 
Note that the account has a new handle since this screenshot was taken.

Right now it just prints the one-minute average every 10 minutes, so Twitter is essentially ignoring 9 minutes worth of data. I might work to fix this and add 10-minute or 5-minute averages, but it works just fine for me for now.  

For those of you who are interested, my handle is @viewwx (click link for my profile).  I don't regularly check it, so it is still better to contact me via my personal account @aaronmangels.

3 comments:

  1. Not sure if this blog is still updated, but I'll comment anyway. I'm doing a very similar project right now (although I have much less experience in the programming field). I'm planning to use it in a location without internet, so I'm planning on outputting the data to a SQLite database. I'm also running a blog at www.piweather.wordpress.com, to try to document the project. Your project looks interesting, and hopefully some information on here will be of use to me. Thanks!

    ReplyDelete
    Replies
    1. I haven't updated it in quite some time, but I'm still around. I just haven't had time to work with my Pi very often--much less document it.

      I'd be happy to help with whatever issues you have and provide snippits of code. My programming experience isn't very extensive, but I was able to pull it off. I'm sure you can too.

      Delete
  2. very enjoyable blog, thanks for writing this!

    ReplyDelete