Blynk fail to recconect to the server after some time

hello ,
This is my code:
bool result = Blynk.connected();
if(result){
Blynk.run();
Serial.println(“BLYNK connected”);
}
else{
Blynk.disconnect();
Blynk.config(auth);
Blynk.connect(3333);
Serial.println(“BLYNK connecting”);
}

Blynk fails to reconnect to the server.I think blynk.connect command is not working properly

better use @Gunner example

Blynk.connected(); giving wrong result even if it is not connected to the internet that is why it’s not trying to make a connection to the blynk server

Sir , I am using esp32 board

You code looks like a random snippet that doesn’t do us any real good. Where are you running this code, what else is happening in the sketch… ands so on.

It works perfectly for hundreds/thousands of other users… but only if utilised properly in code.

Look thoroughly through the examples already given… the basic concepts work regardless of ESP8266, ESP32, Arduino, WiFi, GSM, Ethernet, Serial, etc.

  • Do stuff
  • Check if connected, if so do stuff
  • If not, keep doing stuff but start attempting reconnection at pre selected intervals
  • Repeat
1 Like

I have used FREERTOS and created task base system. Following program is one of the task where it maintains connection between esp32 and blynk server.This logic works fine when there is no problem with internet connection. If the device is not connected to the server, it will make a connection after 30 sec. I have given the authentication code in setup function using Blynk.config(auth, server, port); . Sometimes it works sometime its not. It is only showing "Blynk connecting " message on the screen but its not actually trying to reconnect.

void blynk_con(void * pvParameters)
{
   while(true)
    {
      if(WiFi.status()== WL_CONNECTED&&flagw==1)
      {
         bool result =  Blynk.connected();
         if(result==true){
         Blynk.run(); 
         Serial.println("BLYNK connected"); 
         }
         else{
            delay(30000);
            Blynk.connect();
            Serial.println("BLYNK connecting");   
         }
        
      }
      delay(500);
    }
}

Don’t forget to format posted code…

Blynk%20-%20FTFC