Simple Network Time Protocol Client. This lib feature: Access to SNTP server, and get Epoch (Unix) time.
Diff: SimpleNTP.h
- Revision:
- 1:b5a2e4532331
- Parent:
- 0:2be905de8e28
--- a/SimpleNTP.h Wed Nov 25 10:03:10 2015 +0000 +++ b/SimpleNTP.h Fri Nov 27 02:10:36 2015 +0000 @@ -7,7 +7,7 @@ When cording, I refered to: http://www.softech.co.jp/mm_140305_firm.htm http://www.venus.dti.ne.jp/~yoshi-o/NTP/NTP-SNTP_Format.html - + @code #include "mbed.h" @@ -37,6 +37,8 @@ if(rtc.setRealTime(timeEpoch)) led[1]= 0; } + if(sntp.close() == SimpleNTP::SUCCESS) + led[2]= 0; return; } int main() @@ -62,7 +64,8 @@ public: enum Result { SUCCESS, - ERR_SocketInit, ERR_SetNTPAddr + ERR_SocketInit, ERR_SetNTPAddr, + ERR_SocketClose }; /** Setting for NTP/SNTP server. @@ -71,16 +74,20 @@ @return enum. */ Result setNTPServer(string _server, unsigned short _port= 123); - + /** Get NetworkTime Converted Epoch. * @return epoch(UNIX) time. NOT 1900/01/01~ */ long getNetworkTime(); // mbed is 32bit epoch. NOT "UNSIGNED long". + /** close the socket + */ + Result close(); + private: string server; unsigned short port; - + UDPSocket socket; Endpoint serverNTP;