Getting rtc time and using this info to label data in sd card

Hi,
I am trying to make a temperature logger using two dallas temp sensors and a sd card module to store the temperature values.
I found a very good working code here (Arduino Temperature Data Logger with SD Card - Simple Projects).
However, this application with be located in a remote location, where no AC power and internet are available.
Since the project will be battery powered I decided to use an ESP32 board which could go into deep sleep to save power (I will read the temperatures every 30min, so that's a HUGE power saving).
I was able to make the necessary changes in the code above to make it work with the DOIT ESP32 DEV KIT board as long as I got the time from the internet.
However I could not make it work using a Dallas DS3231 RTC.
Here is the function I am trying to use to read the time and store it // Function to get date and time from RTC module void getTimeStamp() { formattedDate = time.timestamp(DateTime::TIMESTAMP_FULL); // Extract date int splitT = formattedDate.indexOf("T"); dayStamp = formattedDate.substring(0, splitT); Serial.println(dayStamp); // Extract time timeStamp = formattedDate.substring(splitT+1, formattedDate.length()-1); Serial.println(timeStamp); // for debugging Serial.print(time.hour(), DEC); Serial.print(':'); Serial.print(time.minute(), DEC); Serial.print(':'); Serial.print(time.second(), DEC); Serial.println(); }

Any suggestions will be very appreciated.

Please follow the advice given in the link below when posting code. Use code tags (the </> icon above the compose window) to make it easier to read and copy for examination

Make your life easy and use Epoch times for time calculations and storage.

Hi aarg,
I just need to add a "time stamp" to the line that stores the temperatures as was made on the code I mentioned.
Every attempt I have made so far does not work.
Do I need epoch times?
Would you please give me more details on how to do it?
Thank you

To put it more clearly, I just need to replace the code below with another one that would get the time information from the DS3232.

// Function to get date and time from NTPClient
void getTimeStamp() {
  while(!timeClient.update()) {
    timeClient.forceUpdate();
  }
  // The formattedDate comes with the following format:
  // 2018-05-28T16:00:13Z
  // We need to extract date and time
  formattedDate = timeClient.getFormattedDate();
  Serial.println(formattedDate);

  // Extract date
  int splitT = formattedDate.indexOf("T");
  dayStamp = formattedDate.substring(0, splitT);
  Serial.println(dayStamp);
  // Extract time
  timeStamp = formattedDate.substring(splitT+1, formattedDate.length()-1);
  Serial.println(timeStamp);
}

And I could not find anything that works.

DS3232 or DS3231? You mentioned both. The DS3231 is well supported by both the Jeelabs and the J. Christensen RTC libraries. Pick one and look at the examples that ship with the libraries.

You do not "need" Epoch time. However, it usually simplifies time by about 1000%. All that string manipulation you're doing just blows my mind. If it keeps you happy, okay though...

Are you aware that the ESP32 core has standard C/C++ time extensions? Yes! There may be ESP32 specific RTC libraries as well.

I am sorry for the typo.
It's a DS3231.
I am trying to use the example given in Adafruit RTC library for the DS3131 and I am getting an execution error.
It is probably a very stupid mistake.
The problem is that I have to training in these "new" programming languages, so the programming concepts and language syntax makes not much sense to me.
All my experience in developing and using complex codes were made with FORTRAN IV (yes, I am old)..
Can anyone help?

More likely, the Adafruit code is too processor specific. The ESP heavyweights around here will need more than "getting an execution error". You should always cut and paste a full error listing and post it here literally rather than paraphrasing it.

But, I think some research into the ESP32 specific libraries and native functions will yield many pleasant surprises for you! A lot of Arduino time code was written for the comparatively puny AVR processors in the UNO, Nano, Mega etc. and so is ridden with compromises. That isn't necessary with the ESP32 because it has enough memory and processing power to run what are essentially server apps.

C has a native Time library that has a complete suite of conversions, print routines, etc that would simplify your code enormously because it already does much of what you've coded.

My first language was ZOPL, a C clone. After that, several years of BASIC which I hated. Then assembler and FORTH. I didn't see another real compiler again until Pascal and C started to be available on PC's.

Looking at your code, I am not familiar with the functions you call, but it looks like you are requesting a time string from the system and then picking it apart the fields. I'm sure there is a way to get the time in Epoch format, then you can access fields with standard conversion functions. If you do it this way, substituting an Epoch time from the DS3231 (which is super easy) would be a simple plug in replacement for a time request from the ESP32 native RTC that I think you are querying. It's all about which functions you call, there are many choices offered.

I don't think you really have any other choice, since no DS3231 library is going to provide the time string you are starting with.