#include "Arduino.h"
#include <WiFi.h>
#include "esp_sntp.h"
void setup() {
const uint32_t syncInterval {3600UL * 1000 };
const int64_t ntpRestartThreshold = 3600LL * 1000000;
const char ssid[] {"Wokwi-GUEST"};
const char password[] {""};
const char ntpServer1[] {"time.nist.gov" };
const char ntpServer2[] {"pool.ntp.org"};
uint8_t attemptsBeforeReset { 5 };
uint8_t retryTest { 0 };
bool resyncNtp {false};
tm *timeinfo;
timeval tv;
time_t now;
Serial.begin(115200);
vTaskDelay(1000);
Serial.print("Connecting to WiFi ");
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
Serial.print(".");
delay(1000);
}
Serial.println(" Connected!");
sntp_set_sync_interval(syncInterval);
configTzTime("EST5EDT,M3.2.0,M11.1.0", ntpServer1, ntpServer2);
Serial.println("Waiting for time synchronization...");
while (time(nullptr) < 100000) {
Serial.print(".");
delay(1000);
}
Serial.println(" Time synchronized!");
time(&now);
timeinfo = localtime(&now);
Serial.printf("Current time: %s", asctime(timeinfo));
}
void loop() {
// Your loop code here
}