You are here

Time for the Raspberry Pi

I've been using a Raspberry Pi as a dashcam for a few days and the first problem I noticed was the time. Whenever it powered up it would reset back to the same time, resulting in overlapping data files for each startup!

2016-01-05 02-18-05.h264
2016-01-05 02-18-06.h264
2016-01-05 02-18-07.h264
2016-01-05 02-18-10.h264
2016-01-05 02-18-11.h264
2016-01-05 02-18-12.h264
2016-01-05 02-18-17.h264

As the Raspberry Pi doesn't have an RTC (Real time clock), it needs some way of preserving the time over restarts. For this purpose, there is a fake-hwclock package that saves the time on shutdown and reloads it on startup. While this won't give an accurate clock, it will cause the time to be sequential, resolving the overlapped time problem.

However... fake-hwclock only saves the time on soft shut down. In my scenario, there was no way to trigger a soft shutdown, so the dashcam was hard powered off each time, resulting in the time not being preserved and the next boot resetting back to last known time.

One way around this is to manually save the time periodically, e.g. through cron.
Adding this to your /etc/crontab saves the time every minute, reducing any potential overlap to 60 seconds.

* * * * * root fake-hwclock save

Eventually, my dashcam software will have GPS support allowing the time to be synced to that, but fake-hwclock will still help with the initial bootup time.