With the recent end of Daylight Savings time here, I took the opportunity to check the time in all my devices and get them set as accurately as possible.
As I noted in my Daylight Savings again! post, for a long time I’ve used Canon’s EOS Utility to set the time in my EOS cameras via USB cable in order to have them in sync with each other, the computer, and the time in my GPS trails. At the end of that post I commented “Sometimes I wish all my devices could sync their time from the computer!” So of course I set out to see if I was missing something…
And yes, it turns out I was. But be warned, the rest of this post is fairly geeky and technical!
My wife’s camera is a Canon PowerShot, as is the waterproof unit I use for snapshots in wild conditions (both of these cameras are using the CHDK software to save their photos as DNG RAW files). Until now I’d been setting their clocks by hand through their menus. I checked Canon’s CameraWindow software again (very roughly this is the PowerShot equivalent of EOS Utility) but although it provides the ability to set the OwnerName field, it doesn’t support setting the date/time.
So at that point I figured I’d fire up the gphoto2 application. This open source software is accessed via the commandline (on OS X this is via Terminal.app) but this is something I’m very familiar with. This software is available for Windows, OS X, and other Unix derivatives. Tobias Müller wrote about gphoto2 last year, particularly in the context of extracting the shutter count from EOS 7D cameras. Once it’s installed and the camera connected, with a 7D the following command returns the camera’s internal shutter counter:
gphoto2 --get-config /main/status/shuttercounter
But in the context of this post, the interesting command is something like:
gphoto2 --set-config /main/settings/datetime=133325706
That huge number on the end is meant to be the number of seconds since January 1, 1970 (the beginning of the “epoch” in Unix terms). Some web searching digs up a reference to using:
gphoto2 --set-config /main/settings/datetime=`date +%s`
Both of the PowerShot cameras here have the concept of “Home” and “World” timezones, allowing you to quickly switch timezones without having to re-set the hours/minutes/seconds detail. Each timezone has a daylight savings toggle, making it easier again. You could set the camera’s timezone to London, use the above gphoto2 command, and then switch it back to your local timezone. But I decided to take a more general approach. I wrote a tiny Perl script which I saved into the text file set_camtime. It’s a very rough-n-ready program: I could have used some external Perl libraries (“modules”) from CPAN, but tried to use only built-in functions.
#!/usr/bin/perl
open(OFF, 'date +%z|') || die;
my ($sign, $hours, $mins) = (< OFF> =~ /^(.)(..)(..)/);
my $offset = 60 * ($hours * 60 + $mins);
$offset = -$offset if ($sign eq '-');
my $t = time - $offset;
system("gphoto2 --set-config /main/settings/datetime=$t");
This gets the offset of whatever your computer’s local timezone is, and subtracts that from the UTC seconds count before sending it to the camera. It’s ugly but it works. I made the set_camtime file executable (chmod a+rx set_camtime) and moved it into the /usr/local/bin folder. So now the update procedure is:
- Make sure the timezone on my computer is correct for my current location.
- Make sure the timezone on the camera (if it has one) matches that.
- Connect the camera to the computer via USB.
- At the commandline, type set_camtime.
- Disconnect the camera and check the time. It should be correct to within a second.
This works for all the PowerShot (and EOS!) cameras I have access to.
I do also use a Panasonic DMC-G1 (a 12 Mp Micro-4/3 camera) modified for infrared photography. Unfortunately Panasonic do not provide any software to communicate to these cameras via USB, and although I can put the DMC-G1 into “PTP” mode and interface it with gphoto2, it doesn’t support the datetime settings and thus this capability is useless to me. I’m stuck with setting the time by hand, and have put the special Panasonic USB cable back in the box, never to be used again.
That’s enough geek code for now. Back to your regularly-scheduled programming…
You can also do gphoto2 –set-config syncdatetime=1
Unfortunately, with the Firmware update for the EOS 7D, Canon removed the /main/settings/datetime widget. I guess this has to do with the introduction of a time zone setting. Syncdatetime doesn’t work, too:
“The syncdatetime widget is not configurable.”
Shame. Whatever solution we find for the 7D with v2 firmware, I suspect the same will apply for the 5DmkIII. I’ll get back to this soon.