I’m continuing my quest for my mobile app. It’s at the heart of sharing the data I capture with my sensors. After I’ve started the program it should:
Connect to the Arduino board very n minutes (2 for example)
Arduino should start the sensors
wait for a few seconds (they need heating up)
loop through pins a, b, c, d (NO2, CO, O3, temperature)
check smell flag
turn of the sensors
Loop through the Arduino values
Store them as a Python dictionary
Get the latitude and longitude from the internal GPS
Store them in the same dictionary
Connect to the internet
Post the dictionary content to a PHP script (which writes them into a database)
I’m relieved that I’ve made some progress. Yesterday I made a connection to internet and posted variables to a (very basic) PHP script. Today figured out the elegant data type called dictionary. http://docs.python.org/tutorial/datastructures.html#dictionaries It’s a kind of array but you can store key:value pairs. So they’re ideal for creating POST variables to send to a PHP script and very easy and flexible to build. I build a little air quality table that stores all the sensor data, date and time and whether or not the smell was nice at the time of the measurement (more about that some other time). Once I’d manage to store all the values in the database it was time to look for code to read out the GPS values. I came across this great tutorial with a tiny bit of code. http://www.scribd.com/doc/8981028/Tutorial-PythonForS60 Enough for what I need.
Of course the code will have to include error handling. The next step is connecting to the Arduino.
After working with the program for a bit it’s clear that it sometimes takes quite some time for the GPS values to be found. Earlier I had a field in my database table which would insert the data and time at the moment the data was posted. This may very well not be the time the air quality is measured so now I use the phone time which I can also read and format easily with two lines of Python code. Love that language!