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

Committer:
sjalloq
Date:
2019-05-26
Revision:
2:a3aec199dc7c
Parent:
1:099750f42b02

File content as of revision 2:a3aec199dc7c:

#ifndef _NTPCLIENT_
#define _NTPCLIENT_

#include "mbed.h"
//use nslookup 2.pool.ntp.org in cmd to find ip address

#define NTP_DEFULT_NIST_SERVER_ADDRESS "0.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 = 10000);

    private:
        NetworkInterface *iface;
        char* nist_server_address;
        int nist_server_port;

        uint32_t ntohl(uint32_t num);
};

#endif