#include <ESP32Time.h>
#include <WiFi.h>
#include "time.h"
ESP32Time rtc;
const char* ssid = "Wokwi-GUEST";
const char* password = "";
const char* ntpServer = "it.pool.ntp.org";
const long gmtOffset_sec = 3600;
const int daylightOffset_sec = 0;
void setup() {
Serial.begin(115200);
//rtc.setTime(0, 0, 10, 30, 1, 2025); // 30th Jan 2025 09:00:00
//rtc.setTime(1609459200); // 1st Jan 2021 00:00:00
//rtc.offset = 7200; // change offset value
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected.");
/*---------set with NTP---------------*/
configTime(gmtOffset_sec, daylightOffset_sec, ntpServer);
}
void loop() {
struct tm timeinfo;
if (getLocalTime(&timeinfo)){
Serial.println(&timeinfo, "%A, %B %d %Y %H:%M:%S");
} else {
Serial.println("Errore nel recupero dell'orario NTP!");
}
delay(1000);
}