Pages

PiTime

sudo /bin/date MMddHHmmyy.ss


This post is about the one line command above and a proof that one can implement it in more than 500 lines of Java code!

Jokes aside, PiTime is an Android application that updates the time (more precisely the date) on the Raspberry Pi, using the phone as time reference.

There are situations when one needs the correct time on the Pi but there is no Internet connection. One use case is when doing timelapse photography with a headless Pi. If the timelapse movie needs to have a running timestamp in the corner then CreateDate in photo's Exif needs to be correct.



There are a number of ways to set the time:
  1. Connect to the Pi with any ssh client and set the date manually
  2. Use a hardware clock, e.g. Adafruit DS1307
  3. Connect the Pi to the Internet (via an USB tethered mobile phone for example) and force time sync on the Pi
With 1) one needs to simply type the date command above, but setting the time with accuracy is not easy. A hardware clock (2) seems ideal but one still needs to change the time when moving to a different timezone. Option 3) is the one I used so far: connect to the Pi with USB tethering, enable data roaming on the phone, set a route in the Pi to "see" the Internet, force time sync.

Under the hood PiTime sends just the above one line command to the Pi! In the contest "the-most-powerful-one-liner" PiTime would battle well for the last places. It was written as a way to refresh Java coding skills and come back to Android development. 

PiTime fills a real need though. I was using method 3) so far, enabling roaming on the phone and setting a route to let the Pi reach the NTP servers. Roaming for one day is £1.99 on O2 network, so PiTime saves you money for at least one coffee.

A big thanks to JSch authors (the Java SSH library), which is used to connect to the Pi.

The application is already mature enough, no big plans for he future, maybe adding Pi shutdown and reboot functionality. Timezone needs to be set as well. Incorrect timezone is no real showstopper though as Exif doesn't have a timezone field.

Raspberry Pi - Time-lapse video of London skyline

Photos takes on 20th December 2013 every 30 seconds and assembled in a movie at 25 frames per second. During windy days with faster cloud movement reducing the time to 10 seconds should give a more fluid video.



The quality of the photos is surprisingly good, considering the Pi camera is "very typical of the kinds of units you’d see in some mid-range camera phones" (http://www.raspberrypi.org/archives/3525). Had higher hopes on a Microsoft LifeCam Cinema HD webcam, but no, it took terrible shots. This was despite the enticing promise: "Relax while the camera automatically sharpens your images and TrueColor adjusts exposure for bright, vibrant footage. And for even sharper video, take advantage of the high-precision glass lens and ClearFrame Technology to improve the picture even in low light conditions". The Pi people were much more modest but delivered a good product.

Strange looking gear
By chance the first two books match the technology stack

Three books and the Pi on the window sill



Minimalistic Raspberry Pi-based Temperature Monitor

    A while ago I stumbled upon Tomas Holderness's Temperature Server. Beautiful usage of a number of off-the-shelf technologies: Node.js, Highcharts, SQLite. I fixed some minor issues, customized it to my taste, set it to sample the temperature every 30 seconds and let it run and run... As it accumulated data it took my smartphone longer and longer to load the page. Not only that, the charts are really usable on a bigger screen.

    I ended up with a frame with 2 pages, one that shows the graphs, the other the current temperature. The current temperature page is for the impatient, it loads in a snap.

    The implementation is under 100 lines of Python. Basically it is based on overriding the GET request handler with a custom one that reads the temperature, prepares and sends back the page. Initially I had the page written every half a minute to disk (huh, flash) by a separate process and the web server was the out the box one. Worrying about limited flash write cycles I ended up with this solution that doesn't touch the disk and queries the temperature on demand.

    Freebies: the page auto-refreshes every 30 seconds and provides alerts when the temperature is outside a desired range (added because the initial purpose was to monitor the temperature in our baby room).

    Code below. Just change the configuration as required (port and sensor output file) and fire the server.

    PS The original 2-piece implementation based on a separate program that writes the web page to disk and a web server suffered from race conditions (server may have read an incompletely written page and the auto-refresh would fall apart). This solution is more robust.