Problem with calling function once every x minutes
[setup: arduino uno ide 1.8.0, ethernet shield 2 poe, time sync router (which on sync external time provider), included libraries time.h , timelib.h]
hi all,
i trying figure out how have function being called once every 5 minutes, far result have been able achieve far cry need.
the code tinkering follows:
with call function syncedtime() enabled, result:
waiting sync fritz!box...
transmit ntp request
received ntp response
fritz!box has set 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 2 minutes, specified, seeing numerous timestamps per second. when function call commented out, , serial.print lines activated, getting this:
waiting sync fritz!box...
transmit ntp request
received ntp response
fritz!box has set system time!
6
0
6
0
6
0
6
etc. etc.
where serial.print(minute()) correctly returns current minute, serial.print(minute(t)) returns zeroes. obviously, instruction time_t t = now(); doesn't expected do. stuck on one, appreciate leads me getting further.
thanking in advance time,
simon
hi all,
i trying figure out how have function being called once every 5 minutes, far result have been able achieve far cry need.
the code tinkering follows:
code: [select]
void loop()
{
if (minute() - minute(t) >= 5) //doesn't work: keeps running endlessly and
// not once every 5 minutes
{
for(int = 0; < 1; i++) //for should run once when condition
//within if met
{
syncedtime(); // function testing with
/*alternative testing code
serial.print(minute()); // returns current minute correctly
serial.println();
serial.print(minute(t)); // returns zeroes, , hence not the
// minute 1 expects now();
serial.println();
*/
}
time_t t = now();
}
}
with call function syncedtime() enabled, result:
waiting sync fritz!box...
transmit ntp request
received ntp response
fritz!box has set 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 2 minutes, specified, seeing numerous timestamps per second. when function call commented out, , serial.print lines activated, getting this:
waiting sync fritz!box...
transmit ntp request
received ntp response
fritz!box has set system time!
6
0
6
0
6
0
6
etc. etc.
where serial.print(minute()) correctly returns current minute, serial.print(minute(t)) returns zeroes. obviously, instruction time_t t = now(); doesn't expected do. stuck on one, appreciate leads me getting further.
thanking in advance time,
simon
can share minute() , now() functions?
Arduino Forum > Using Arduino > Programming Questions > Problem with calling function once every x minutes
arduino
Comments
Post a Comment