Created
October 31, 2011 17:54
-
-
Save futureshape/1328159 to your computer and use it in GitHub Desktop.
Ethercard getNtpTime
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
unsigned long getNtpTime() { | |
unsigned long timeFromNTP; | |
const unsigned long seventy_years = 2208988800UL; | |
ether.ntpRequest(ntpServer, ntpMyPort); | |
Serial.println("NTP request sent"); | |
while(true) { | |
word length = ether.packetReceive(); | |
ether.packetLoop(length); | |
if(length > 0 && ether.ntpProcessAnswer(&timeFromNTP,ntpMyPort)) { | |
Serial.println("NTP reply received"); | |
return timeFromNTP - seventy_years + timeZoneOffset; | |
} | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment