Need help with SparkIntervalTimer, pls

First, if this is not the right forum, please feel free to move this thread.

I need some help with interval timer setup and code. I have a garage monitor using photon and I want to send myself a notification if it is left open for more than X minutes.

The way I am trying to do is to use SparkIntervalTimer like the skeleton code below.

#include "SparkIntervalTimer/SparkIntervalTimer.h"

IntervalTimer statusCheckerTimer;        
int checkStatus(String blah);

void setup()
// allocate getStatus to run every 500ms (1000 * .5ms period)
// statusCheckerTimer.begin(getStatus, 2000, hmSec);

void getStatus(void){

As soon as I compile it and flash it onto the device, the device goes offline. In order to do anything else with the device, I have to connect it to computer and re-install the firmware.

I am sure I am doing something wrong in my code, because device does not do that if I comment all of the timer code. Can anyone help this newbie please?

@cheekoo, I am assuming you are compiling on the web IDE. First, I would need to see your code to provide help. Second, SparkIntervalTimer was really designed to fire interrupts at defined intervals. Your requirement is more suited to using a simple millis() based timer or using to do timing instead. :smile:

Thanks for the quick reply!
Yes - I am using web ide.
The way I was planning to implement it was -

void openDoorNotifier(void){
    int status = checkStatus("blah");
    if(status == 0){
        if(previousStatus == "OPEN" || lastButPreviousStatus == "OPEN" ){
            // send notification that it has been open for last 90 minutes!
            shouldAlertVariable = 1;
  "", "Garage door has been open for last 90 minutes!", "Garage door has been open for last 90 minutes!"); 
        lastButPreviousStatus = previousStatus;
        previousStatus = "OPEN";
        Blynk.virtualWrite(virtualPinPreviousStatus, previousStatus);
        Blynk.virtualWrite(virtualPinLastButPreviousStatus, lastButPreviousStatus);
    } else {
        previousStatus = "CLOSED";
        lastButPreviousStatus = "CLOSED";
        Blynk.virtualWrite(virtualPinPreviousStatus, previousStatus);
        Blynk.virtualWrite(virtualPinLastButPreviousStatus, lastButPreviousStatus);
        shouldAlertVariable = 0;

My timer config is -

openDoorNotifierTimer.begin(openDoorNotifier, 3600000, hmSec);

That was the best I could come up with :frowning: Any better ideas?

Ok, so if I understand, you want to run openDoorNotifier every 500ms or so (3600000 hmSec = 500 minutes!!). The best and easiest way is to have a non-blocking timer in loop() that call openDoorNotifier() at that interval like this:

unsigned long openDoorNotifierTimer;

... //other code
openDoorNotifierTimer = millis();

  if (millis() - openDoorNotifierTimer > 500)  // or whatever value in milliseconds
    openDoorNotifierTimer = millis();

That would work for sure. thanks!

We don’t support timers? Coming from Java background, I am so much used to ShceduledThreadPoolExecutor :frowning:
“SparkIntervalTimer” sounded very exciting!

@cheekoo, it is (I wrote it!) but it’s not the best tool for the your job IMO. :wink:

Nice! thanks for writing that. I think it is great!

The SparkIntervalTimer I had in the beginning was the wrong one. I have 2 in my program.

I still think intervalTimer would be best, as I want to check status every 30 minutes, and if it is open for 3 consecutive times, time to send notifications. We can write our own intervalTimer, like you suggested above, or we can re-use your amazing library - SparkIntervalTimer.

What do you say?

@cheekoo, the interrupt service routine you have does a lot of calls to Blynk functions. Having short ISR code is not only good practice but also wise. The current routine does not follow that practice IMO. What you can do is instead of the full code, simply set a flag that you test in loop() to indicate it’s time to run the code. Then simply reset the flag and wait for it again :smile:

1 Like

Sounds good. Will go with that option.

Appreciate your help!

1 Like

A quick update, your solution worked perfectly!
My garage monitor/opener has a bunch of code, is there a place i can share it?

@cheekoo, you can share the entire project on or create a github repo and share it in the “Project Share” category! Good work! :wink:

I came here looking for a timing solution for my project. Which so happens to be a garage door opener too. I wanted to add a door open reminder as well. The best of all I don’t have to remove it to update the code! Thanks.


I like your project! Thanks for sharing.

BTW - have you tried Blynk? I loved it, and dropped my initial idea of doing a webpage, as I was going to use it on my iphones only, and it was pretty easy to set it up, without having to manage my own webserver somewhere.

I did saw it in the article on Make: and even downloaded it. But the author mentioned that if you did not like the idea of have control of your garage in the cloud you could install it on your own server. I used MODX since I have familiarity with it and I could have more control.

For example I can create another user account and give them a new “virtual” key. No software to download and I can set restrictions for time of day or day of week.