Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update TimeNTP_ESP8266WiFi.ino #96

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 11 additions & 20 deletions examples/TimeNTP_ESP8266WiFi/TimeNTP_ESP8266WiFi.ino
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include <TimeLib.h>
#include <ESP8266WiFi.h>
#include <WiFiUdp.h>

char buffer[10];
const char ssid[] = "*************"; // your network SSID (name)
const char pass[] = "********"; // your network password

Expand Down Expand Up @@ -67,35 +67,26 @@ void loop()
if (timeStatus() != timeNotSet) {
if (now() != prevDisplay) { //update the display only if time has changed
prevDisplay = now();
digitalClockDisplay();
printDigitalClock();
printDigitalDate();
Serial.println();
}
}
}

void digitalClockDisplay()
void printDigitalClock()
{
// digital clock display of the time
Serial.print(hour());
printDigits(minute());
printDigits(second());
Serial.print(" ");
Serial.print(day());
Serial.print(".");
Serial.print(month());
Serial.print(".");
Serial.print(year());
Serial.println();
sprintf(buffer, " %02d:%02d:%02d", hour(), minute(), second());
Serial.print(buffer);
}

void printDigits(int digits)
void printDigitalDate()
{
// utility for digital clock display: prints preceding colon and leading 0
Serial.print(":");
if (digits < 10)
Serial.print('0');
Serial.print(digits);
// digital clock display of the time
sprintf(buffer, " %02d.%02d.%04d", day(), month(), year());
Serial.print(buffer);
}

/*-------- NTP code ----------*/

const int NTP_PACKET_SIZE = 48; // NTP time is in the first 48 bytes of message
Expand Down