Skip to content

Commit

Permalink
Update WiFi_getTime.ino
Browse files Browse the repository at this point in the history
  • Loading branch information
tigoe committed Dec 14, 2023
1 parent 45bbcd4 commit 1f4416f
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions WiFi_getTime/WiFi_getTime.ino
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
WiFiUDP Udp;
// local port to listen for UDP packets
const int localPort = 2390;
unsigned long epoch = 0;

void setup() {
// initialize serial:
Expand All @@ -52,9 +51,9 @@ void loop() {
// get the time. Use this for the WiFiNINA lib:
// epoch = WiFi.getTime();
// get the time. Use this for the other libs:
epoch = getTime();
delay(10000);
unsigned long epoch = getTime();
Serial.println(epoch);
delay(5000);
}

void connectToNetwork() {
Expand All @@ -75,7 +74,6 @@ void connectToNetwork() {
Serial.println(WiFi.RSSI());
}


// send an NTP request and wait for the result:
unsigned long getTime() {
// NTP timestamp packet is 48 bytes:
Expand Down Expand Up @@ -104,7 +102,7 @@ unsigned long getTime() {
unsigned long result = 0;
for (byte b = 40; b < 44; b++) {
// move the current value left 8 bits, and add the next byte:
result = (result << 8) + packetBuffer[b];
result = (result << 8) | packetBuffer[b];
}
// subtract the time since 1900:
result = result - SEVENTY_YEARS;
Expand Down

0 comments on commit 1f4416f

Please sign in to comment.