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.

MSP432E401Y: SNTP_getTimeByAddr never works SNTP_getTime does.Why ?

Part Number: MSP432E401Y

Hi,

using SDK: simplelink_msp432e4_sdk_3_20_00_10, using IPV4

I need to have the option to get the UTC time using SNTP service. If I use SNTP_getTime by using the built in server name list (sntp.c) it works. Always. However if I try to use the function SNTP_getTimeByAddr it never works and returns with the error code -107.

I tried to find the root cause. The only thing I can find is within sntp.c both functions do finally call the very same function internally:

static int32_t getTime(SlNetSock_Addr_t *server, uint16_t ifID, SlNetSock_Timeval_t *timeout, uint64_t *ntpTimeStamp);

The difference is that in working version (SNTP_getTime) the value for ifID is not '0'. In the version SNTP_getTimeByAddr ifID is nulled or set to '0' before calling getTime

The application is based on an example from TI. I check which version has to be called and I need both of them to work properly.

        // Chk if a dedicated time server has to be called. If not use one
        // of the internal compiled list of servers.

        if (bTRUE == sysCfg.iCfgNetUseSNTP && (0 != sntpIP)) { <<-- Check which call is needed ...

            retval = SNTP_getTimeByAddr((SlNetSock_Addr_t *)&sntpServer, &timeval, &ntpTimeStamp); <<-- never works reval = - 107
        } else {

            /* Get the time use the built in NTP server list: */
            retval = SNTP_getTime(NULL, 0, &timeval, &ntpTimeStamp); <<-- is working!
        }

Any idea, where to look further?

Markus

  • Hi,

    We will look into it and get back to you ASAP. Please bear with us.

    Thanks,

    PM

  • Hi Markus,

    Sorry for the delayed response. I am actively looking into this and should have some information to relay back tomorrow.

    Thanks,

    Alexis

  • Hi Markus,

    ngrkus said:
    The difference is that in working version (SNTP_getTime) the value for ifID is not '0'. In the version SNTP_getTimeByAddr ifID is nulled or set to '0' before calling getTime

    In SNTP_getTimeByAddr(), ifID == 0 means the interface is selected automatically, vs. SNTP_getTime() where the IF ID value is known (it was determined during the DNS resolution).

    ngrkus said:
    if I try to use the function SNTP_getTimeByAddr it never works and returns with the error code -107.

    This code means that the call to receive data failed:

    /*!                                                                                                                                                                            
     *  @brief Failed to recieve the new time from the NTP server                                                                                                                  
     */                                                                                                                                                                            
    #define SNTP_ERECVFAIL              (-107)

    This happens in the getTime function:

        /* Retrieve the NTP packet from the socket and update our time. */                                                                                                         
        ret = SlNetSock_recv(sd, &sntpPkt, sizeof(SNTP_Header_t), 0);                                                                                                              
        if ((ret < 0) || (ret != sizeof(SNTP_Header_t)) || (sntpPkt.originateTS[0] != integrityCheck))                                                                             
        {                                                                                                                                                                          
            SlNetSock_close(sd);                                                                                                                                                   
            return (SNTP_ERECVFAIL);                                                                                                                                               
        }                

    Can you get a Wireshark capture of this? Do you see the NTP packet going out to the server? Do you see a response from the server coming back?

    Would also be good to put a break point at the return shown above and check what the value of ret is.

    Steve

  • Hi Steve,

    thank you for your reply. Digging deeper and deeper finally I was able to find the root cause of all the confusion.

    I am deeply sorry about it. Before using the time server IP address I do the following:

    uint32_t sntpIP = inet_addr(sysCfg.iCfgNetSNTP); which basically translates the dot IP address "216.239.35.0"

    (google time server as an example) to the internet-address inet_addr returns an IP address in the network order being big endian

    and not in the local machine little endian order. Before calling the function SNTP_getTimeByAddr I basically did call

    sntpServer.sin_addr.s_addr = SlNetUtil_htonl(sntpIP);

    This reverts the network address back to the little endian format. Obviously this is wrong.

    By just assigning the sntpIP address to the structs member and then calling SNTP_getTimeByAddr everything

    works! Aaarrggghh! I really should have read the man pages ... for inet_addr() It even has it in its function name ...more aaarrggghhh ...

    Thank you for your help! It works now and I am happy ;-)

    br

    Markus

  • No worries, I'm glad you got past the problem!

    Steve

**Attention** This is a public forum