how to go about scheduling a daily task!?

hello. i have nodeMCU on internet and retrieve time signal from time.nist.gov and send data to iot service with succes. how to make Arduino do certain thing every day at midnight!?

Check the time?

yes i figured that much but what line to pursue!? i have read a lot about it and it is mostly about millis which drift as i gather. also many projects are with a battery powered clock chip that is set on upload of code! this i get from online...!?

The Time Library (TimeLib.h) contains a function called setSyncProvider which adjusts the millis() based clock to an external time reference at periodic intervals. The default synchronization is every five minutes. It will allow you to get accurate time from the Time Library with no drift.

Check out the example in the Time library (TimeLib.h) TimeNTP_ESP8266WiFi which demonstrates linking to a timer server for the sync. It's analagous to the standard Time Library sketch TimeNTP which connects to the time server over ethernet.

If you wanted you could also use the TimeAlarms library. It is an extension of the Time Library and it enables you to set up and call functions at specified times.

cattledog:
The Time Library (TimeLib.h) contains a function called setSyncProvider which adjusts the millis() based clock to an external time reference at periodic intervals. The default synchronization is every five minutes. It will allow you to get accurate time from the Time Library with no drift.

Check out the example in the Time library (TimeLib.h) TimeNTP_ESP8266WiFi which demonstrates linking to a timer server for the sync. It's analagous to the standard Time Library sketch TimeNTP which connects to the time server over ethernet.

If you wanted you could also use the TimeAlarms library. It is an extension of the Time Library and it enables you to set up and call functions at specified times.

thank you for kind reply.. karma for you :slight_smile:
i have the example running and i pretty much see how it works. i think i might be overkill though with a lot of code and packages that are not needed.

my project sends data to thingspeak every minute right now. i need to reset a variable every day at midnight. i was thinking something like downloading the time every time i send data and then use something 'if' to see if retrieved time is 00:00:xx if i set send interval to 50s i'm sure to get 00:00 every time. sometimes i might get two but that is not an issue.

is it possible to run an if after
time_t getNtpTime(); !?

it would save a lot of code and traffic

Rosaline:)

is it possible to run an if after
time_t getNtpTime(); !?

That's a function prototype, so the basic answer is no.

You can use a call to getNtpTime to get a time_t, use the hour from that and compare with midnight.

At midnight, do what needs to be done, set a flag that it is done and clear that flag at one o'clock.