Blynk.run() calls setup code all the time?

I am creating a Drone with Blynk.
Here’s the code.(The actual code is too long so I summarized it into a function called main_loop().
void setup()
{

    M_1.attach(3);
    M_2.attach(9);
    M_3.attach(10);
    M_4.attach(11);
    delay(1000);
    M_1.write(30);
    M_2.write(30);
    M_3.write(30);
    M_4.write(30);
    delay(5000);
    throttle=0;
    normal();
  
 
  pinMode(w_led, OUTPUT);
  
    digitalWrite(w_led, HIGH);

 
  SerialBLE.begin(9600);
  Blynk.begin(SerialBLE, auth);

  //Serial.println("Waiting for connections...");
  //delay(1000);
    digitalWrite(w_led, LOW);
  
   
      led.on();

  Wire.begin();
  mpu.begin();
  mpu.calcGyroOffsets();
  delay(2000);
  while (onoff == 0)
  {
    Blynk.run();
  }
  digitalWrite(w_led, LOW);
  th_1 = 0;
  th_2 = 0;
  th_3 = 0;
  th_4 = 0;
  throttle = 350;
  normal();
  delay(1000);
  led.off();
  c++;
    
}
void loop()
{
  Blynk.run();
  main_loop();
}

According to the code the four motors should first calibrate then the bluetooth will be setup and to indicate that the setup has started the led at D12 will switch on. But, whenever I connect with bluetooth and it starts with the throttle, the motors stop and the led again starts. Any suggestions what is the actually the problem. In my code or that Blynk.run() calls setup().

Why are you calling main_loop(); in your void loop()?

This could be a cause for disconnect and reconnect.

Use timer or interrupt handling. Don’t put code in the void loop.

I am trying what you said

Actually I have another question.
Will this snippet actually work ?
while (onoff == 0)
{
Blynk.run();
}
in setup()

Not sure why you need to do that.

Tell me what you are trying to get it to do.

The code snippet actually waits for a button assigned to variable onoff to see whether it is pressed and as long as it is not pressed the code will be stuck in the loop.

It looks like it will do that. If I assume that onoff state will change with the button.

It’s impossible to tell what is happening, without knowing what is happening in your main_loop function.
However, my guess is that this function is causing Blynk disconnections, or even reboots of your board.

Reading this might help…

When you read this, bear in mind that calling main_loop from your void loop is exactly the same as having the main_loop code within your void loop.

Pete.