Hi,
I can't understand how to use this function. somehow it is referenced to 1970 but when I try to convert 3 days into seconds it doesn't give me the expected number 259200.
My code is 150 lines long so the important part is:
tmElements_t wateringInterval = {0,0,0,4,1,1970}; // days between waterings (3) in seconds
time_t a = makeTime(wateringInterval);
Serial.println("watering interval ");
Serial.println(a);
the number in a I get is 1007251200.
How is the number I get calculated by the function?
How do I use makeTime to calculate the seconds in 3 days?
Is there a better way to get the seconds in a given time span with this library?
Two problems:
There are seven elements to a tmElements_t, (second, minute, hour, weekday, day, month, year), so there needs to be a dummy value for weekday.
Year is referenced to 1970, so you need to subtract 1970, or use CalendarYrToTM() which does the subtraction for you.
Note that there is also a fixed definition of SECS_PER_DAY in the library, which is a little easier to use in this case.
tmElements_t wateringInterval = {0, 0, 0, 0, 4, 1, CalendarYrToTm(1970)}; // days between waterings (3) in seconds
time_t a = makeTime(wateringInterval);
Serial.println("watering interval ");
Serial.println(a);
time_t b = 3 * SECS_PER_DAY; //calculates number of seconds in three days
Serial.println(b);
Thanks David, I wasn’t aware of that option and I’ll use it as I want to be able a user to select how many days the system waits before alarming to water the plants.
The help is greatly appreciated!