void NtpClient::requestTime() { if (!WifiStation.isConnected()) { connectionTimer.initializeMs(1000, Delegate<void()>(&NtpClient::requestTime, this)).startOnce(); return; } if (serverAddress.isNull()) { if (!resolveServer()) { return; } } // connect to current active serverAddress, on NTP_PORT this->connect(serverAddress,NTP_PORT); uint8_t packet[NTP_PACKET_SIZE]; // Setup the NTP request packet memset(packet, 0, NTP_PACKET_SIZE); // These are the only required values for a SNTP request. See page 14: // https://tools.ietf.org/html/rfc4330 // However size of packet should still be 48 bytes. packet[0] = (NTP_VERSION << 3 | 0x03); // LI (0 = no warning), Protocol version (4), Client mode (3) packet[1] = 0; // Stratum, or type of clock, unspecified. // Send to server, serverAddress & port is set in connect NtpClient::send((char*) packet, NTP_PACKET_SIZE); }
void NtpClient::requestTime() { // Start listening for incomming packets. // may already been started in that case nothing happens. this->listen(NTP_LISTEN_PORT); if (serverAddress.isNull()) { if (!resolveServer()) { return; } } uint8_t packet[NTP_PACKET_SIZE]; // Setup the NTP request packet memset(packet, 0, NTP_PACKET_SIZE); // These are the only required values for a SNTP request. See page 14: // https://tools.ietf.org/html/rfc4330 // However size of packet should still be 48 bytes. packet[0] = (NTP_VERSION << 3 | 0x03); // LI (0 = no warning), Protocol version (4), Client mode (3) packet[1] = 0; // Stratum, or type of clock, unspecified. NtpClient::sendTo(serverAddress, NTP_PORT, (char*) packet, NTP_PACKET_SIZE); }