NTP networking client stuff
Dependents: Coursework_Version_6 Coursework_Version_8 ELEC351-Coursework
Revision 1:099750f42b02, committed 2018-12-07
- Comitter:
- Alix955
- Date:
- Fri Dec 07 13:07:56 2018 +0000
- Parent:
- 0:3c1170035e2b
- Commit message:
- ntp client stuff;
Changed in this revision
NTPClient.cpp | Show annotated file Show diff for this revision Revisions of this file |
NTPClient.h | Show annotated file Show diff for this revision Revisions of this file |
diff -r 3c1170035e2b -r 099750f42b02 NTPClient.cpp --- a/NTPClient.cpp Tue Dec 04 17:36:03 2018 +0000 +++ b/NTPClient.cpp Fri Dec 07 13:07:56 2018 +0000 @@ -20,6 +20,7 @@ if (ret_gethostbyname < 0) { // Network error on DNS lookup + printf("Error on DNS lookup : %d\n" , ret_gethostbyname); return ret_gethostbyname; } @@ -44,9 +45,11 @@ } else { if (n < 0) { // Network error + printf("Network error: %d\n", n); return n; } else { // No or partial data returned + printf("No or partial data returned: -1"); return -1; } }
diff -r 3c1170035e2b -r 099750f42b02 NTPClient.h --- a/NTPClient.h Tue Dec 04 17:36:03 2018 +0000 +++ b/NTPClient.h Fri Dec 07 13:07:56 2018 +0000 @@ -1,14 +1,18 @@ -#include "mbed.h" +#ifndef _NTPCLIENT_ +#define _NTPCLIENT_ -#define NTP_DEFULT_NIST_SERVER_ADDRESS "2.pool.ntp.org" -//#define NTP_DEFULT_NIST_SERVER_ADDRESS "0.europe.pool.ntp.org" +#include "mbed.h" +//use nslookup 2.pool.ntp.org in cmd to find ip address + +//#define NTP_DEFULT_NIST_SERVER_ADDRESS "2.pool.ntp.org" +#define NTP_DEFULT_NIST_SERVER_ADDRESS "109.74.206.120" #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); + time_t get_timestamp(int timeout = 10000); private: NetworkInterface *iface; @@ -16,4 +20,6 @@ int nist_server_port; uint32_t ntohl(uint32_t num); -}; \ No newline at end of file +}; + +#endif