sudo /bin/date

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.

No comments:

Post a Comment