0

timezone strange behavior
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

timezone strange behavior

by jdelcamp11 on Tue Aug 20, 2019 11:54 am

I am using the timezone library in many of my routine on the feather M0.
But it throws errors and won't compile the 1st time after loading a sketch.
If I comment out the two timezone sections it compiles.
I can then uncomment these two sections and it compiles and runs fine.
Since the workaround is good it is just an irritant, but confusing.
Any ideas?
Code: Select all | TOGGLE FULL SIZE
/* Feather MO
 * Using onboard RTC with set time from Nist server
 * includes timezone
 * To get this to work I have to comment out the two sections referencing
 * timezone, compile the program, then remove comment out and recompile
 * This happens every time I open the sketch
 * or copy the code into a different sketch *
 */
 
  //=================================================================
  //* remove leading "/" to compile first time - then put it back
  #include <Timezone.h>
     //US Central Time Zone (Chicago, Houston)
  TimeChangeRule usCDT = {"CDT", Second, dowSunday, Mar, 2, -300};
  TimeChangeRule usCST = {"CST", First, dowSunday, Nov, 2, -360};
  Timezone usCT(usCDT, usCST);
  TimeChangeRule *tcr;   // pointer to the time change rule
//*/
  //=================================================================

  #include <RTCZero.h>
  RTCZero rtc;
  String StartTime;
  char DateString[16];
  char TimeString[16];
    // unix time - actTime is current time, ClockSet is time RTC last was reset to NTP
  long actTime, ClockSet = 0;
  int DAY, lastDay = 0;
//  end of clock section   ****/

void setup() {
     //****  START RTC   *********
  rtc.begin();
  //getTime();  // from NIST  - commented out here for brevity
  StartTime=DateString; 
 }

void loop() {
  // put your main code here, to run repeatedly:
 }
 
void readClock()
 {
       int Year, Month, Day, Hour, Minute, Second;
  //=================================================================
  // remove leading "/" to compile first time - then put it back
  //* using timezone  remove leading "/" to compile first time - then put it back
       time_t localTime = usCT.toLocal(rtc.getEpoch(), &tcr);
       Month  = month(localTime);
       Day    = day(localTime);
       Year   = year(localTime);
       Hour   = hour(localTime);
       Minute = minute(localTime);
       Second = second(localTime);
       actTime=localTime;
       DAY = Day;
     //*/
  //=================================================================
     
    sprintf(DateString, "%4d%02d%02d%02d%02d%02d",
                Year, Month, Day, Hour, Minute, Second);
    sprintf(TimeString, "%02d%02d%02d",
                Hour, Minute, Second);
 }  // end of readClock  ****/

jdelcamp11
 
Posts: 155
Joined: Mon Nov 17, 2014 12:30 am

Please be positive and constructive with your questions and comments.