Latest Work...

Harry Potter Clock V1.2

I mentioned in one of the last posts about the clock that it ocasionally lost its GPRS connection after being moved to somewhere where the signal wasn't of brilliant quality. To try and remedy this I added an external antenna to the USB modem that was being used. This made very little difference, the clock would lose its connection and the only thing that could be done would be to 'turn it off and on again' - until the connection was lost again. Not ideal, time for a different approach. I had always wanted to replace the model B Raspberry Pi with the new Model A version, as because it lacked ethernet and what is basically an on board USB hub - its power consumption is claimed to be about a third of that of its bigger brother. This would be good for a number of reasons - mainly down to the fact that the voltage regulator on the circuit board always ran just a bit too hot for my liking! 

Above - The Raspi Model A, probably the easiest computer to set up I've ever used

Anyway, I'd originally inteded to use WiFi instead of GSM data - and so sent off for a WiFi dongle that was known to work with the Pi. After a brisk setup - everything seemed great. Huzzah!


Not so fast, like the GSM modem before it, it would appear that the WiFi dongle wasn't much more reliable. I left it pinging a php script once a minute for an hour, but I discovered that it was dropping out after about 15 minutes. Others have discovered this problem too, it looks like the adapter I had has some kind of problem with the firmware (either on the OS or on the hardware itself) that causes it to power down after some time regardless of activity and hence drop the connection. 

As you can see from the first picture - I thought it might be interesting to try and see if SMS would be a better way of controling the device. The GSM modem is after all basically a mobile phone - and so can recieve and send text messages. This way, a connection to a server doesn't have to be constant - so if the device loses signal, it will handle re-connecting to the phone network itself,  rather than rely on the operating system to dial up and set up a TCP/IP over PPP connection. I started looking around for how to achieve this, and discovered this set of tutorials for reading and sending SMS messages using AT commands. Even better, there's a Python Library for sending SMS messages! (There is a Python Library for everything). The tutorial given on the site is pretty straightforward, however I found that I had to make one modification to the installation: There are two ways of formatting data sent to the modem via AT Commands; SMS PDU and SMS Text. I'm not entirely sure of the ins and outs of each method (more info here). Anyway, I was planning on sending data in text format to make the code easier to read, so this needed to be communicate to the E160 which defaults to PDU mode. This is a bit of a hack, but I changed out the source code in /usr/lib/python2.6/site-packages/sms-0.4-py2.6.egg/__init__py by adding


right after the line in the __init__ for the Modem class. This seemed to do the trick!


The rest is easy - I don't have the code to hand, but basically the script is called, again via a cron job, to check if there are any text messages. If there are, then it deletes all of the ones (if any) that are not sent from mine or another approved phone (numbers can also be added by text) - and any remaining that have a command as shown in the above image are parsed by Python (which is practically what it is designed for) and send out the commands to the Arduino just like in the first version.

The SIM in the clock is a GIffGaff SIM, so replies back to my iPhone are free. Also, one neat thing I discovered - I was able to swap the SD card out of the first RasPi straight into the model A (after an apt-get update/upgrade on the Model B) and it worked straight away with no modifications. Impressive!

Anyway, this has proved to be a much more reliable way to run the clock, and a heckuva lot easier to update on the go, although does mean that without an SMS gateway (and hence £££), there's no way to do automatic geo-location updates from the web. What I would like to do however is make a dedicated bit of hardware to send the text messages from another modem. To do this I'm planning on using the Arduino and USB host shield...

<< Go back to the previous page