Wednesday, November 4, 2015

91: Daylight Savings Time for "Smart Controllers"
(and why you should study cron)

Clock time is important to my "live" Particle Photon system. Imagine my surprise in finding the time off by an hour on Nov. 1. Sloppy me. Particle Docs is explicit that the provided function does not adjust for Daylight Savings.

Lucky for me, I have a Linux/Raspberry Pi to back me up. Here's a little shell script that can correct the time in my Photon program:

photon=1234... # your Photon's ID
accessT=5678... # your access_token
a=`date | sed -n 's/.* .\([DS]T\).*/\1/p'`
if [ "$a" != "ST" ] ; # previous WAS "DT"
  v=-5  # Standard Time (hours less than GMT)
  v=-4  # Daylight Time
# This can tell the Photon 
curl$photon/$thisF \
 -d access_token=$accessT -d "args=$v"

Unix and Linux have a scheduling program called cron. And each user can have a personal set of scheduled programs accessed by the crontab app.. If the above shell code is in a file called "set-tz" then this crontab entry will execute it every Sunday in October, November and March:

# min hr dom mo dow command
0 3 * 3,10,11 0 sh set-tz

Read it as: 
"at zero minutes after the hour, 
any day-of-month, 
March, October, November, 
Then execute set-tz."

Ugly, but looks isn't everything.

No comments:

Post a Comment