'ESP8266 Clock DST '*********************************************************************** 'My new NTP code w/Automatic Daylight Saving Time (this works) (12/07/2016) '*********************************************************************** memclear baudrate 9600 debug = 0 '0 = operational code , 1 = debug mode decsec = 0 counter = 0 timesetup(-5,0) 'eastern time zone delay 3000 serialtimeout 100 '.1 seconds timeout gosub [gettime] button "Exit ", [Exit] Timer 1000, [incsec] '1.0 second ticks wait ' '******************************************************************** [incsec] counter = counter + 1 'increment timer serialinput picin 'grab any serial data if available picin = mid(picin,1,5) 'decipher the string if picin == "Time?" then gosub [gettime] 'REQUEST FOR TIME FROM NIXIE CLOCK if debug = 1 then decsec = decsec + 1 if decsec = 10 then decsec = 0 serialprint "." 'tel'em we are doing something every 10 seconds end if endif if counter > 599 then gosub [gettime] 'AUTOMATIC updates @ 10 minute intervals serialflush 'FLUSH SERIAL INPUT BUFFER wait ' '******************************************************************** [gettime] counter = 0 'reset AUTOMATIC timer if debug = 1 then serialprintln 'finish the line of period's tstr = time() 'grab the actual time dy = mid(tstr,1,3) 'dowk 'decipher the string mh = mid(tstr,5,3) 'month dd = mid(tstr,9,2) 'date hh = mid(tstr,12,2) 'hour mm = mid(tstr,15,2) 'min ss = mid(tstr,18,2) 'sec yr = mid(tstr,21,4) 'year ' if dy == "Sun" then dowk = 1 'decipher the day of week if dy == "Mon" then dowk = 2 if dy == "Tue" then dowk = 3 if dy == "Wed" then dowk = 4 if dy == "Thu" then dowk = 5 if dy == "Fri" then dowk = 6 if dy == "Sat" then dowk = 7 ' if mh == "Jan" then mnth = 1 'decipher the month if mh == "Feb" then mnth = 2 if mh == "Mar" then mnth = 3 if mh == "Apr" then mnth = 4 if mh == "May" then mnth = 5 if mh == "Jun" then mnth = 6 if mh == "Jul" then mnth = 7 if mh == "Aug" then mnth = 8 if mh == "Sep" then mnth = 9 if mh == "Oct" then mnth = 10 if mh == "Nov" then mnth = 11 if mh == "Dec" then mnth = 12 ' '================================================ '--- DST Calc (dec1 dow,dec2 mth,dec2 date) --- '================================================ dst = 1 'covers Apr, May, Jun, Jul, Aug, Sep, Oct If mnth < 3 then dst = 0 'Jan,Feb ' 'March: when to spring ahead if mnth == 3 and dd < 8 then dst=0 if mnth == 3 and dd > 7 and dd < 15 and dowk == 1 and hh < 2 then dst=0 if mnth == 3 and dd == "08" and dowk > 1 then dst=0 if mnth == 3 and dd == "09" and dowk > 2 then dst=0 if mnth == 3 and dd == "10" and dowk > 3 then dst=0 if mnth == 3 and dd == "11" and dowk > 4 then dst=0 if mnth == 3 and dd == "12" and dowk > 5 then dst=0 if mnth == 3 and dd == "13" and dowk > 6 then dst=0 ' 'November: when to fall back if mnth == 11 and dd > 7 then dst=0 if mnth == 11 and dd < 8 and dowk == 1 and hh > 1 then dst=0 if mnth == 11 and dd == "02" and dowk < 3 then dst=0 if mnth == 11 and dd == "03" and dowk < 4 then dst=0 if mnth == 11 and dd == "04" and dowk < 5 then dst=0 if mnth == 11 and dd == "05" and dowk < 6 then dst=0 if mnth == 11 and dd == "06" and dowk < 7 then dst=0 ' if mnth == 12 then dst = 0 'Dec ' if dst == 1 then hh = hh + 1 'add the hour if hh == "24" then hh = 0 'check for rollover ' '******************************************************************** if debug = 0 then 'actual code to output string's to nixie clock circuit (TickTock2) serialprint hh 'set hours serialprintln "H" delay 100 serialprint mm 'set minutes serialprintln "M" delay 100 serialprint ss 'set seconds serialprintln "S" else 'output test message: day text/month text/date numeric/year numeric/hours:minutes:seconds picout = dy 'day of week text picout = picout & "/" picout = picout & mh 'month text picout = picout & "/" picout = picout & dd 'date numeric picout = picout & "/" picout = picout & yr 'year numeric picout = picout & "/" picout = picout & hh 'hours picout = picout & ":" picout = picout & mm 'minutes picout = picout & ":" picout = picout & ss 'seconds serialprintln picout end if ' return ' [Exit] end 'stop execution if requested