[Setup: Arduino Uno IDE 1.8.0, Ethernet Shield 2 with PoE, time sync with router (which itself is on sync with an external time provider), included libraries Time.h and TimeLib.h]
Hi all,
I am currently trying to figure out how to have a function being called once every 5 minutes, but so far the result I have been able to achieve is a far cry from what I need.
The code I am tinkering with is as follows:
void loop()
{
if (minute() - minute(t) >= 5) //doesn't work: keeps running endlessly and
// not once every 5 minutes
{
for(int i = 0; i < 1; i++) //for should run only once when condition
//within if is met
{
syncedTime(); // function I am currently testing with
/*Alternative testing code
Serial.print(minute()); // Returns current minute correctly
Serial.println();
Serial.print(minute(t)); // Returns only zeroes, and hence not the
// minute one expects from now();
Serial.println();
*/
}
time_t t = now();
}
}
With the call to function syncedTime() enabled, this is what I get as a result:
Waiting for sync with Fritz!Box...
Transmit NTP Request
Received NTP Response
Fritz!Box has set the system time!
[22:02:00 / 05-01-2017]
[22:02:00 / 05-01-2017]
[22:02:00 / 05-01-2017]
[22:02:00 / 05-01-2017]
[22:02:01 / 05-01-2017]
[22:02:01 / 05-01-2017]
[22:02:01 / 05-01-2017]
[22:02:01 / 05-01-2017]
Etc. Etc.
Instead of once every two minutes, as specified, I am seeing numerous timestamps per second. When the function call is commented out, and the Serial.print lines are activated, I am getting this:
Waiting for sync with Fritz!Box...
Transmit NTP Request
Received NTP Response
Fritz!Box has set the system time!
6
0
6
0
6
0
6
Etc. etc.
Where Serial.print(minute()) correctly returns the current minute, Serial.print(minute(t)) only returns zeroes. Obviously, the instruction time_t t = now(); doesn't do what I expected it to do. As I am completely stuck on this one, I would much appreciate any leads that would help me getting further.
Thanking you in advance for your time,
Simon