Need help with timer structure

hi all,

i am asking to make sure about my understanding. this code runs on esp32. powered with usb cable nothing else connected. board library version 2.0.17. blynk version 1.3.2
i want to update around 40-50 data. they are not that time critical.
i choose this strategy:
i have 5 timer. they start executing after 5 sec. also they have 1 sec delay between them.
basically;
sec: 1 2 3 4 5 6 7 8 9 10 11
timer: a b c d e a b c d e a

do you think that this code structure okay for blynk(without disconnect, flood error, hearthbeat timeout)?
what should be my BLYNK_HEARTBEAT if i use wifi or gsm ?
What would you do if something was wrong or to make the code structure better?

#define BLYNK_PRINT Serial
#define BLYNK_DEBUG
#define BLYNK_TEMPLATE_ID "****"
#define BLYNK_TEMPLATE_NAME "*****"
#define BLYNK_AUTH_TOKEN "*****"

#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>

char ssid[] = "***";
char pass[] = "***";
BlynkTimer timer;
int s;
int s1;
int s2;
int s3;
int s4;
int s5;
int s6;
int s7;
int s8;
int s9;
int s10;
int s11;
int s12;
int s13;
int s14;
int s15;
int s16;
int s17;
int s18;
int s19;
int s20;
int s21;
int s22;
int s23;
int s24;
int s25;
int s26;
int s27;
int s28;
int s29;
int s30;
int s31;
int s32;
int s33;
int s34;
int s35;
int s36;
int s37;
int s38;
int s39;

void a()
{
  //  later some reading calculation 
  Serial.println("aaaaaaaaaaaaaaaaaaaaaa"); //test
  s = random(0,100);
  s1 = random(0,100);
  s2 = random(0,100);
  s3 = random(0,100);
  s4 = random(0,100);
  s5 = random(0,100);
  s6 = random(0,100);
  s7 = random(0,100);
  Blynk.virtualWrite(V0, s);
  Blynk.virtualWrite(V1, s1);
  Blynk.virtualWrite(V2, s2);
  Blynk.virtualWrite(V3, s3);
  Blynk.virtualWrite(V4, s4);
  Blynk.virtualWrite(V5, s5);
  Blynk.virtualWrite(V6, s6);
  Blynk.virtualWrite(V7, s7);
  Serial.println("aaaaaaaaaaaaaaaaaaaaaaaaaaaa"); //test
}

void b()
{
// later some reading calculation 
  Serial.println("bbbbbbbbbbbbbbbbbbbbbbbbbbbbb"); //test
  s8 = random(0,100);
  s9 = random(0,100);
  s10 = random(0,100);
  s11 = random(0,100);
  s12 = random(0,100);
  s13 = random(0,100);
  s14 = random(0,100);
  s15 = random(0,100);
  Blynk.virtualWrite(V8, s8);
  Blynk.virtualWrite(V9, s9);
  Blynk.virtualWrite(V10, s10);
  Blynk.virtualWrite(V11, s11);
  Blynk.virtualWrite(V12, s12);
  Blynk.virtualWrite(V13, s13);
  Blynk.virtualWrite(V14, s14);
  Blynk.virtualWrite(V15, s15);
  Serial.println("bbbbbbbbbbbbbbbbbbbbbbbbbb");//test
}

void c()
{ 
// later some reading calculation 
  Serial.println("ccccccccccccccccccccccccccccccc"); //test
  s16 = random(0,100);
  s17 = random(0,100);
  s17 = random(0,100);
  s19 = random(0,100);
  s20 = random(0,100);
  s21 = random(0,100);
  s22 = random(0,100);
  s23 = random(0,100);
  Blynk.virtualWrite(V16, s16);
  Blynk.virtualWrite(V17, s17);
  Blynk.virtualWrite(V18, s18);
  Blynk.virtualWrite(V19, s19);
  Blynk.virtualWrite(V20, s20);
  Blynk.virtualWrite(V21, s21);
  Blynk.virtualWrite(V22, s22);
  Blynk.virtualWrite(V23, s23);
  Serial.println("ccccccccccccccccccccccccccccccccccccc"); //test
}

void d()
{ 
// later some reading calculation 
  Serial.println("dddddddddddddddddddddddddddddd"); //test
  s24 = random(0,100);
  s25 = random(0,100);
  s26 = random(0,100);
  s27 = random(0,100);
  s28 = random(0,100);
  s29 = random(0,100);
  s30 = random(0,100);
  s31 = random(0,100);
  Blynk.virtualWrite(V24, s24);
  Blynk.virtualWrite(V25, s25);
  Blynk.virtualWrite(V26, s26);
  Blynk.virtualWrite(V27, s27);
  Blynk.virtualWrite(V28, s28);
  Blynk.virtualWrite(V29, s29);
  Blynk.virtualWrite(V30, s30);
  Blynk.virtualWrite(V31, s31);
  Serial.println("dddddddddddddddddddddddddddddddd"); //test
}
void e()
{
  // later  some reading calculation 
  Serial.println("eeeeeeeeeeeeeeeeeeeeeeeeeeeeeee"); //test
  s32 = random(0,100);
  s33 = random(0,100);
  s34 = random(0,100);
  s35 = random(0,100);
  s36 = random(0,100);
  s37 = random(0,100);
  s38 = random(0,100);
  s39 = random(0,100);
  Blynk.virtualWrite(V32, s32);
  Blynk.virtualWrite(V33, s33);
  Blynk.virtualWrite(V34, s34);
  Blynk.virtualWrite(V35, s35);
  Blynk.virtualWrite(V36, s36);
  Blynk.virtualWrite(V37, s37);
  Blynk.virtualWrite(V38, s38);
  Blynk.virtualWrite(V39, s39);
  Serial.println("eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee");
}

BLYNK_WRITE(V13)
{ 
  if(param.asInt() == 1)
  {
    Serial.println("swswswswswswswswswswswsw");
  }
  else
  { 
    Serial.println("swswswswswswswswswswswsw");
  }
}
void setup()
{
  Serial.begin(115200);


Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);

  timer.setTimeout(1000, []() {
    timer.setInterval(5000L, a);
  });
  timer.setTimeout(2000, []() {
    timer.setInterval(5000L, b);
  });
  timer.setTimeout(3000, []() {
    timer.setInterval(5000L, c);
  });
  timer.setTimeout(4000, []() {
    timer.setInterval(5000L, d);
  });
  timer.setTimeout(5000, []() {
    timer.setInterval(5000L, e);
  });
}

void loop()
{
  Blynk.run();
  timer.run();
}

I don’t think this I’d going to work the way you expect, because timer.run() isn’t being executed when this code is executed.
You should put a normal blocking delay() between initialising your timeout timers to get the desired effect.

Pete.

Hi pete,
Thanks for reply.

are you suggesting this?

 timer.setInterval(5000L, a);
  delay(1000);
  timer.setInterval(5000L, b);
  delay(1000);
  timer.setInterval(5000L, c);
  delay(1000);
  timer.setInterval(5000L, d);
  delay(1000);
timer.setInterval(5000L, e);
  delay(1000);

Yes.

Pete.

what do you think about 1 sec delay? too low too high ? suggesting better method?
each virtualwrite takes around 70-90ms(checked with serialprints). to be in safe region i divided 40 data into 5 timer function and gave each one 1 sec to complete.

With 5 second interval timers you can’t have more than 1 second delay between the 5 timers.
The last delay is irrelevant BTW.

Pete.