Wednesday, May 5, 2010

Finally: Code!

After several hours of updating my code with comments and/or getting things more sensible in my code I've finally got some code for the Interwebs to gobble up. My code isn't the best in the world, and it's still very much a work in progress, but I wanted to give back to the community that helped me so much. Although I just realized that I didn't put any licensing information in my code I'll just say here that I'm providing it free to the community - as in open source (unless I've mistakenly and unwittingly borrowed someone else's code that has a restriction, in which case let me know and I'll do my best to fix it immediately!). It'd be nice if you would let me know if you've used it and how. It'd also be nice if you gave me attribution if you distribute anything based on my code.

My Processing code is what I spent the most time on and what came mostly from my head, rather than copy/paste from other sources. The Arduino code is more stale than my Processing code too since it "just works".

Both sketches are quite customized to my specific situation, with lots of hard-coded values for my temperature probes, names, etc. But I think it should be fairly easy to identify those customized parts and change them to suit your needs. The images of my house that Processing draws to are obviously also very specific to my needs but you should be able to create your own in any way you see fit.

And in case it matters I'm doing all of this development on a Mac, so some things may differ if you're on Windows or Linux. I know that I have a Serial port "auto selector" bit of code that will definitely not work in Windows without a tweak or two. I also save my images to my web server path that's surely different that yours will be. Other than that I'm not sure what differences there may be, so watch out and feel free to let me know what I could do to make this more cross platform.

So here's my code:

I think I failed to mention in my code that my Processing sketch originally was a client/server configuration. The server side took in the Serial data from the Arduino, wrote it to logs and sent it out to the client sketch than graphed it. I've since altered things so that the server sketch does the logging AND the graphing. But I still have code in there for the client that isn't being used right now since the client hasn't been rewritten to understand this new code properly. The server makes smaller iPhone size graphs and the client did a 3x bigger graph where every pixel represented a minute (width=time). I may or may not continue along this path. Right now I've found that my lower resolution graphs are just fine. I setup a Dashboard widget to show each graph image I create then host on my web server - so a key press pops open the dashboard where I can see everything at a glance. And the iPhone web app works great when I'm away from my computer. (But my iPhone doesn't have cell service now, so I just use it over WiFi. But my web server is public so the web app should theoretically work anywhere.) I'll post my web app too when it's less ugly.

So download my sketches and please let me know what you like or dislike. I hope it helps someone out there!