Skip to content

Instantly share code, notes, and snippets.

@futureshape
Created October 31, 2011 17:54
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save futureshape/1328159 to your computer and use it in GitHub Desktop.
Save futureshape/1328159 to your computer and use it in GitHub Desktop.
Ethercard getNtpTime
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