How to manage reconnection with Blynk.Edgent as well as with old blynk?

Hi,
With old Blynk 1.0 i used to manage connection in case of issues with some commands like Blynk.connected() to test and Blynk.config() to reconnect. I was wondering if it was possible to do as well with new Blynk 2.0 and the BlynkEdgent library ? This function is important for me in order to manage an automatic reconnection, in case of loss of blynk server or loss of the wifi of the box, which happens regularly …
See below an extract of my actual reconnection program. Can the same commands be used with BlynkEdgent ? I haven’t seen any examples for this.

Thanks

void CheckConnection() // Fonction appelée régulièrement pour vérifier si connexion OK. Si NOK, on relance une connexion ==> appel connectWifi()
{
  Connected2Blynk = Blynk.connected();
  if (!Connected2Blynk) 
  {
    connectWifi();
  }
}

void connectWifi() // Lance la connexion wifi et la connexion au serveur de l'application Blynk
{
  unsigned long blynkTimeout = 4000;    // Temps donné pour la connexion
  unsigned long blynkStart = millis();

  Serial.println("Connecting Wifi/Blynk");

  while (!Blynk.connected())
  {
    WiFi.begin(ssid, pass);
    Blynk.config(auth);
    Blynk.connect(); 

    if (millis()>blynkStart+blynkTimeout) break;
  }

  Connected2Blynk = Blynk.connected();

  if (Connected2Blynk)
  {
    envoiMail("Reconnexion après déconnexion longue !");
  }
}

Yes use BLYNK_COMNNECTED

Hello,
I think that BLYNK_CONNECTED don’t work if you have already lost the blynk server connection ! So, that’s the reason ok my development in old Blynk…
Ok but my question was … In case of disconnection how can i detect it and reconnect ? In my script (blynk 1.0 library) i checked with blynk.connected() and reconnected with blynk.config() in case of a lost connection. So to be clear, is it possible to do that with the same or others commands with blynk 2.0 and blynkEdgent library ?
Does anyone have a concrete example ?
Thanks :wink:

BLYNK_CONNECTED is a callback function that is triggered once when the device either connects or re-connects to the Blynk server.
It has no role in connection management.

@gacaron have you tried doing any tests with the latest Edgent examples for your particular device?
The examples seem to contain some re-connection routines already.

Pete.

Hello Pete,
No i haven’t done any test. I just want to know the best way to manage my issues before to migrate my application to blynk 2.0
I think that it is possible to use my old <BlynkSimpleEsp32.h> library to keep the benefits of my scripts ? It is important to manage an automatic re-connection because i noticed with old blynk that sometimes blynk.run (in loop) wasn’t active anymore and so a complete reconnection was mandatory.
We don’t have any precision for that at yet …

I don’t really understand the question, but you need to be using the latest versions of the Blynk library files with Blynk 2.0

I think that should be your first step, using the latest version of the Blynk library and latest examples, direct from the GitHub site rather than the version that is installed via the Arduino IDE.

Pete.

Thanks ! I will return my conclusion when i had done my migration. Unfortunately, i have not enough time at yet, so it will be done in a few weeks , … i hope so :wink: