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.
NTPClient.h@1:099750f42b02, 2018-12-07 (annotated)
- Committer:
- Alix955
- Date:
- Fri Dec 07 13:07:56 2018 +0000
- Revision:
- 1:099750f42b02
- Parent:
- 0:3c1170035e2b
- Child:
- 2:a3aec199dc7c
ntp client stuff;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Alix955 | 1:099750f42b02 | 1 | #ifndef _NTPCLIENT_ |
Alix955 | 1:099750f42b02 | 2 | #define _NTPCLIENT_ |
Alix955 | 0:3c1170035e2b | 3 | |
Alix955 | 1:099750f42b02 | 4 | #include "mbed.h" |
Alix955 | 1:099750f42b02 | 5 | //use nslookup 2.pool.ntp.org in cmd to find ip address |
Alix955 | 1:099750f42b02 | 6 | |
Alix955 | 1:099750f42b02 | 7 | //#define NTP_DEFULT_NIST_SERVER_ADDRESS "2.pool.ntp.org" |
Alix955 | 1:099750f42b02 | 8 | #define NTP_DEFULT_NIST_SERVER_ADDRESS "109.74.206.120" |
Alix955 | 0:3c1170035e2b | 9 | #define NTP_DEFULT_NIST_SERVER_PORT 123 |
Alix955 | 0:3c1170035e2b | 10 | |
Alix955 | 0:3c1170035e2b | 11 | class NTPClient { |
Alix955 | 0:3c1170035e2b | 12 | public: |
Alix955 | 0:3c1170035e2b | 13 | NTPClient(NetworkInterface *iface); |
Alix955 | 0:3c1170035e2b | 14 | void set_server(char* server, int port); |
Alix955 | 1:099750f42b02 | 15 | time_t get_timestamp(int timeout = 10000); |
Alix955 | 0:3c1170035e2b | 16 | |
Alix955 | 0:3c1170035e2b | 17 | private: |
Alix955 | 0:3c1170035e2b | 18 | NetworkInterface *iface; |
Alix955 | 0:3c1170035e2b | 19 | char* nist_server_address; |
Alix955 | 0:3c1170035e2b | 20 | int nist_server_port; |
Alix955 | 0:3c1170035e2b | 21 | |
Alix955 | 0:3c1170035e2b | 22 | uint32_t ntohl(uint32_t num); |
Alix955 | 1:099750f42b02 | 23 | }; |
Alix955 | 1:099750f42b02 | 24 | |
Alix955 | 1:099750f42b02 | 25 | #endif |