MCPcopy Create free account
hub / github.com/SmingHub/Sming / requestTime

Method requestTime

Sming/Components/Network/src/Network/NtpClient.cpp:36–78  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

34}
35
36void NtpClient::requestTime()
37{
38 debug_d("NtpClient::requestTime()");
39
40 // Schedule a retry in anticipation of failure
41 startTimer(NTP_CONNECTION_TIMEOUT_MS);
42
43 if(!WifiStation.isConnected()) {
44 debugf("NtpClient waiting for connection...");
45 return;
46 }
47
48 ip_addr_t resolvedIp;
49 int result = dns_gethostbyname(
50 server.c_str(), &resolvedIp,
51 [](const char*, LWIP_IP_ADDR_T* ip, void* arg) {
52 // We do a new request since the last one was never done.
53 if(ip)
54 reinterpret_cast<NtpClient*>(arg)->internalRequestTime(*ip);
55 },
56 this);
57
58 debug_d("dns_gethostbyname() returned %d", result);
59
60 switch(result) {
61 case ERR_OK:
62 // Documentation says this will be the result if the string is already
63 // an ip address in dotted decimal form or if the host is found in dns cache.
64 // however I'm not sure if the dns cache is working since this never seems to
65 // be called for a host lookup other than an ip address.
66 // Doesn't really matter since the lookup will be fast anyways, the host
67 // is most likely found in the dns cache of the next node the query is sent to.
68 internalRequestTime(resolvedIp);
69 break;
70 case ERR_INPROGRESS:
71 // currently finding ip, internalRequestTime() will be called when its found.
72 debug_d("DNS IP lookup in progress...");
73 break;
74 default:
75 debug_d("DNS lookup error occurred.");
76 break;
77 }
78}
79
80void NtpClient::internalRequestTime(IpAddress serverIp)
81{

Callers 1

gotIPFunction · 0.80

Calls 3

internalRequestTimeMethod · 0.80
isConnectedMethod · 0.45
c_strMethod · 0.45

Tested by

no test coverage detected