Fork of the espurna firmware for `mhsw` switches
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

66 lines
985 B

  1. /*
  2. NTP MODULE
  3. */
  4. #pragma once
  5. #include "espurna.h"
  6. #if NTP_SUPPORT
  7. #include "broker.h"
  8. #if NTP_LEGACY_SUPPORT // Use legacy TimeLib and NtpClientLib
  9. #include <TimeLib.h>
  10. #include <WiFiUdp.h>
  11. #include <NtpClientLib.h>
  12. time_t ntpLocal2UTC(time_t local);
  13. #else // POSIX time functions + configTime(...)
  14. #include <lwip/apps/sntp.h>
  15. #include <TZ.h>
  16. #include "ntp_timelib.h"
  17. #endif
  18. // --- rest of the module is ESPurna functions
  19. enum class NtpTick {
  20. EveryMinute,
  21. EveryHour
  22. };
  23. struct NtpCalendarWeekday {
  24. int local_wday;
  25. int local_hour;
  26. int local_minute;
  27. int utc_wday;
  28. int utc_hour;
  29. int utc_minute;
  30. };
  31. struct NtpInfo {
  32. String local;
  33. String utc;
  34. String sync;
  35. String tz;
  36. time_t now;
  37. };
  38. BrokerDeclare(NtpBroker, void(const NtpTick, time_t, const String&));
  39. NtpInfo ntpInfo();
  40. String ntpDateTime(tm* timestruct);
  41. String ntpDateTime(time_t ts);
  42. String ntpDateTime();
  43. bool ntpSynced();
  44. void ntpSetup();
  45. #endif // NTP_SUPPORT