Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 7 of 7

Thread: Bugreport: Timelib

  1. #1
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany NRW
    Posts
    6,570

    Bugreport: Timelib

    output from a modified demo (code below)

    Code:
    10:04:58 1 1 2020
    10:04:59 1 1 2020
    10:05:00 1 1 2020
    20:21:30 28 1 2020
    20:21:31 28 1 2020
    20:21:32 28 1 2020
    20:21:33 28 1 2020
    This is reproducable on T3.2 and T3.6
    code:
    Code:
    /*
     * TimeRTC.pde
     * example code illustrating Time library with Real Time Clock.
     * 
     */
    
    #include <TimeLib.h>
    #include <Wire.h>
    
    
    time_t getTeensy3Time()
    {
      return Teensy3Clock.get();
    }
    
    void setup()  {
    
        setSyncProvider(getTeensy3Time);
      setTime(10, 0, 1, 1, 1, 2020); //set initial time
      
      Serial.begin(9600);
      while (!Serial) ; // wait until Arduino Serial Monitor opens
      //setSyncProvider(RTC.get);   // the function to get the time from the RTC
      if(timeStatus()!= timeSet) 
         Serial.println("Unable to sync with the RTC");
      else
         Serial.println("RTC has set the system time");      
    }
    
    void loop()
    {
      if (timeStatus() == timeSet) {
        digitalClockDisplay();
      } else {
        Serial.println("The time has not been set.  Please run the Time");
        Serial.println("TimeRTCSet example, or DS1307RTC SetTime example.");
        Serial.println();
        delay(4000);
      }
      delay(1000);
    }
    
    void digitalClockDisplay(){
      // digital clock display of the time
      Serial.print(hour());
      printDigits(minute());
      printDigits(second());
      Serial.print(" ");
      Serial.print(day());
      Serial.print(" ");
      Serial.print(month());
      Serial.print(" ");
      Serial.print(year()); 
      Serial.println(); 
    }
    
    void printDigits(int digits){
      // utility function for digital clock display: prints preceding colon and leading 0
      Serial.print(":");
      if(digits < 10)
        Serial.print('0');
      Serial.print(digits);
    }
    red lines are modified from the example.
    It happens after 5 minutes.
    Last edited by Frank B; 01-28-2020 at 07:42 PM.

  2. #2
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany NRW
    Posts
    6,570
    ..it happens after the syncinterval :
    line 40:
    static uint32_t syncInterval = 300; // time sync will be attempted after this many seconds

    ..which is 5 minutes exactly

  3. #3
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany NRW
    Posts
    6,570
    ok, turns out this it not easy solvable.
    setTime(10, 0, 1, 1, 1, 2020); //set initial time
    does not set the rtc.time, because it does not know how. the automatic sync again does not know this and reads the rtc time. again. therefore the time will be wrong.

    Best is:
    - not to use the timelib
    - or not to use setTime()
    - or use
    Teensy3Clock.set()

    I guess this is solved as any change to timelib would be incompatible to arduino.
    Last edited by Frank B; 01-28-2020 at 08:50 PM.

  4. #4
    Senior Member oddson's Avatar
    Join Date
    Feb 2013
    Location
    Isle in the Salish Sea
    Posts
    1,326
    When it hits the sync interval it syncs!?
    That's a bug??

  5. #5
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany NRW
    Posts
    6,570
    it does ignore setTime then. It should calculate with offsets - but it doesn't, obvoiusly.

    Edit: any doing so would lead to other problems regarding usability (user: "hey, i've set the time and switched off - after restart the time is wrong")
    So best is "don't fix".
    Or set the rtc time somehow. That needs a new callback. This is incompatible. (The lib is quite old... maybe newer versions are better?)
    Last edited by Frank B; 01-28-2020 at 09:04 PM.

  6. #6
    Senior Member oddson's Avatar
    Join Date
    Feb 2013
    Location
    Isle in the Salish Sea
    Posts
    1,326
    So the bug is the set command is not setting Teensy3Clock?

  7. #7
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany NRW
    Posts
    6,570
    see Post #5

    setTime doesn't make any sense. if does not know how to set rtc it at least should use an offset. as it is , it is senseless because at first sync the user-set time is gone.

    good night

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •