ESP32 Learn

NTP Time Sync + DS3231 Fallback

2025-09-18 路 ~1 min read
Table of contents
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
#include <WiFi.h>

#include <time.h>

const char * ssid = "ssid";
const char * pw = "pass";
void setup() {
  Serial.begin(115200);
  WiFi.begin(ssid, pw);
  while (WiFi.status() != WL_CONNECTED) delay(200);
  configTime(0, 0, "pool.ntp.org", "time.nist.gov");
  delay(1000);
  time_t now;
  time( & now);
  Serial.println(ctime( & now));
}
void loop() {}

馃敄 #ntp #rtc #time