ntp.c 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. //
  2. // Created by janco on 25-2-16.
  3. //
  4. #include <dev/board.h>
  5. #include <dev/debug.h>
  6. #include <sys/timer.h>
  7. #include <arpa/inet.h>
  8. #include <net/route.h>
  9. #include <pro/dhcp.h>
  10. #include <pro/sntp.h>
  11. #include <stdlib.h>
  12. #include <stdio.h>
  13. #include <io.h>
  14. #include <string.h>
  15. #include <time.h>
  16. #include "ntp.h"
  17. time_t ntp_time = 0;
  18. tm *ntp_datetime;
  19. uint32_t timeserver = 0;
  20. void NtpInit() {
  21. /* Timezone van nederland (gmt 1) */
  22. _timezone = -2 * 60 * 60;
  23. GetTime();
  24. }
  25. void GetTime(){
  26. /* Ophalen van pool.ntp.org */
  27. puts("Tijd ophalen van pool.ntp.org (213.154.229.24)");
  28. timeserver = inet_addr("213.154.229.24");
  29. for (;;) {
  30. if (NutSNTPGetTime(&timeserver, &ntp_time) == 0) {
  31. break;
  32. } else {
  33. NutSleep(400);
  34. puts("Fout bij het ontvangen van de tijd");
  35. }
  36. }
  37. puts("Opgehaald.\n");
  38. ntp_datetime = localtime(&ntp_time);
  39. printf("NTP tijd is: %02d:%02d:%02d\n", ntp_datetime->tm_hour, ntp_datetime->tm_min, ntp_datetime->tm_sec);
  40. //return ntp_datetime;
  41. }