Help with Simpletimer

I need help for simple timer, I have a function that run in fixed interval

void do_something() {

But I need to run this function when only connected to blynk server but I don’t know how to implement to code -> timer.enable(x). Or do something else like that ?

void setup(){
 x = timer.setinterval(3000L, do_something);

I didn’t write any blynk.begin() or config for this thread

I found that from blynk web example;

void loop(){
If (connect2blynk) {;
} else {

Is my logic is correct or not !

There is a bug in SimpleTimer which causes the first timer that’s initialised to behave strangely when it’s deleted. This has an impact on any other timers, as they can then have their index corrupted. I can’t remember if this also affects disabling and enabling the first timer or not.
This bug is fixed in BlynkTimer, and the number of timer instances for one timer object is increased (to 16 if I remember correctly), so you’re far better using BlynkTimer.

If you have no choice but to use SimpleTimer then you can create a dummy timer instance, which will be allocated the index of 0, and never use this timer.
Documentation for SimpleTimer is here:

BlynkTimer uses the same syntax and functionality, with the enhancements I mentioned earlier.


@Gunner said there is the same bug with BlynkTimer
When did they fixed it ? I missed that information.
I always use a dummy timer :thinking:

So what actually timer.disable() function really does, my goal is to execute do_something() function when only connected to blynk because reading/writing function senseless when it not connected to blynk server also create unnecessary traffic in local network

Have you read the documentation I linked to?


1 Like

Thanks @PeteKnight I did it…