Skip to content

Instantly share code, notes, and snippets.

@stevenshy
Created January 31, 2018 15:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stevenshy/4af22e853d0f98f41bca58ebc496a08a to your computer and use it in GitHub Desktop.
Save stevenshy/4af22e853d0f98f41bca58ebc496a08a to your computer and use it in GitHub Desktop.
#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