[SOLVED] SimpleTimer error? Not sure :(

Hey guys, I’m not sure this is a Arduino IDE 1.6.8 fault, Blynk or SimpleTimer. I can’t seem to instanciate simpletimers anymore :frowning:

E.g. this doesn’t work anymore:

SimpleTimer timer;

byte timerInstance1 = timer.setInterval(10000L, doSomethingRoutine);
byte timerInstance2 = timer.setInterval(5000L, doSomethingElseRouting);

At compile it gives me error:

MegaDomo_v0.9:156: error: 'doStuff' was not declared in this scope
 byte timerDoStuffShort  = timer.setInterval(10000L,  doStuff);
                                                      ^

If I put the line behind the routine it appears to work, but the problem is I need to declare the timer instance globally because I turn timers on and off using “timer.disable(timerInstance1);”

Anybody know what I can about this? Because my main home domotics program doesn’t compile anymore and there for I cannot update to the latest Blynk library.

This does work:

#include <SPI.h>
#include <Ethernet.h>
#include <BlynkSimpleEthernet.h>
#include <SimpleTimer.h>

char auth[] = "YourAuthToken";

SimpleTimer timer1;
SimpleTimer timer2;

void sendUptime()
{
  Blynk.virtualWrite(V5, millis() / 1000);
}

void setup()
{
  Serial.begin(9600); // See the connection status in Serial Monitor
  Blynk.begin(auth);
  timer1.setInterval(10000L, sendUptime);
  timer2.setInterval(5000L, sendUptime);
}

void loop()
{
  Blynk.run(); // Initiates Blynk
  timer1.run(); // Initiates SimpleTimer
  timer2.run(); // Initiates SimpleTimer
}

But I’d hate to make a new timer for everything.

The plot thickens …

void dooStuff()
{
  // Fake void to fool timer :(
}

// Timers
byte timerFake          = timer.setInterval(10000L, dooStuff);
byte timerDoStuffShort  = timer.setInterval(10000L,  doStuff);         // Short interval for checking if lights are off
byte timerDoStuffLong   = timer.setInterval(300000L, doStuff);         // Long interval to prevent light from flickering
byte timerCalculate     = timer.setInterval(10000L,  calculateStuff);  // Calculate LDR outcome continiously
byte timerLEDs          = timer.setInterval(1000L,   setLEDs);         // Set LED's every 2 seconds for indicators
byte timerDHT           = timer.setInterval(10000L,  doDHT);           // DHT readings

void setup() 
{
// and all other stuff including timer stuff

This appears to make everything work again :persevere: At least, it doesn’t give errors, but I’m reluctant to upload this to my Mega.

I had a similar problem in my sketch I think. The first declared timer (id = 0) didn’t work, I also worked around with a dummy-timer or fake timer in your code. Then all following timers worked fine.

I just tested it, and it does appear to be like you say. Everything works fine if you add a dummy timer. Weird.

Is this an error in SimpleTimer ? At first it did work in my sketch and maybe I updated the IDE or libraries, I am not sure, but in the end it did not work anymore.

I just upgraded to 1.6.8 and Blynk 0.3.4. I’m highly doubtful it has something to do with Blynk. I’m suspecting something with the compiler in the IDE. It appears that the order in which you add the functions and declarations of the simple timer objects matter more than it used to. But since I’m enabling and disabling timers from said function I can’t declare it after it, but if I declare them before the function I get the error.

Pulling out hairs again, lol, glad we got at least this work around.

I am sure it has nothing to do with Blynk, I had the error in a project with no Blynk involved, just an arduino, temp sensor and a fridge :wink:

I could use a cold one about now, lol. Anyway, I’ll mark it as solved, at least we got a workaround.

@Lichtsignaal what made you upgrade to 1.6.8, out of curiousity?

Use FreeRTOS its way better to controll tasks also a lot more Energy efficient. You should be able to easly understand API

Well, @Costas more or less triggered me. I think he did some extensive testing using this IDE and found no big issues (and he deals with it on a professional basis) so I though I’d upgrade. I went back to 1.6.7 and found the same problem though. So I think it’s a combination of things, but I’m too lazy to find out what. And I only develop small things in and around the house, so it’s no biggie for me. I’m, for now, busy with IoT as a hobby.

Which brings me to @conkerkh, I’ve looked at FreeRTOS but it’s not really my cup of tea from what I can see. It looks, sorry to say, old fashioned and bloated from the looks of their website. It may very well be an excellent product, but their “quickstart” is also not really good. I think I’ll stick to simpler things for now.

Sorry to say but but you are wrong. FreeRTOS has been for years which is why their website looks flaky, but as itself is the most popular way of multitasking with fully customizable scheduler. This is used in professional applications all over the world. Simple Timer is nothing like it😄

As for Costas based he might be working somewhere on projects but by looking what he wrote in different post I would be worried a lot about outcome of this lol…