A time interface class. This class replicates the normal time functions, but goes a couple of steps further. mbed library 82 and prior has a defective gmtime function. Also, this class enables access to setting the time, and adjusting the accuracy of the RTC.
Dependents: CI-data-logger-server WattEye X10Svr SSDP_Server
Diff: TimeInterface.cpp
- Revision:
- 21:f3818e2e0370
- Parent:
- 20:5ca2c94d46b8
- Child:
- 23:a89b319b552c
--- a/TimeInterface.cpp Mon Nov 20 17:09:48 2017 +0000 +++ b/TimeInterface.cpp Tue Nov 21 17:04:12 2017 +0000 @@ -44,18 +44,23 @@ NTPResult TimeInterface::setTime(const char* host, uint16_t port, uint32_t timeout) { - NTPClient ntp(m_net); NTPResult res; - // int16_t tzomin = get_tzo_min(); - INFO("setTime(%s, %d, %d)\r\n", host, port, timeout); - res = ntp.setTime(host, port, timeout); - INFO(" ret: %d\r\n", res); - if (res == NTP_OK) { - // if the time was fetched successfully, then - // let's save the time last set with the local tzo applied - // and this saves the last time set for later precision - // tuning. - set_time(std::time(NULL)); + + if (m_net) { + NTPClient ntp(m_net); + // int16_t tzomin = get_tzo_min(); + INFO("setTime(%s, %d, %d)\r\n", host, port, timeout); + res = ntp.setTime(host, port, timeout); + INFO(" ret: %d\r\n", res); + if (res == NTP_OK) { + // if the time was fetched successfully, then + // let's save the time last set with the local tzo applied + // and this saves the last time set for later precision + // tuning. + set_time(std::time(NULL)); + } + } else { + res = NTP_CONN; } return res; }