Sunday, January 29, 2012

Step Six: Getting Started with Google App Engine

In order to store all this useful data with minimal thinking about databases etc. Google App Engine is an easy choice.


Warning:

I hope that this post illustrates how using only 2-3 dozen lines of code, we have a 'free' web-based datastore for this project. What follows is a primer for future posts where we will tie everything together.


Google App Engine will allow us to easily handle the Arduino's requests, store data, and let us retrieve data to display in a web browser.


To get started with Google App Engine you can sign up at: appengine.google.com.


For the purposes of this blog/tutorial, I will assume that you have some working knowledge of App Engine, that you can gain by working through the python tutorial.


If you are very technical, hopefully you can likely stich together a working app using this blog and source code provided alone (without completing the tutorial).


Once you are up and running with the App Engine Launcher and have created your first application, it's quite simple to log data.


The Model:

Since database reads / writes are limited (and we want to keep within App Engine's free-quota limits), storing a day of entries in a single string will be a hacky-effective solution.

I am also storing the date as a unix timestamp integer to remove some complexity of working with timestamps when it's time to graph them.


Defining an API:
Quite simply, the Arduino will pass a temperature and humidity value. Our Google App Engine application will receive these values, and record them to the database. An example request might look like:
myproject.appspot.com/t=7205&h=4302 which represents an entry of 72.05 degrees F and 43.02% humidity. Timestamp isn't required because that is handled server side.



Handling Requests from the Arduino:
The following code is heavily commented, and all records are formatted to be super-friendly to use with Flot (javascript based graphing library) in future posts.

The above code will be used to handle requests made from the Arduino. Note the use of the X-Arduino-Data header. This will be used for debugging the Arduino sketch.


Displaying Posts:
This code will be used to handle requests from the browser in order to display our temperature/humidity records from the datastore:



Confused? Probably. We'll be pulling everything together in the next post(s).


TLDR;

In order to proceed you need a Google App Engine account and basic understanding of App Engine. We can make use of Google App Engine using only 2-3 dozen lines of code. The next few posts will bring everything together.

No comments:

Post a Comment