6

I use Motion detection and a webcam as a security camera. It's headless with no internet or keyboard. To turn the camera off while it's not need I just turn the power supply off. Because I shut it down this way the time doesn't get saved onto the SD card, which I think happens on a normal shutdown?, so when I boot it up next time the time it loads off the SD card is way back to the last time I ever shut the Pi down correctly. This makes the timestamps and file names of the images Motion is storing on my USB stick double/triple/quadruple up with previous recordings and it makes it hard to sort through and some files also get overwritten.

I am wanting to know a way where a script(the one that saves the time on normal shutdowns) saves the current time of the system every 10 minutes or so, so that if the Pi looses it power and turns back on, it will continue making recording from where it previously was(within 10 minutes)(might overwrite a few minutes worth).

11chubby11
  • 4,694
  • 5
  • 24
  • 31
  • 2
    Use a RTC it costs under 5USD/4GBP and will keep time for years or use the software called fake hardware clock. – Piotr Kula Nov 12 '13 at 20:43
  • Similar to https://raspberrypi.stackexchange.com/questions/1397/how-accurate-is-raspberry-pis-timekeeping – SDsolar Jun 20 '18 at 01:33

2 Answers2

5

Have a search on ebay for "i2c rtc"

enter image description hereenter image description here

There are plenty of very inexpensive ones based on the DS1307 battery included!

I've connected one of these previously, but I don't think I posted the code anywhere yet. I'll add it to this answer when I find it.

The other chip is an AT24C32 flash memory that you can ignore.

John La Rooy
  • 11,847
  • 9
  • 46
  • 74
3

You can install ntp and fake hardware clock

apt-get install ntp fake-hwclock

ntp will get the time when you have internet access and fake hardware clock will save time to the Pi every so often. After reboot or power cycle - if there is no internet fake clock will read the last time it save.

We dont want the Pi to crash at all and generally fake-hw clock is the best choice if you want to spend $0 :) But for a few "bucks" look at John La Rooy's answer for an external clock that will keep time for years.

Piotr Kula
  • 17,168
  • 6
  • 63
  • 103