Close

No RTC?

A project log for Off-Grid Garden Watering System

Solar powered watering system controlled with a Raspberry Pi to deliver an exact metered water volume to your garden plot, on schedule

scott-feldmanScott Feldman 09/03/2022 at 18:591 Comment

The Raspberry Pi does a great job keeping time as long as there is power.  After a power failure, the Raspberry Pi's time will not be correct.  Knowing the correct day/time is important for this project as the schedule determines when to turn on/off the system, so not having the correct time is a problem.

Two solutions come to mind:

  1. Add a $10 RTC (real time clock) hardware module to the Raspberry Pi to keep time in the event of a power failure.
  2. Use the first contact with a cell phone to set the time, from the cell phone's time.

The first option is easy but adds $10 to the system costs.

The second option works this way: After install, the Raspberry Pi comes up with some random day/time.  On first connection by a cell phone, push down the current day/time (from the cell phone) to the Raspberry PI.  As long as there is power, the Raspberry Pi will have the correct day/time.  The assumption here is the cell phone has the correct time, which is a reasonable assumption since most phones should have the correct time due to NTP.  In the event of a power failure (not likely since the system is off-grid and the battery/solar setup should keep the Raspberry Pi powered on 24/7), the Raspberry Pi's time will be messed up.  This means the watering schedule is messed up.  The system may water on the wrong day/times.  But, it will still water.  Once a cell phone reconnects to the system, the time will be corrected.

Discussions

Scott Feldman wrote 09/08/2022 at 01:20 point

I implemented option #2 and it works great.  The RPi time can be really off and the system doesn't care.  On first browser connect, the browser time and time zone is pushed down to the RPi.  With that info, we can calculate a time difference between browser time and RPi time, accounting for the browser's time zone location.  From this point on, the system does time math in the browser's time/zone reference.  Subsequent browser pushes of time and time zone are ignored.

  Are you sure? yes | no