How to change SimpleTimer timer interval remotely?

Step 1.
You need a global variable so that you can easily track your timer by using its ID

int timerID;

Step 2.
In your function where you call setInterval do like this

timerID = timer.setInterval(interval, notifyUptime);

Step 3.
In your “change interval” function delete the existing then create a new one.

timer.deleteTimer(timerID);
// set new interval
timerID = timer.setInterval(interval, notifyUptime); // now contains new interval
8 Likes