2012/03/08

Pachube on Adafruit's IoT Printer

I've been meaning to check out pachube for a while now and it seemed like fiddling with Adafruit's Internet of Things Printer was a perfect chance.  The JSON parsing code from the Gutenbird sketch lent itself nicely to tweaking for the pachube datastream JSON feed.  Pachube was also very easy to get up and running with between the developer documentation, easy API key generation, and each feed page having buttons to see the various formats (XML, CSV,  JSON).  The end result is that I can get a print out of air quality data for Boston:
(https://pachube.com/feeds/23716 - "Air Quality Index and pollutant data for Boston, Massachusetts webscraped from http://www.airnow.gov/. AIRNow observational data are not fully verified or validated; these data are subject to change and should be considered preliminary. If observational data are used for analyses, displayed on web pages, or used for other programs or products, the analysis results, displays, or products must indicate that these data are preliminary.")

It's still definitely a work in progress - I'd like to format the dates a bit and there seems to be an intermittent bug with the fetch/parse process.  Nonetheless, I've put the code up on github for anyone interested in playing around with it.  There are a couple section of code that I think are a bit interesting.

Adding the pachube API key is as simple as setting one additional header in the HTTP request.
The pachube feed does contain a last updated field for the feed; unfortunately, it is the last field in the feed.  I wanted to stick with (for lack of a better term) the SAX style parsing of the JSON that the original Gutenbird sketch uses rather than do a DOM style load of the data.  Each entry does have a timestamp, but I was looking for something that would tell me when the feed as a whole had been updated.

I ended up looking at the HTTP response header for Last-Modified (I'm considering whether to refactor the code to just store a hash of the value since I'm only using it to decided whether to print the feed or not).  If the value has changed, I save it and return true to indicate the feed should be printed.
Looking through the pachube API feed, the structuring of the interesting data is close enough to the twitter feed that reusing the Gutenbird parsing code made a lot of sense to me.  As an aside, Jenkins build feeds seem to follow this same "object which contains a single array of interesting shallow objects" (JSON-SAISO anyone? no?):
It took me a couple reads to understand the original code from Gutenbird; but, once I grokked it, I think it's a really elegant approach.  It's looking in the JSON for a given name, which will have an array as the value.  When in each object, it looks for specific names and saves the values. Finally, at the end of each object, it handles the data for that object.

I tweaked it as below for the name/value pairs I'm interested in (and I'm using a callback function for printing).  Again, very few modifications were needed to switch from parsing twitter to parsing pachube.
I'm curious to see what data feeds other IoT owners will find interesting.  I'm guessing that as time passes, there'll be more and more sketches available to track different data.

[Updated]
Welcome Adafruit and Flickr readers - here's a little bonus content :)

The same feed as above, but with swanky outlining:

And the relevant code changes to printEntryToPrinter :


And setup :

2012/03/03

Arduino NG upgrade

I've updated my Arduino NG by adding auto reset and an Atmega328P chip; it definitely breathed new life into an old board that was just gathering dust.  The Atmega328P from Adafruit was a direct swap as advertised.  While the main Arduino site's hacking section has instructions on adding auto-reset by soldering on a 0.1uF capacitor, many people have had better luck using the two upper pins.  A good overview of the difference is presented in this wiki entry (the short form is that it depends on how your Arduino IDE / computer handles DTR and RTS when opening a serial connection).  OSX 10.6 / Arduino 1.0 seems fine with the upper pins.  I now have an Arduino NG capable of running an Ethernet Shield and an LCD Shield (and I don't need to pry off shields to upload new code) for about 7 dollars.


2012/02/26

Weather Ticker Using Adafruit's Internet of Things Printer

We built the Adafruit Internet of Things Printer last week and, after playing around with it a bit, we settled on tracking a twitter feed of local weather (this has lent itself to all sorts of jokey comments about it not really being whatever outside until the twitter feed through the printer confirms it).

However, it also turns out to be a surprisingly clever UI.  We correlated people getting headaches with the barometric pressure changing over the weekend.  Could we see this by looking at the twitter feed on a computer?  Sure - but we've never tracked the weather that way before.  There's something very natural feeling about a length of paper with points in time along it (blame it on growing up with timelines in classrooms).

2012/02/22

Graphing Vivarium Humidity and Temperature Using RRDTool

The temperature and humidity monitoring of my vivarium is really coming together.  I'm recording a timestamp, humidity, and temperature to an SD card every minute using Adafruit Industries' SD card breakout board:
Components on breadboard

The SD card is sneaker netted to a computer running RRDtool and used to produce graphs to give a sense of how the environment looks across the day.  The temperature nicely lines up with what I'd expect given the way the thermostat on the house heating is set up:
24 Hours of Temperature Data

2012/02/12

Tracking Humidity and Temperature with an Arduino

Having added a realtime clock to my Boarduino, I'm now on to measuring the humidity and temperature inside the vivarium.  This iteration displays the current reading along with the time on the LCD.  Eventually, I plan to capture the data so I can graph how these are changing over the course of the day.

Masdevallia with AM2302 Temperature / Humidity Sensor
Incremental Bill of Materials
New to this step is a temperature / humidity sensor from Adafruit Industries.  I went with the AM2302 since I think the DHT22 will give a reasonable amount of accuracy and I liked the larger plastic housing.  I did end up soldering a scrap length of CAT5 cable to the sensor's wires to make the wires long enough to get out of the vivarium to the board.

Description Cost
AM2302 (Wired DHT22) Temperature-Humidity Sensor $15.00
(The full bill of materials is provided at the end of this post)

Wiring
Components with Logical Connections

  1. The AM2302 runs on 5V along with the LCD and RTC.
  2. The ground line is connected to common ground.
  3. The data line is connected to digital pin 2 on the Boarduino.

Code
Initial setup of the sensor involves creating a new DHT object and passing in the data pin and sensor type as parameters.
Each pass through the loop, read the values from the sensor. The sensor only produces readings every two seconds, so this might be better reduced to only reading every 5 seconds or some other arbitrary interval.
Full source code is available on github:
https://github.com/dmalec/Project-Masdev/tree/master/masdev_temp_humid

LCD Showing Time, Humidity, & Temperature
Full Bill of Materials
Description Cost
AM2302 (Wired DHT22) Temperature-Humidity Sensor $15.00
Boarduino $17.50
FTDI To USB Adapter $14.75
16x2 LCD $9.95
LCD Backpack $10.00
Real Time Clock (DS1307) $9.00
12V 6A Power Supply $8.62
Total $84.82


The next step is recording the temperature and humidity readings to an SD card and graphing the data using RRDTool.

2012/02/01

Building an Arduino LCD Clock

The first step in my Arduino monitored / controlled orchid vivarium is giving my Arduino the ability to track time with reasonable accuracy and display information on an LCD.  I went with a Boarduino for ease of prototyping, but the final build will probably use an Uno or Mega.

Components as built on a breadboard
Bill of Materials
A lot of my supplies were bought from Adafruit Industries.  I've been very pleased with everything I've ordered from them and the tutorials/instructions are excellent.  I bought an LCD power supply on Amazon because eventually I'll want to run 12V computer case fans.

Description Cost
Boarduino $17.50
FTDI To USB Adapter $14.75
16x2 LCD $9.95
LCD Backpack $10.00
Real Time Clock (DS1307) $9.00
12V 6A Power Supply $8.62
Total $69.82

Wiring
Components with logical connections 

  1. The 5V pin of the Boarduino is connected to the 5v pin of the DS1307 breakout and the 5v terminal of the LCD backpack.
  2. The ground pin of the Boarduino is connected to the ground pin of the DS1307 breakout and the ground terminal of the LCD backpack.
  3. The A4 pin of the Boarduino is connected to the SDA pin of the DS1307 breakout and the DAT terminal of the LCD backpack.
  4. The A5 pin of the Boarduino is connected to the SCL pin of the DS1307 breakout and the CLK terminal of the LCD backpack.

Code
I've created a github repo to track the project in general:
https://github.com/dmalec/Project-Masdev

The sketch specific to the LCD RTC clock is available here:
https://github.com/dmalec/Project-Masdev/tree/master/masdev_lcd_clock

Clock pictured mid second change

The next step is adding a temperature and humidity sensor to the circuit and replacing the banner output with those readings.

Forcing an Editor Resize During a GXT EditorGrid Resize

We were having some issues with GXT's EditorGrid during resizes.  If a user was actively editing, then started resizing the grid, the cell editor remained at the original location instead of moving along with the grid cell.  There may be better solutions, but the one I came up with is adding a resize listener that forces the editor to realign to the new cell location, like so: