I tried to use a ticker to trigger an action in 1 or more hours.
If I use timerEndTimer.attach_ms(onTime*3600000, triggerTimerEnd); it works as long as onTIme is 1 (hour). If I set onTime to 2 (hours) or more the function triggerTimerEnd is never called.
Arduino IDE 1.6.7
Board esp8266 by ESP8266 Community version 2.2.0
Hardware Adafruit HUZZAH ESP8266
Code extract that fails if trigger time is > 1 hour:
#include <Ticker.h>
/**
triggerTimerEnd
called by Ticker timerEndTimer
sets flag timerEndTriggered to true for handling in loop()
will initiate switching off the aircon after programmed hours
*/
void triggerTimerEnd() {
timerEndTriggered = true;
}
void setup() {
.....
}
void loop() {
.....
// Start timer to switch off the aircon after "onTime" (default = 1 hour = 60mx60s+1000ms=3600000 milliseconds)
timerEndTimer.attach_ms(onTime*3600000, triggerTimerEnd); // Doesn't work if more than an hour
.....
}
Code workaround to get it running:
#include <Ticker.h>
void triggerTimerEnd() {
timerCounter++;
if (timerCounter == onTime) {
timerEndTriggered = true;
timerCounter = 0;
}
}
void setup() {
.....
}
void loop() {
.....
// Start timer to switch off the aircon after "onTime" (default = 1 hour = 60mx60s+1000ms=3600000 milliseconds)
timerEndTimer.attach_ms(3600000, triggerTimerEnd);
.....
}
The workaround just uses a counter to check if the requested amount of time has passed. This works of course only in my case and if the trigger times are multiples of 1 hour.
More detailed code examples attached:
Full source code available on:
Github repository