I’ve been working on a Python program today that monitors which application I’m using. For now it’s writing the data with a timestamp to a text file. But of course I want to share this data on numuseum. I’m now researching the use of sockets. As only just discovered that Flash can also work with sockets… That’s very interesting for me, I should be able to push life data to a Flash film. Wow!
Tag Archives: python
Win some, lose some
I’ve been working really hard the last weeks. I’ve started to develop the Flash web application. I started with the calendar part which gets all the different days from the database and presents a nice, scrollable and selectable list of days. The user can choose from which days she wants to see data. They are grouped by month and presented in a visual hierarchy. As you can hear I’m pretty happy with it and especially happy with how smooth the coding is going.
I must confess I’m very happy with ActionScript 3. What a robust language! Once you get the hang of it (and it is quite a difference from the first handful of methods and from AS1 too) it’s great to work with. So now I’m ready to start with Google maps and the projection of the data.

Design for the web application
Onto the part where I lost some… I’d already done quite some work on the communication between the Arduino and the Nokia. Except for the formatting I could receive data from the Arduino on my phone. As I needed to fill the database for my web app I tried running the old (working) scripts on my phone. I could make a Bluetooth connection but the communication didn’t work and I often got the message error(13, ‘Permission Denied’), a dreaded message which I thought I’d solved. So I tried installing a new version etc. No luck. As I’m running out of time for the presentation on the 19th I decided to fake the data so I could at least continue with my development.
So now I’ve manipulated the data from my collecting silence database. I wrote a Processing script which loops through all the lines of my database dump and creates new SQL queries from the existing data and writes them to a file. I could then import the queries and now I have a nice database on AQAb filled with almost 1000 rows of data. I do feel a little naughty but it’s the only way I can continue with my work at the moment. My knowledge of Python on mobile devices is too limited. And now I can’t even run the Scriptshell without errors, *sigh*
Oh yes, I’ve also done a video and photo shoot with Hans, my model. Pfff, filming is a true profession. I hope I’ll be able to make something presentable of the shots when editing. It’s a challenge to keep track of everything when you have to be director, producer and cameraperson at the same time.
I heart Python
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)

Data returned after inserted into 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.
Update 9-9-2009
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!
Python kick-off
Last week I did some research on Python for mobile devices. I was so enthusiastic about the documentation I found online and the apparent ease of the language that it was also clear to me what Smartphone I would buy. After quite some hesitation I decided to go for the Symbian based Nokia N97. It beat the i-Phone because I’m already used to Nokia, it has a real keyboard, a 5 mega pixel camera and it runs on Symbian. I found this great tutorial by one of the authors of ‘Mobile Python: Rapid prototyping of applications on the mobile platform.’ I haven’t bought it yet. I’ll see how far I can get without it as there is lots of info to be found online. They do have a chapter on interfacing with an Arduino board which isn’t in the code section. To get started you only need a simple text editor and the latest stable Python for S60 (Pys60) programs which you must upload to your phone. At this moment they are the Python_1.9.4.sis and PythonScriptShell_1.9.4_5thEd.sis as my phone runs on the latest, 5th edition of Symbian. They are not at the top of the maemo list so it took me a while to find out which versions I had to download. I installed them with my Nokia software. All I had to do was to write a little script:
import appuifw
appuifw.note(u"This works", "info")
For example and store it as a .py file. Upload it to my phone. Then go to the Pys60 program on my phone, run the script and see the following astonishing result ;-)
It works!
Even though the result is of course very simple a ‘Hello World’ script is quite rewarding because you know the routine of writing and uploading and you know your software is working correctly. I’m really looking forward to programming scripts on my phone because so much is possible. From databases to turning your phone into a server!

