Friday, April 11, 2014

Getting Sensor Data online with Xively


I was able to recently prove the sensors for temp and moisture (using the SHT11 & DS18B20) worked well with my RPi setup. As I mentioned in the original plan, some early research indicated that uploading the recorded data to Xively would prove useful for later public web access, and help me avoid constructing my own database for the data. 

I'd like to make the weather station data publicity available for my fellow gardeners, but do not want any dependency on the sharing of the data on the RPi itself. In my setup using PPP for my remote radio I intend to have the remote put the data to Xively via my base stations physical network connection. So far, in local testing (around the house) it is working well. Below describes how I've got it working. (Referencing the great work of other.)

I'm not going to detail the steps to get an Xively feed setup, and data posted to it. I followed others tutorials online that did a better job than I'd do. The one provided by Xively itself ended up the basis for nearly all my feeds: https://xively.com/dev/tutorials/pi/, and for those looking for the nitty-gritty details, I'll save you tracking down the API:  http://xively.github.io/xively-python/, and the wrapper library itself: https://github.com/xively/xively-python   AdaFruit (as always) has a good follow-along tutorial that could also be referenced: https://learn.adafruit.com/connecting-the-max31855-thermocouple-amplifier-breakout-to-an-electric-imp/configure-the-agent-for-xively

Here are all my scripts for grabbing data, as well as the scripts for posting to Xively: https://github.com/geekskunk/remotegardensite/tree/master/garden_monitor Update your API and channel names accordingly if you borrow.

Pictured below and available here is my Xively Feed: https://xively.com/feeds/1824193320  I find this Xively page helpful for general use, but for a wider audience a more refined site is needed (and in the works.)



Now that I have the data steady flowing to Xively, I'll work next on visualizing the data in a more useful way on my one site. At the moment I'm considering: https://xively.com/dev/tutorials/channel-viz, as well as this https://jasonneylon.wordpress.com/2013/05/26/plotting-xively-timeseries-data-using-rickshaw/ Also for quick view of current values Google Gauges, like from this tutorial: http://www.sdyoung.com/home/home-status/how-i-visualize-the-sensors/jquery-and-json-enabled-google-gauges/

Until my site is up, here are a few quick pointers for pulling the Xively data. They are not interactive, but do provide an alternative the Xively site proper. I was tipped off on this simple approach from this site which extensively uses this method.

Actual html:

<img src=https://api.xively.com/v2/feeds/1824193320/datastreams/air_temp.png?w=800&h=200&c=2188c5&g=true&t=Last%2024Hrs%20Air%20Temperature%20History&b=true&duration=1day&scale=Datastream&timezone=-05&l=Internal%20Air%20Temperature%20%C2%B0F>

Template html:

<img src=https://api.xively.com/v2/feeds/INSERT_YOUR_FEED_ID_HERE/datastreams/CHANNEL_NAME.png?w=800&h=200&c=2188c5&g=true&t=INSERT_TITLE_HERE&b=true&duration=1day&scale=Datastream&timezone=-05&l=INSERT_YOUR_LABLE_HERE>


Example output:

For more API details (which apply to the image generation) check out: https://xively.com/dev/docs/api/data/read/single_datastream/




No comments:

Post a Comment