I'm no longer a beginner about programming but not a big expert. Especially when it comes to subjects how the Arduino-IDE has organised all the libraries. I have written some small libraries myself and can use them. But I don't have a deep understanding of the possabilites how to "configure" them
For a ESP32-project where I measure temperature-data I added code that connects to a NTP-server syncing time disconnect from the NTP-server and then use the internal ESP32-RTC
This code with time-relaed functions needs to include a file
#include "time.h"
very specific name indeed
The code I found online makes os of some functions to sync and to printout timedata
examples
void printLocalTime(){
struct tm timeinfo;
if(!getLocalTime(&timeinfo)){
Serial.println("Failed to obtain time");
return;
}
Serial.print("Day of week: ");
Serial.println(&timeinfo, "%A");
I want to take a look into all the function this library has
So i looked up my harddisk where do I find "time.h"
there are a lot of files named "time.h".
Even in subfolders related to ESP32 like
C:\Users\Stefan\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.4\tools\sdk\include\newlib\sys
there are multiple files named "time.h"
So how can I find out which "time.h" is used for compiling and how can I find out what other functions for time-setting etc this library has?
When compiling the compiler and linker spits out a lot of processing-data but I don't know if it would be helpful to to take a look into this compiler-output
When compiling the compiler and linker spits out a lot of processing-data but I don't know if it would be helpful to to take a look into this compiler-output
It should tell you exactly which time.h file was used. I assume that you have verbose reporting turned on
Once you know which file was used then you can look into it to see what functions are available
thank you for answering. I have coded for years using delphi so my programming-experience in general is quite good but I'm still almost a novice about the Arduino-IDE and what bells and whistles the Arduino-IDE does have.
Where do I switch on "verbose reporting"
This compiler-log-text is pretty large and has very long lines. If I copy this compiler-log-text to another Texteditor like jedit or ultraedit and search for time.h it does not find any "time.h." so I gues verbose reporting ist still switched off
StefanL38:
Where do I switch on "verbose reporting"
File > Preferences > Show verbose output during: compilation
I can see you already have it turned on.
You can see here the output that tells you the location of the libraries in use:
Bibliothek WiFi in Version 1.0 im Ordner: C:\Users\Stefan\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.4\libraries\WiFi wird verwendet
Bibliothek OneWire in Version 2.3.5 im Ordner: C:\Users\Stefan\Documents\Arduino\libraries\OneWire wird verwendet
Bibliothek DallasTemperature in Version 3.8.0 im Ordner: C:\Users\Stefan\Documents\Arduino\libraries\DallasTemperature wird verwendet
Bibliothek HeartBeat_Blinker_class im Ordner: C:\Users\Stefan\Documents\Arduino\libraries\HeartBeat_Blinker_class (legacy) wird verwendet
Bibliothek nonBlocking_Timer_class im Ordner: C:\Users\Stefan\Documents\Arduino\libraries\nonBlocking_Timer_class (legacy) wird verwendet
Bibliothek PString-Arduino-lib in Version 3.0.2 im Ordner: C:\Users\Stefan\Documents\Arduino\libraries\PString-Arduino-lib wird verwendet
As you noticed, no time.h, because it's not a library.
I'm not sure what the best way is to find this information. I will sometimes add a #warning or #error directive to a file as a quick and dirty way to find out whether that code is being compiled.
As pert said, "time.h" is not part of any Arduino library, it's a part of the C library. See Date and time utilities - cppreference.com. The ESP32 Core uses Newlib as its C library implementation.
Arduino sketches use C++, so if you should probably be using std::chrono to handle dates and time: Date and time utilities - cppreference.com
To see the hierarchy of all included headers and their location on disk, you can add the -H to the compile command in ~/.arduino15/packages/esp32/hardware/esp32/1.0.4/platform.txt:
thank you very much for this deep insight. I don't know how many years it will take for me to dive that deep into the toolchain. So now the compile-log lists three files time.h.
I guess it will be easier to search for a time-library which has a directly documented API instead of crawling through these files and its hierarchy
So the functionality I would like to have is:
connect to a NTP-server
if connection to NTP-server is not possible get date-time-information from somewhere else
and setup ESP32-RTC to that timedata.
I'm not married to this deep down nested time.h. I'm open to any other library that can set and retrieve time-data from the ESP32-RTC.
If anyone has a suggestion for an easy to use and well documented Time-library please post a hint or a link.
StefanL38:
I guess it will be easier to search for a time-library which has a directly documented API instead of crawling through these files and its hierarchy
The C library's time functions are well documented. I even posted a link to the documentation:
If you use an full-featured IDE like Eclipse / Sloeber, you can track down and step into definitions for #inlcude files, variables, functions, classes, etc with a simple right-click of your mouse.
uh wow! Lot's of information. Thank you for posting the links. The ESP32-RTC-link seems to fully document the ESP32-RTC-API.
I can crawl through this documentation - sure. I don't want to sound egoistic. If somebody has an example code handy (=1 minute to copy & paste the link) I want to ask once more. If nobody has a link handy - no problem at all.
Does anybody have a demo-code **handy ** that shows how to
set day month year,
set hour minute, second
of the ESP32-RTC?
best regards Stefan
The ESP32's "RTC" isn't a realtime clock in the usual sense unfortunately. It's just a counter a bit like millis() that keeps ticking away, even in sleep mode. It doesn't really do hours or minutes like a DS3231 or suchlike.
I wish they didn't call it an RTC because it misleads a lot of people.
To set time, settimeofday POSIX function can be used. It is used internally in LwIP SNTP library to set current time when response from NTP server is received.