This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

LAUNCHCC3235MOD: Setting Daylight Savings Time

Part Number: LAUNCHCC3235MOD

When I go to launchpad webpage and set time, it shows a good local time, but my SNTP code

//...
if (clock_settime(CLOCK_REALTIME, &ts) != 0) {
        Display_printf(display, 0, 0, "startSNTP: Failed to set current time\n");
        iret=0;
    }
    else{
        iret=1;
        int isz=sizeof(tp);
        int ires=clock_gettime(CLOCK_REALTIME,&tp);
        strftime(&(acdt[0]), 0x30, "%D %T", gmtime(&tp.tv_sec));
        Display_printf(display, 0, 0, "Time=%s\n",&acdt[0] );
        strftime(&(acdt[0]), 0x30, "%D %T", localtime(&tp.tv_sec));
        Display_printf(display, 0, 0, "Local Time=%s\n",&acdt[0] );
    }
//...

I get results as if  DST not properly configured:

retVal=0

Time=10/11/23 15:42:22

Local Time=10/11/23 09:42:22

which would be wrong for CDT

How do I configure properly the DST in local time?

  • Hi,

    SNTP protocol provide UTC time. Re-calculation of UTC time to your local time is up to your code.

    Common way is set location of your device by user and from this location calculate UTC offset according DST rules for that place. Other option can be usage of DHCP Option 2. But this feature is not supported by DHCP client inside NWP. You will need to run own DHCP client at application processor to add this feature.

    Jan

  • As I stated, the device was setup by user in web interface and the correct local time displayed. There must be some way to do this. Current code looks like 

     

    // Time
    #include <time.h>
    #include <unistd.h>
    #include <ti/net/sntp/sntp.h>
    #define TIME_BASEDIFF        ((((uint32_t)70 * 365 + 17) * 24 * 3600))
    #define TIME_NTP_TO_LOCAL(t) ((t) - TIME_BASEDIFF)
    #define NTP_SERVERS 1
    #define NTP_SERVER_PORT 123
    /*  Time to wait for reply from server (seconds) */
    #define NTP_REPLY_WAIT_TIME 5
    /* Must wait at least 15 sec to retry NTP server (RFC 4330) */
    #define NTP_POLL_TIME 15
    #define TIME_BASEDIFF        ((((uint32_t)70 * 365 + 17) * 24 * 3600))
    #define TIME_NTP_TO_LOCAL(t) ((t) - TIME_BASEDIFF)
    volatile int g_ibtime=0;
    //
    int startSNTP(void){
        uint32_t uimax = 0xffffffff;
        int iret=0;
        if (g_ibtime==1) return 1;
        int32_t  retVal;
        uint32_t seconds;
        uint32_t secondsFraction;
        SlNetSock_Timeval_t timeval;
        uint64_t ntpTimeStamp = 0;
        uint32_t uiunix_secs;
        struct timespec ts;
        //struct tm;
        struct timespec tp;
        char acdt[0x30];
        /* Set timeout value for NTP server reply */
        timeval.tv_sec = NTP_REPLY_WAIT_TIME;
        timeval.tv_usec = 0;
        do {
            /* Get the time use the built in NTP server list: */
            //retVal = SNTP_getTime((const char *)"192.168.1.85", 1, &timeval, &ntpTimeStamp);
            retVal = SNTP_getTime(0, 0, &timeval, &ntpTimeStamp);
            if (retVal != 0) {
                Display_printf(display, 0, 0,
                    "startSNTP: couldn't get time (%d), will retry in %d secs ...",
                    retVal, NTP_POLL_TIME);
                sleep(NTP_POLL_TIME);//
                Display_printf(display, 0, 0, "startSNTP: retrying ...");
            }
            Display_printf(display, 0, 0,"startSNTP: Got time.\n");
            seconds = (0xFFFFFFFF00000000 & ntpTimeStamp) >> 32;
            // The seconds fraction is stored in the lower 32 bits
            secondsFraction = ntpTimeStamp;
            Display_printf(display, 0, 0,"seconds=0x%08x\n",seconds);
            ts.tv_sec=TIME_NTP_TO_LOCAL(seconds);
            Display_printf(display, 0, 0,"unix seconds=0x%08x\n",ts.tv_sec);
            ts.tv_nsec=(int32_t)(((double)secondsFraction / (double)uimax) *( (double)0x3B9ACA00));
            Display_printf(display, 0, 0,"nanoseconds=0x%08x\n",ts.tv_nsec);
            int ix= strftime(&acdt[0], 0x30, "%D %T", &ts.tv_sec);
            Display_printf(display, 0, 0,"retVal=%d\n",retVal);
        } while (retVal < 0);
        if (clock_settime(CLOCK_REALTIME, &ts) != 0) {
            Display_printf(display, 0, 0, "startSNTP: Failed to set current time\n");
            iret=0;
        }
        else{
            iret=1;
            int isz=sizeof(tp);
            int ires=clock_gettime(CLOCK_REALTIME,&tp);
    
            strftime(&(acdt[0]), 0x30, "%D %T", gmtime(&tp.tv_sec));
            Display_printf(display, 0, 0, "Time=%s\n",&acdt[0] );
            strftime(&(acdt[0]), 0x30, "%D %T", localtime(&tp.tv_sec));
            Display_printf(display, 0, 0, "Local Time=%s\n",&acdt[0] );
        }
        g_ibtime=1;
        return iret;
    }
    

  • Hi,

    I never used time.h library with CC32xx. I would recommand to use clock_sync.h library as is common way with TI demo examples (e.g. local_time). There is function ClockSync_setTimeZone() for settings of timezone.

    Jan

  • Thanks. I'm beginning to rethink this based on complexity and how useful it would be in a timestamp. UTC and xST is good enough for me now. My router does not support dhcp option 2 as far as I can tell.