Comments on: Getting Date and Time with ESP32 on Arduino IDE (NTP Client) https://randomnerdtutorials.com/esp32-ntp-client-date-time-arduino-ide/ Learn ESP8266, ESP32, Arduino, and Raspberry Pi Thu, 25 Jul 2024 13:14:42 +0000 hourly 1 https://wordpress.org/?v=6.8.2 By: Abel https://randomnerdtutorials.com/esp32-ntp-client-date-time-arduino-ide/#comment-941754 Thu, 25 Jul 2024 13:14:42 +0000 http://randomnerdtutorials.com/?p=66810#comment-941754 Hi, can this project be used in the Wi-Fi Manager project (AsyncWebServer library) https://randomnerdtutorials.com/esp32-wi-fi-manager-asyncwebserver/

]]>
By: Sara Santos https://randomnerdtutorials.com/esp32-ntp-client-date-time-arduino-ide/#comment-891496 Thu, 15 Feb 2024 10:43:57 +0000 http://randomnerdtutorials.com/?p=66810#comment-891496 In reply to Dana Bruce Simison.

Hi.
Make sure you use the NTP Client library we mention in the tutorial and follow the suggested installation method.
Regards,
Sara

]]>
By: Dana Bruce Simison https://randomnerdtutorials.com/esp32-ntp-client-date-time-arduino-ide/#comment-889737 Sat, 10 Feb 2024 05:32:42 +0000 http://randomnerdtutorials.com/?p=66810#comment-889737 In reply to Marshall Corry.

Your solution doesn’t address the issue mentioned, that is getFormattedDate() does not exist. I copied your code into the cpp file and still get the same compilation error.

]]>
By: Sara Santos https://randomnerdtutorials.com/esp32-ntp-client-date-time-arduino-ide/#comment-878701 Tue, 19 Dec 2023 10:52:18 +0000 http://randomnerdtutorials.com/?p=66810#comment-878701 In reply to Jackaroo.

Yes. You’re right.
Thanks for the clarification.
Regards,
Sara

]]>
By: Jackaroo https://randomnerdtutorials.com/esp32-ntp-client-date-time-arduino-ide/#comment-878598 Mon, 18 Dec 2023 23:05:13 +0000 http://randomnerdtutorials.com/?p=66810#comment-878598 In reply to Sara Santos.

Hi, Sara,

thank you for answering.

My main point in my comment was that, in the named example code, the main focus is on the representation of the members of “&timeinfo” as char().

For use with MCUs, it is far more common to get the values as numeric int. Although that’s pretty trivial, the tutorial shows how to print the NTP-result as a formatted string, but not how to easily get the values as ints to process them. So if you’re not too familiar with the tm structure, this may seem a bit, say, “complicated”.

Hence the comment.

Thanks again, have nice holidays!

]]>
By: Sara Santos https://randomnerdtutorials.com/esp32-ntp-client-date-time-arduino-ide/#comment-878491 Mon, 18 Dec 2023 10:55:20 +0000 http://randomnerdtutorials.com/?p=66810#comment-878491 In reply to Jackaroo.

Hi.
Yes.
At the beginning of the tutorial, we recommend checking this new tutorial that uses that method: https://randomnerdtutorials.com/esp32-date-time-ntp-client-server-arduino/
Regards,
Sara

]]>
By: Jackaroo https://randomnerdtutorials.com/esp32-ntp-client-date-time-arduino-ide/#comment-878351 Sun, 17 Dec 2023 13:10:58 +0000 http://randomnerdtutorials.com/?p=66810#comment-878351 There’s no need for any additional library, simply load “time.h” like this


//Ok, a quick and brief tutorial upon NTP with Arduino:

//First, in the global section, have

#include "time.h" // we'll need that later on

char Result[8]; // placeholder, string for what we request from NTP

// We use the old "uint" declaration mostly for heritage

uint32_t targetTime = 0; // Universal Counter

uint8_t hh, mm, ss; // We want hours, minutes and seconds in the first place, expand to your demands

// Definitions for the latter to use "configTime" function of "time.h"

const char* ntpServer = "192.168.178.1"; // local NTP-Server in my case, here inside LAN; use any of "pool.ntp.org" a. s. o.
const long gmtOffset_sec = 3600; // CET vs. UTC
const int daylightOffset_sec = 0; // Fiddle around with tzData()

// Core function: "Void()" for being in the global scope

void syncNTP() {
struct tm timeinfo;

// "timeinfo" now is of the strucrure "tm"
// filled with getLocalTime() will provide us with more than we expect

if(!getLocalTime(&timeinfo)){
return; // we don't care: Success on success, fail on fail; next try only 60 min away
}
hh = timeinfo.tm_hour;
mm = timeinfo.tm_min;
ss = timeinfo.tm_sec;
}

void setup(void) {

WiFi.mode(WIFI_STA); //connect WiFi
WiFi.begin(ssid, password);

configTime(gmtOffset_sec, daylightOffset_sec, ntpServer); // Here, our NTP-client role starts off!

targetTime = millis() + 1000;
syncNTP();

}

void loop() {
if (targetTime < millis()) {
targetTime += 1000;
ss++; // Advance second
if (ss==60) {
ss=0;
mm++; // Advance minute
if(mm>59) {
mm=0;
hh++; // Advance hour
if (hh>23) {
hh=0;
}
syncNTP(); // NTP-update hourly, edit for own needs
}
}

sprintf(Result, "%02d:%02d:%02d", hh, mm, ss);
// From here, print/use $Result wherever you want?

}
}

]]>
By: Manfred Prefi https://randomnerdtutorials.com/esp32-ntp-client-date-time-arduino-ide/#comment-856145 Sun, 20 Aug 2023 20:25:55 +0000 http://randomnerdtutorials.com/?p=66810#comment-856145 In reply to Sara Santos.

Hallo,

I have again the same problem with the above mentioned scetch, which worked fine until now, that I just wanted to flash to another boaed.

With the following statement comes an error when compiling:

formattedDate = timeClient.getFormattedDate();

The error message is:

Compilation error: ‘class NTPClient’ has no member named ‘getFormattedDate’; did you mean ‘getFormattedTime’?

I compared again with your code and could not find any discrepancy.
I am working with the same machine and the same libraries.

What could be the reason for this?
Thanks for your help

]]>
By: Sara Santos https://randomnerdtutorials.com/esp32-ntp-client-date-time-arduino-ide/#comment-853618 Sun, 06 Aug 2023 10:00:33 +0000 http://randomnerdtutorials.com/?p=66810#comment-853618 In reply to Manfred Prefi.

Thanks 😀

]]>
By: Manfred Prefi https://randomnerdtutorials.com/esp32-ntp-client-date-time-arduino-ide/#comment-853404 Sat, 05 Aug 2023 16:38:22 +0000 http://randomnerdtutorials.com/?p=66810#comment-853404 In reply to shumifan49.

Hi,
Yes, also I got once at the error message when compiling the suggestion to enter getFormattedTime(…) instead of getFormattedDate(..), but that didn’t work, I got only the time (without date).
My new sketch works now – see my reply to Sara Santos.
Thanks for the answer.
Manfred

]]>