|
@ -57,11 +57,11 @@ class AhoyNetwork { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
bool updateNtpTime(void) { |
|
|
bool updateNtpTime(void) { |
|
|
if(NetworkState::CONNECTED != mStatus) |
|
|
if(NetworkState::GOT_IP != mStatus) |
|
|
return false; |
|
|
return false; |
|
|
|
|
|
|
|
|
IPAddress timeServer; |
|
|
|
|
|
if (!mUdp.connected()) { |
|
|
if (!mUdp.connected()) { |
|
|
|
|
|
IPAddress timeServer; |
|
|
if (!WiFi.hostByName(mConfig->ntp.addr, timeServer)) |
|
|
if (!WiFi.hostByName(mConfig->ntp.addr, timeServer)) |
|
|
return false; |
|
|
return false; |
|
|
if (!mUdp.connect(timeServer, mConfig->ntp.port)) |
|
|
if (!mUdp.connect(timeServer, mConfig->ntp.port)) |
|
@ -71,7 +71,7 @@ class AhoyNetwork { |
|
|
mUdp.onPacket([this](AsyncUDPPacket packet) { |
|
|
mUdp.onPacket([this](AsyncUDPPacket packet) { |
|
|
this->handleNTPPacket(packet); |
|
|
this->handleNTPPacket(packet); |
|
|
}); |
|
|
}); |
|
|
sendNTPpacket(timeServer); |
|
|
sendNTPpacket(); |
|
|
|
|
|
|
|
|
return true; |
|
|
return true; |
|
|
} |
|
|
} |
|
@ -173,7 +173,7 @@ class AhoyNetwork { |
|
|
#endif |
|
|
#endif |
|
|
|
|
|
|
|
|
private: |
|
|
private: |
|
|
void sendNTPpacket(IPAddress& address) { |
|
|
void sendNTPpacket(void) { |
|
|
//DPRINTLN(DBG_VERBOSE, F("wifi::sendNTPpacket"));
|
|
|
//DPRINTLN(DBG_VERBOSE, F("wifi::sendNTPpacket"));
|
|
|
uint8_t buf[NTP_PACKET_SIZE]; |
|
|
uint8_t buf[NTP_PACKET_SIZE]; |
|
|
memset(buf, 0, NTP_PACKET_SIZE); |
|
|
memset(buf, 0, NTP_PACKET_SIZE); |
|
@ -188,9 +188,7 @@ class AhoyNetwork { |
|
|
buf[14] = 49; |
|
|
buf[14] = 49; |
|
|
buf[15] = 52; |
|
|
buf[15] = 52; |
|
|
|
|
|
|
|
|
//mUdp.beginPacket(address, 123); // NTP request, port 123
|
|
|
|
|
|
mUdp.write(buf, NTP_PACKET_SIZE); |
|
|
mUdp.write(buf, NTP_PACKET_SIZE); |
|
|
//mUdp.endPacket();
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void handleNTPPacket(AsyncUDPPacket packet) { |
|
|
void handleNTPPacket(AsyncUDPPacket packet) { |
|
|