A port and bug fix of Alix955/code/ntp-client. The socket would hang as it was defined both with a timeout and as blocking.
Diff: NTPClient.h
- Revision:
- 0:3c1170035e2b
- Child:
- 1:099750f42b02
diff -r 000000000000 -r 3c1170035e2b NTPClient.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/NTPClient.h Tue Dec 04 17:36:03 2018 +0000 @@ -0,0 +1,19 @@ +#include "mbed.h" + +#define NTP_DEFULT_NIST_SERVER_ADDRESS "2.pool.ntp.org" +//#define NTP_DEFULT_NIST_SERVER_ADDRESS "0.europe.pool.ntp.org" +#define NTP_DEFULT_NIST_SERVER_PORT 123 + +class NTPClient { + public: + NTPClient(NetworkInterface *iface); + void set_server(char* server, int port); + time_t get_timestamp(int timeout = 15000); + + private: + NetworkInterface *iface; + char* nist_server_address; + int nist_server_port; + + uint32_t ntohl(uint32_t num); +}; \ No newline at end of file