Menu

Time Display Format

Matt
2020-07-10
2020-12-22
  • Matt

    Matt - 2020-07-10

    Hi Robert,
    Thanks for taking the time and effort with the projects you've created.
    I'm really enjoying tinkering with the Arduino projects. (I'm also building the dew controller)

    I have a suggestion for the GPS project,
    I noticed it displays the time in UTC format,
    so I added a few lines in the OLED code to display "UTC":

    sprintf( mytime, "Time: %02d:%02d:%02d", GPS.hour, GPS.minute, GPS.seconds);
    sprintf( mydate, "Date: %02d/%02d/%04d", GPS.day, GPS.month, GPS.year + 2000);
    myoled.clear();
    myoled.println(mydate);
    myoled.print(mytime);
    myoled.println(" UTC");

    However I'm thinking it would be great if you could change a variable for your own timezone, so that the time is displayed (on the oled) in local format.
    So you could have a variable as timezone offset ( eg: +8 , or +10) and it would then display the time locally.
    and maybe also have a variable for 12/24hr mode.

    Would this affect the serial output to ASCOM?
    I'm guessing it expects to see the time in UTC format.

    edit: After some research it looks like a libary could be included to implement this.
    The library also caters for daylight savings changes
    https://github.com/JChristensen/Timezone

     

    Last edit: Matt 2020-07-13
  • brownrb

    brownrb - 2020-07-13

    Hi Matt

    The GPS project was a simple device to input GPS data into something like EQMOD or Astroplanner. It was never my intent to make it into something bigger.

    As the GPS provides "GPS" data to other programs, the xpectation is that wille be UTC, as that is what is output by all GPS systems.

    In terms of "Loc" not that simple. I had looked at Timezone mentioned by your post sometime ago.

    To do this correctly is is not just time zone offset but also DLS settings as well.

    The newer mySQM+ project does all of this and more, using NTP, GPS and RTC code.

    However, the code is all here and anyone can make changes and add/delete what they want. I really do not plan on making any changes to the GPS code.

    Kind regards
    Robert

     
  • brownrb

    brownrb - 2020-07-13

    In answer to

    Would this affect the serial output to ASCOM?
    Not a good idea as it would break other apps I currently use
    I'm guessing it expects to see the time in UTC format.
    yes it does

     

    Last edit: brownrb 2020-07-13
  • Matt

    Matt - 2020-07-29

    Hi Robert

    Thanks for the valuable feedback.
    I can appreciate that you have time invested in many other projects. : )

    I spent some time on this ( mostly for my own learning purposes )
    and was able to implement the library from
    https://github.com/JChristensen/Timezone

    The way I set it up means the local timezone can easily be changed.

    ( It's a bit like Cisco config
    clock timezone AEST 10 0
    clock summer-time ADST recurring 1 Sun Oct 2:00 1 Sun Apr 3:00
    )

    // myLocal Time Zone
    TimeChangeRule mySTD = {"AEST", First, Sun, Apr, 3, 600};   // UTC + 10 hours
    TimeChangeRule myDST = {"AEDT", First, Sun, Oct, 2, 660};    // UTC + 11 hours
    Timezone myTZ(myDST, mySTD);
    

    The oled display now has a second line like this:

        Time:00:00:00 UTC
                    :00:00:00 AEST
    

    I have also attached image of display, (with GPS coordinates blacked out)
    ( moved 'Fix' and 'Quality' to the same bottom line of the oled screen )

    With the library the timezone label AEST should automatically change to ADST when DST takes effect (1st Sunday in October at 2am)
    I also configured it so it only calculates the local time when a GPS fix is detected.

    None of this affects the serial NMEA output,
    only the OLED display and I kept the time format as 24hr time for simplicity.

    Happy to share the rest of the code in case anyone else would like this.

    (NB: I'm a bit of a newbie with arduino coding so please let me know if my coding can be improved on.)

    I'll be using this to feed into my APT software using a Skywatcher EQ6r via EQMod

    Thanks again

    Matt

     

    Last edit: Matt 2020-07-29
  • brownrb

    brownrb - 2020-07-29

    Hi Matt
    I will take a look and thank you for you efforts
    I use the GPS as is in UTC to feed into EQMOD and it handles things just fine.
    So I did not see a need to impleement a LOC time but ys that might be useful on the OLED display.

    I will get back after taking a look at the code.
    Cheers
    Robert

     
  • Matt

    Matt - 2020-07-30

    Thanks Robert,
    I'll include my code here for reference.
    I'm sure you'll be able to improve on it, this is just what I added to get it working.

    Matt

    #include <Timezone.h>   // https://github.com/JChristensen/Timezone
    #include <TimeLib.h>    // https://github.com/PaulStoffregen/Time
    
    // my Time Zone - users only need change this section
    TimeChangeRule mySTD = {"AEST", First, Sun, Apr, 3, 600};   // UTC + 10 hours - standard time starts 'first' 'Sunday' 'April' at '3am' 10hrs = 600min
    TimeChangeRule myDST = {"AEDT", First, Sun, Oct, 2, 660};    // UTC + 11 hours - daylight time starts 'first' 'Sunday' 'Oct' at '2am' 11hrs = 660min
    Timezone myTZ(myDST, mySTD);
    
    TimeChangeRule *tcr;  // pointer to the time change rule, use to get timezone abbrev eg: AEST/AEDT - I used this for the oled display
    
    char localTime[] = "00000000";      // used by sprintf to format local timezone displays (this could be improved on as it will display 0's until updated)
    
    
    // this is where I added the section to get the gps time, then send to the timezone library to calculate the local time
    // this could be improved on or relocated
    // ideally detect when GPS has valid time - only needs one satellite 
    // I've seen GPS not have a fix, but still have valid date/time
    
      if ( GPS.fix != 1 )
        myoled.Display_Inverse();  
      else
        myoled.Display_Normal();
        setTime(GPS.hour, GPS.minute, GPS.seconds, GPS.day, GPS.month, GPS.year + 2000);   //set the arduino time to GPS (hr,min,sec,day,mnth,yr)
        time_t tzutc = now();
        time_t tzlocal = myTZ.toLocal(tzutc, &tcr); // call the library to convert to my timezone
        sprintf(localTime, "%02d:%02d:%02d", hour(tzlocal), minute(tzlocal), second(tzlocal));  // format local time from conversion
    
    
    // added this section for oled to display UTC and myTimezone
    
      // section to display GPS UTC time
      myoled.print(mytime);
      myoled.println(" UTC");  // added UTC label
    
      // section to display local regional time
    
      myoled.print("    : "); // no need to redisplay "Time:" label
      myoled.print(localTime);
      myoled.print(" ");
      myoled.println(tcr -> abbrev); // automatically display AEST or ADST
    
    
    // modified last oled line to include both fix and quality
    // refer previous oled image attachment
    
      sprintf(tmpstr, "Fix : %d", GPS.fix );
      myoled.print(tmpstr);
    
      sprintf(tmpstr, "     Qlty: %d", GPS.fixquality);
      myoled.println(tmpstr);
    
     

    Last edit: Matt 2020-07-30
  • brownrb

    brownrb - 2020-12-22

    Hi Matt
    5 months have passed and I am now back to revisit this.
    very impressed.
    Do you mind if this code snippet from you is included in the next update of the firmware?

    Regards
    Robert

     
    • Matt

      Matt - 2020-12-22

      Hi Robert

      No probs, you sure can.
      The code isn't mine, I merely adapted it from the relevant github pages.

      I can confirm the DST time and label kicked over nicely when it came into effect in October.

      Hopefully you can improve the code a little in the way it updates and also the initial display before it gets a time sync / sat lock.

      I'm finally putting together your dew controller project into a case.
      Going to need it before Winter comes around again.
      Will post some pics of that in the relevant forum/pages once I finish it.

      Thanks

      Matt

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.