Fixed NTPResult values

Dependents:   NTPClient_HelloWorld_WIZ550io LPC11U68_NTPClient_HelloWorld_WIZ550io SNIC-ntpclient-example NTPClient_HelloWorld ... more

Fork of NTPClient by Donatien Garnier

Revision:
6:15c04f752381
Parent:
5:c70ed0bfab2e
--- a/NTPClient.cpp	Sun Dec 22 13:59:33 2013 +0000
+++ b/NTPClient.cpp	Sun Feb 01 13:43:49 2015 +0000
@@ -146,11 +146,11 @@
 
   //Compute offset, see RFC 4330 p.13
   uint32_t destTm_s = (NTP_TIMESTAMP_DELTA + time(NULL));
-  int64_t offset = ( (int64_t)( pkt.rxTm_s - pkt.origTm_s ) + (int64_t) ( pkt.txTm_s - destTm_s ) ) / 2; //Avoid overflow
+  int64_t offset = ( ( (int64_t)pkt.rxTm_s - (int64_t)pkt.origTm_s ) + ( (int64_t)pkt.txTm_s - (int64_t)destTm_s ) ) / 2; //Avoid overflow
   DBG("Sent @%ul", pkt.txTm_s);
   DBG("Offset: %lld", offset);
   //Set time accordingly
-  set_time( time(NULL) + offset );
+  if(offset != 0) set_time( time(NULL) + offset );
 
 #ifdef __DEBUG__
   ctTime = time(NULL);