Today I wrote a script to keep the board’s time accurate, which works as follows:
- Uses service to pause ntpd to free up the NTP socket.
- Runs ntpdate with servers ntp.carleton.edu and time.nist.gov.
- Stores the exit code of ntpdate. If it failed, get system time from the hardware clock. If it succeeded, sync the hardware clock to new system time.
- Send an alert if unable to access hardware clock.
- Restart ntpd and exit.
This will be run hourly by cron at low priority, and by the script starting the program. This way, the hardware clock is always as correct as possible in case it must be used. The use of ntpd may cause a large discontinuity in system time, but these will be forced before the program begins to operate — the sync to hardware time will reduce this discontinuity to a easily manageable level unless the board has been running without internet for a week or longer, in which case (approximately) just one cycle’s worth of data per week of internet downtime will be disrupted when internet is restored. This would manifest simply as missing data from that cycle; the scheduler would rush the wait time between sending a Q to the PIC and requesting data with an S, and find nothing when it tried to read.
The primary benefit of this way of keeping time is that received data is guaranteed to be timestamped accurately to within a few seconds at the very most. Failure cases are massive internet downtime and RTC battery failure, both of which are reported to users. If the RTC battery dies and power/internet go down, and then power is restored without internet, there is no avoiding that timestamps will be off by however long power was down for. A feature to add if I finish everything else is smart tracking of this scenario — the python program knows if the RTC is accessible, and throws out data collected with no RTC or internet access.
Before that, however, I still have to:
- Test scheduling and startup.sh more fully.
- Write and test a DataOutputter class
- Write some more data converter objects as available
- Write Tom’s control panel
- Write documentation
–Soren