SimpleTimer with tons of Timers = Getting Disconnect

I’m using the SimpleTimer library, but I’m having a problem with it… I’ve 5 timers, each timer takes about 0.1 to 0.7 seconds to execute, it’s not enough to disconnect the blynk, the problem is when times matches and they execute all at the same time. So, to execute them all at the same time, it takes about 2-3 seconds, and at this time my blynk disconnects.

My problem:

  • Getting disconnected from blynk when my timers execute at the same time

Things which I tried:

  • I shortened the code (this helped a lot! But didn’t solve my problem)
  • I tried to change the timer to (3, 2, 5 [so, they usually doesn’t matches]) [ Didn’t help ]

I think my problem could be solved if I could make a timer between each Timers, but I don’t know how to do it without changing their respective intervals/sequences.

My timers in Setup:
Timer.setInterval(10000L, Temperatura_Horario);
Timer.setInterval(1800000L, Dimmer);
Timer.setInterval(18000L, DespertadorFuncao);
Timer.setInterval(4000L, Luminosidade);
Timer.setInterval(5000L, Sensores);

Try dividing timers. A you said, you have five of them, so number them and start them separately in the void loop.

So stagger them by odd, but long/short enough ranges…

Timer.setInterval(10010L, Temperatura_Horario);
Timer.setInterval(1800020L, Dimmer);
Timer.setInterval(18030L, DespertadorFuncao);
Timer.setInterval(4040L, Luminosidade);
Timer.setInterval(5050L, Sensores);

Play around with the ranges until you get what you need.

Another solution would be to add in one of the longer ones :slight_smile: at the end of it

I tried that, but the timer doesn’t executes exacly after 4040 millis, it’s the next time after it, so my problem keeps happening… But anyways, I’m changing back to 4040’s. Thanks.

Tried that too! I tried to change in the begin, middle and end of the function, but didn’t work, I think I’ve to spam some “”

Sorry, I doesn’t understand what you meant, can you explain better to me? Thanks.

Blynk has a heart beat time out of 10 seconds which disconnects you if you don’t “talk” to the server. If you get disconnects merely after a 3 sec period I’d guess you are flooding the server with requests

The timers WILL try to run precisely on time… but other circumstances can and will interfere when multiple timers eventually coincide as being called at the same time, thus the odd spacing recommendations.

I have a project running 10 current (and another 4-5 that I kick in when testing)… so I can concur with the fun of juggling them to play nicely together :stuck_out_tongue:

You also need to take into consideration the time it takes a function to process when called… as in will it have the time to complete before a different function is called, etc. These little MCUs are NOT multitasking devices.

Like this.

Than add this:

SimpleTimer timer;
SimpleTimer timer1;
SimpleTimer timer2;
SimpleTimer timer3;
SimpleTimer timer4;

and this:;;;;;

Good to know!! I’m not flooding the server!! Look at my code

void Temperatura_Horario()
  h = dht.readHumidity(); // (DHT22) Umidade
  temp = dht.readTemperature(); // (DHT22) Temperatura
  hic = dht.computeHeatIndex(dht.readTemperature(), h, false); // (DHT22) Sensação Térmica
  myNextion.setComponentText("menuac.t0", String(hic)); // (DISPLAY) Texto Sensação Térmica MenuAC
  myNextion.setComponentText("menuac.t2", String(h)); // (DISPLAY) Texto Umidade MenuAC
  myNextion.setComponentText("menuac.t6", String(temp)); // (DISPLAY) Texto Temperatura MenuAC
  Blynk.virtualWrite(V14, hic); // (BLYNK) Enviar Sensação Térmica
  Blynk.virtualWrite(V16, h); // (BLYNK) Enviar Humidade

Look at this, only 2 writes every 10 seconds, that’s not flooding, right?

Another part of the code

void Luminosidade()
  luminosidade = lightMeter.readLightLevel();
  Blynk.virtualWrite(V10, luminosidade);

@zodiac That was how I first started using timers… but I found out that it was more complicated then required if you have less than 16 timers total.

This method is more a way of having a humongous amount of timers… as each named Blynktimer instance can contain 16 separate timers.

But even named and called that way shouldn’t make much difference in the actual “timing” :stuck_out_tongue_winking_eye: of execution.