Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#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
You can’t perform that action at this time.