9 Replies Latest reply on Oct 16, 2014 2:51 PM by mhahn

    no ntp on edison?


      am I missing something, or is there currently no ntp in the default OS image for edison?


      If not, might I consider you add this in as soon as possible.

      I don't see how this device is supposed to run practically in the wild as an IoT device without time sync

        • 1. Re: no ntp on edison?

          Hi Daveman,


          Yes, you are right about the importance of NTP. By the way, thanks for your feedback. We'll forward this suggestion to the team that builds the Edison image.


          Have a nice day!




          • 2. Re: no ntp on edison?

            Please read related posting from AlexT


            Also confirm if this works for you.

            • 3. Re: no ntp on edison?

              Can the build team please consider integrating it into the default images?

              • 4. Re: no ntp on edison?

                Hey Dave, this is WIP. We should get ETA soon.

                • 5. Re: no ntp on edison?

                  Sounds good.


                  It is sort of interesting that I created duplicate of this thread, just after this one was created.    After I tried the stuff in AlexT and it did not want to install for me, I thought I would try to see if there was something simple I could try until something came along.  So I did a net search and looked at the site: c - How to write a NTP client? - Stack Overflow


                  I then hacked up a version of one of the programs there, where I then added code that if my clock was off by more than 5 seconds it would try to update the time.  The program is not great, sometimes it hangs waiting for a packet that does not return...  I hacked my version up to use the IP address that was returned when I pinged a us time serover in the pool.


                  Again this is just a hacked up version, no promises, or the like but at least it helps me to get reasonably close, so my makefiles don't get screwed up looping on files that are way off in the future time...


                  If you wish to give it a try, I have included the sources here.  Sorry I don't know the best way to include code here.  On other boards, I would put them in code tags or include the file, but not sure how...

                  // Building with: i586-poky-linux-gcc -o ntpdate ntpdate.c

                  /* This code will query a ntp server for the local time and display

                  * it.  it is intended to show how to use a NTP server as a time

                  * source for a simple network connected device.

                  * This is the C version.  The orignal was in Perl


                  * For better clock management see the offical NTP info at:

                  * http://www.eecis.udel.edu/~ntp/


                  * written by Tim Hogard (thogard@abnormal.com)

                  * Thu Sep 26 13:35:41 EAST 2002

                  * Converted to C Fri Feb 21 21:42:49 EAST 2003

                  * this code is in the public domain.

                  * it can be found here http://www.abnormal.com/~thogard/ntp/



                  #include <stdio.h>

                  #include <sys/types.h>

                  #include <sys/socket.h>

                  #include <netinet/in.h>

                  #include <arpa/inet.h>

                  #include <netdb.h>

                  #include <time.h>

                  #include <string.h>


                  void ntpdate();


                  int main() {


                    return 0;



                  void ntpdate() {


                  //  char *hostname="";

                    char *hostname="";  // ping 0.us.pool.ntp.org

                    int portno=123;    //NTP is port 123

                    int maxlen=1024;        //check our buffers

                    int i;          // misc var i

                    unsigned char msg[48]={

                      010,0,0,0,0,0,0,0,0  };    // the packet we send

                    unsigned long  buf[maxlen]; // the buffer we get back

                    //struct in_addr ipaddr;        //

                    struct protoent *proto;    //

                    struct sockaddr_in server_addr;

                    int s;  // socket

                    time_t tmit;  // the time -- This is a time_t sort of


                    //use Socket;


                    //#we use the system call to open a UDP socket

                    //socket(SOCKET, PF_INET, SOCK_DGRAM, getprotobyname("udp")) or die "socket: $!";


                    s=socket(PF_INET, SOCK_DGRAM, proto->p_proto);



                    //#convert hostname to ipaddress if needed

                    //$ipaddr  = inet_aton($HOSTNAME);

                    memset( &server_addr, 0, sizeof( server_addr ));


                    server_addr.sin_addr.s_addr = inet_addr(hostname);

                    //argv[1] );

                    //i  = inet_aton(hostname,&server_addr.sin_addr);


                    printf("ipaddr (in hex): %x\n",server_addr.sin_addr);



                  * build a message.  Our message is all zeros except for a one in the

                    * protocol version field

                    * msg[] in binary is 00 001 000 00000000

                    * it should be a total of 48 bytes long



                    // send the data

                    printf("sending data..\n");

                    i=sendto(s,msg,sizeof(msg),0,(struct sockaddr *)&server_addr,sizeof(server_addr));


                    // get the data back

                    struct sockaddr saddr;

                    socklen_t saddr_l = sizeof (saddr);




                    //We get 12 long words back in Network order







                  * The high word of transmit time is the 10th word we get back

                    * tmit is the time in seconds not accounting for network delays which

                    * should be way less than a second if this is a local NTP server



                    tmit=ntohl((time_t)buf[10]);    //# get transmit time




                  * Convert time to unix standard time NTP is number of seconds since 0000

                    * UT on 1 January 1900 unix time is seconds since 0000 UT on 1 January

                    * 1970 There has been a trend to add a 2 leap seconds every 3 years.

                    * Leap seconds are only an issue the last second of the month in June and

                    * December if you don't try to set the clock then it can be ignored but

                    * this is importaint to people who coordinate times with GPS clock sources.



                    tmit-= 2208988800U;


                    /* use unix library function to show me the local time (it takes care

                    * of timezone issues for both north and south of the equator and places

                    * that do Summer time/ Daylight savings time.




                    //#compare to system time

                    printf("Time: %s",ctime(&tmit));



                    printf("System time is %d seconds off\n",i-=tmit);


                    // what happens if we call settimeof day?

                    if (abs(i) > 5) {

                        struct timeval tv;

                        tv.tv_sec = tmit;

                        tv.tv_usec = 0;

                        settimeofday(&tv, 0);

                        printf("Time updated\n");



                  • 6. Re: no ntp on edison?

                    - would "rdate" work for you?

                    - also connman has a built in "ntpd light" - you might try this

                    - at least I appear to be only able to use code formatting when starting a thread

                    • 7. Re: no ntp on edison?

                      Looks like there's no NTP package in the repo at the moment - I'm building that one right now.


                      But isn't there a systemd piece that does timesync already? I don't have the board at hand, but I recall my one had correct time when I checked that and there was a process like system-timesyncd or something along these lines (or is that a false memory? %)

                      • 8. Re: no ntp on edison?

                        ...and the package is in the repo now.

                        • 9. Re: no ntp on edison?

                          at least I do have correct time on my Edison after reboots. But I do use connman