/* NTP MODULE Copyright (C) 2016-2017 by Xose PĂ©rez */ #include #include #include // ----------------------------------------------------------------------------- // NTP // ----------------------------------------------------------------------------- void ntpConnect() { NTP.begin(NTP_SERVER, NTP_TIME_OFFSET, NTP_DAY_LIGHT); NTP.setInterval(NTP_UPDATE_INTERVAL); } bool ntpConnected() { return (timeStatus() == timeSet); } void ntpSetup() { NTP.onNTPSyncEvent([](NTPSyncEvent_t error) { if (error) { if (error == noResponse) { DEBUG_MSG_P(PSTR("[NTP] Error: NTP server not reachable\n")); } else if (error == invalidAddress) { DEBUG_MSG_P(PSTR("[NTP] Error: Invalid NTP server address\n")); } wsSend("{\"ntpStatus\": false}"); } else { DEBUG_MSG_P(PSTR("[NTP] Time: %s\n"), (char *) NTP.getTimeDateString(NTP.getLastNTPSync()).c_str()); wsSend("{\"ntpStatus\": true}"); } }); } void ntpLoop() { now(); }