11 years, 11 months ago.

error in NTPResult?

Hi there, when trying to readout NTPResult i am getting a compler error as if NTP_DNS and NTP_OK is the same statement:

case label value has already appeared in this switch at line xxx

Where line number to whichever, NTP_DNS or NTP_OK comes first, i don't get it!
Shuffling cases around just changes the line number.

         NTPResult res;
         switch(res)
            {
            case NTP_CONN:          printf("NTP sync connection error\n");
            break; 
            case NTP_PRTCL:         printf("NTP sync Protocol error\n");
            break;
            case NTP_TIMEOUT:       printf("NTP sync timeout (%ims)\n", NTP_TIMEOUT);
            break;
            case NTP_DNS:           printf("NTP sync could not resolve DNS hostname (%s)\n", NTP_SRV);
            break;
            case NTP_OK:            printf("NTP sync OK\n");
            break;
            }

i am using

Import libraryNTPClient

NTP Client for the mbed networking libraries

Question relating to:

1 Answer

11 years, 11 months ago.

Check the ntpclient lib and you will find the declaration

//NTP client results
enum NTPResult
{
  NTP_DNS, ///<Could not resolve name
  NTP_PRTCL, ///<Protocol error
  NTP_TIMEOUT, ///<Connection timeout
  NTP_CONN, ///<Connection error
  NTP_OK = 0, ///<Success
};

This shows that NTP_OK is forced to 0, while NTP_DNS will be auto-defined to 0 also. This leads to the compiler error. Change the enum order to fix this: NTP_OK should be the first in the list.

Accepted Answer

Thanks, that did the trick, I also found i had a #define NTP_TIMEOUT 1 to... well define the timeout, same problem.

Unfortunately, there's still some bugs in the library. If i unplug the network cable it returns a error code, but not always the same one (i would expect NTP_CONN), this is minor and not really a problem. However, if the ntp server is unreachable (using bogus server or port) it just hangs,i see from the debug messages that i get a "pong from the ping" that can't be right.

Trying NTP sync from 0.uk.pool.ntp.org port 120 [NTPClient : DBG]Time is set to (UTC): Thu Jan 1 01:13:00 1970 [NTPClient : DBG]Binding socket [NTPClient : DBG]Ping [NTPClient : DBG]Pong

posted by Thomas Olsson 06 Jan 2013