Created
January 31, 2018 15:50
-
-
Save stevenshy/4af22e853d0f98f41bca58ebc496a08a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <WiFi.h> | |
#include <NTPClient.h> | |
#include <WiFiUdp.h> | |
#define NTP_OFFSET -3 * 60 * 60 // In seconds | |
#define NTP_INTERVAL 60 * 1000 // In miliseconds | |
#define NTP_ADDRESS "0.pool.ntp.org" | |
WiFiUDP ntpUDP; | |
NTPClient timeClient(ntpUDP, NTP_ADDRESS, NTP_OFFSET, NTP_INTERVAL); | |
const char* ssid = "xxxxxxxxxx"; // INSERT YOUR OWN WIFI SSID > replace "xxxx" > example "seven@unifi" | |
const char* password = "xxxxxxxx"; // INSERT YOUR OWN WIFI PASS > replace "xxxx" > example "seven123" | |
void setup() | |
{ | |
Serial.begin(115200); | |
WiFi.begin(ssid, password); | |
while (WiFi.status() != WL_CONNECTED) | |
{ | |
delay(500); | |
Serial.println("Connecting to WiFi.."); | |
} | |
Serial.println("Connected to the WiFi network"); | |
Serial.println("IP address: "); | |
Serial.println(WiFi.localIP()); // show IP ADDRESS | |
timeClient.begin(); | |
} | |
void loop() | |
{ | |
timeClient.update(); | |
String formattedTime = timeClient.getFormattedTime(); | |
Serial.println(formattedTime); | |
delay(1000); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment