From a9929670799666e239cbd1db006246dcc0a0bbfe Mon Sep 17 00:00:00 2001 From: Me No Dev Date: Wed, 19 Jun 2024 09:55:54 +0300 Subject: [PATCH] fix(time): Fix SimpleTime to also use DHCP (#9886) --- .../examples/Time/SimpleTime/SimpleTime.ino | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/libraries/ESP32/examples/Time/SimpleTime/SimpleTime.ino b/libraries/ESP32/examples/Time/SimpleTime/SimpleTime.ino index 8c76f15d483..d82e5f2977d 100644 --- a/libraries/ESP32/examples/Time/SimpleTime/SimpleTime.ino +++ b/libraries/ESP32/examples/Time/SimpleTime/SimpleTime.ino @@ -33,14 +33,6 @@ void setup() { // First step is to configure WiFi STA and connect in order to get the current time and date. Serial.printf("Connecting to %s ", ssid); WiFi.begin(ssid, password); - while (WiFi.status() != WL_CONNECTED) { - delay(500); - Serial.print("."); - } - Serial.println(" CONNECTED"); - - // set notification call-back function - sntp_set_time_sync_notification_cb(timeavailable); /** * NTP server address could be acquired via DHCP, @@ -52,6 +44,15 @@ void setup() { */ esp_sntp_servermode_dhcp(1); // (optional) + while (WiFi.status() != WL_CONNECTED) { + delay(500); + Serial.print("."); + } + Serial.println(" CONNECTED"); + + // set notification call-back function + sntp_set_time_sync_notification_cb(timeavailable); + /** * This will set configured ntp servers and constant TimeZone/daylightOffset * should be OK if your time zone does not need to adjust daylightOffset twice a year,