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.

CC3200: wrong date-time calculation from SNTP

Part Number: CC3200

Hello all,

I am using cc3200 controller. In my application I am using SNTP time to feed my RTC. Now, I am facing problem with the SNTP time coming from the ntp server, it is showing wrong date.

I checked the GetSNTPTime() function in time.c and tried to calculate using debugger where is the problem.

I am using IST time zone so time difference will be +5:30 of GMT and I am taking time from this server 0.asia.pool.ntp.org. So taking the example of todays date-time it must show 31-12-2018 16:17:20. But now it is showing 00-01-2019 16:17:20. I checked the URL but it is giving correct time so there might be problem with the calculations in the function GetSNTPTime()

Earlier also in the same function on every 31st day of the month it starts giving 00, I made it correct in the calculation of month

        for (iIndex = 0; iIndex < 12; iIndex++)
        {
            g_sAppData.isGeneralVar -= g_acNumOfDaysPerMonth[iIndex];
            if (g_sAppData.isGeneralVar <= 0)
                    break;
        }

I made changes in the if condition earlier it was

g_sAppData.isGeneralVar = 0

I change it to 

g_sAppData.isGeneralVar <= 0

This correction resolved my problem with day, now I am facing problem with the year due to which month and day also get wrong.

  • Hi Shubham,

    There is an existing E2E thread with someone that has had the same issue as you. You can find it here. Let me know if this helps.

    Jesu

  • Hi Jesu,

    I checked the link you shared and implemented in my code but the results are same. I have tested it with the Los Angeles time which is -8 hrs from GMT and seeing the current time there is 11:18 PM.

            //
            g_sAppData.ulElapsedSec -= TIME2013;
    
            //
            // in order to correct the timezone
            //
            g_sAppData.ulElapsedSec += (ucGmtDiffHr * SEC_IN_HOUR);
            g_sAppData.ulElapsedSec += (ucGmtDiffMins * SEC_IN_MIN);
    
            UART_PRINT("real time sec:%u\r\n", g_sAppData.ulElapsedSec);
    
            g_sAppData.pcCCPtr = &g_sAppData.acTimeStore[0];
    
            //
            // day, number of days since beginning of 2013
            //
            g_sAppData.isGeneralVar = g_sAppData.ulElapsedSec/SEC_IN_DAY;
            memcpy(g_sAppData.pcCCPtr, g_acDaysOfWeek2013[g_sAppData.isGeneralVar%7], 0);       //need to change 0 to 3 for show day
            g_sAppData.pcCCPtr += 0;        // did changes
    //        *g_sAppData.pcCCPtr++ = '\x20';
    
            //
            // year
            // number of days since beginning of 2013
            //
            g_sAppData.ulGeneralVar = g_sAppData.ulElapsedSec/SEC_IN_DAY;
            g_sAppData.ulGeneralVar /= 365;                                    //year =2013+this value
            g_sAppData.uisCCLen = itoa(YEAR2013 + g_sAppData.ulGeneralVar,
                                       g_sAppData.pcCCPtr);
            g_sAppData.pcCCPtr += g_sAppData.uisCCLen;

    My calculations are getting wrong in the above code. For current time stamp I am getting 

    g_sAppData.ulElapsedSec  = 189299475

    And if you use above value in calculating the Year and date it will come 2019. So this is the main problem.

    Thanks & Regards

    Shubham

  • Hi,

    It will be great if someone reply to my query.

    Thanks & regards

    Shubham

  • Hi Shubham,

    You can try to use my code e2e.ti.com/.../2082275

    Jan