Program on ESP Board stop in sartup if Blynk is not connected```

Hello my Blynk friends.

If made a programm on ESP for Homeautomation.
Everything is working well.
Now I test some failure cases which could be.
One of them is, that on Start up, no WLAN is available.
The Other test case, is if Blynk server is down or do not can reach.

For WLan only , this if have on my Sketch insert and It works well.
So if WLAN is not available, I get a measage on screen and the programm
goes further in Startupsequence in Sketch
After Wlan is connected and availabe I go to connect to Blynk.
And there I see, if Blynk connection do not come together, the Programm stops here and
go not further. It looks like it was waiting.and waiting and waiting…

I test this in that wise , that I make for a try, an emulate “no Blynk connection” by set a wrong Token.

So the Question is:
How can I make it , that my Programm see that there is no Blynk connection and
goes further in programm sequence and do not “stop”.

Unlucky I do not can see on Serial Monitor, because I Have this Pins on my Hardware for Leds
and Watchdog…

Here is the Part in void setup() , where I be after all Init´s and so on and after a stable Wlan Connection.
For better understanding, i is the value for 20 tryings to connect Wlan.
It “stops” or “hang up” or “wait” for sure on : Blynk.begin(auth, ssid, pass); // new Blynk IOT

if (i >=20 )                          // Anzeige , wenn nach 20 Versuchen keine WLAN Aufbau    
    {   
      u8g2.setFont(u8g2_font_courB10_tf);
      u8g2.setCursor(0, 10);
      u8g2.clearBuffer();
      u8g2.println("No WLAN ");
      u8g2.setCursor(0, 30);
      u8g2.println("----");
      u8g2.setCursor(0, 50);
      u8g2.println("Connection");
      u8g2.sendBuffer();
      u8g2.clearBuffer(); 
      delay(800);
    }
      else 
      {
      Blynk.begin(auth, ssid, pass);    // new Blynk IOT
      }
      
      delay(800);
      bool result = Blynk.connected();  
      
      if (result == false)              // damit Programm nicht hängt, wenn Bynk am Anfang nicht vorhanden ist.
      {
      u8g2.setFont(u8g2_font_courB10_tf);
      u8g2.setCursor(0, 10);
      u8g2.clearBuffer();
      u8g2.println("No Blynk");
      Blynk.disconnect();
      delay(800);
´´´

Blynk.begin is a blocking function.
It tries to connect to WiFi and then to the Blynk server. If either fails then code execution will stop.

If you search the forum for “Blynk.config” you will see many discussions about how to use Blynk.config and Blynk.connect instead of Blynk.begin to allow your device to run when offline.

Pete.

Good morning Pete,
you are the “good fairy” and the magician of this forum.
Thank you for the super quick help.
I can read now by myself …

Pete, thanks for your hint.
Now it works fine.
For all other …here is the simple solution for my case.

if (i >=20 )                          // Anzeige , wenn nach 20 Versuchen keine WLAN Aufbau    
    {   
      u8g2.setFont(u8g2_font_courB10_tf);
      u8g2.setCursor(0, 10);
      u8g2.clearBuffer();
      u8g2.println("No WLAN ");
      u8g2.setCursor(0, 30);
      u8g2.println("----");
      u8g2.setCursor(0, 50);
      u8g2.println("Connection");
      u8g2.sendBuffer();
      u8g2.clearBuffer(); 
      delay(800);
    }
      else 
      {
      //Blynk.begin(auth, ssid, pass);    // Blynk.begin hängt wenn kein Blynk verfügbar ist.
                                          // Deswegen Blynk.config
      
      u8g2.setFont(u8g2_font_courB10_tf);
      u8g2.setCursor(0, 10);
      u8g2.println("Blynk connect");
      u8g2.setCursor(0, 30);
      u8g2.println("try for 30sek.");
      u8g2.sendBuffer();
      u8g2.clearBuffer();
      
      Blynk.config(auth);
      Blynk.connect();
      }
      
Blynk_Connect = Blynk.connected();     
      if (Blynk_Connect == false)        
      {
        u8g2.setFont(u8g2_font_courB10_tf);
        u8g2.setCursor(0, 10);
        u8g2.println("kein Blynk");
        u8g2.sendBuffer();
        u8g2.clearBuffer();
        
        Blynk.disconnect();
        delay(2000);
      }

I do not need here more about the WLAN Connect, because i do this in advance by WiFi.begin (ssid,
pass);

So, everything fine …

I had exactly the same situation some days ago, as discussed in this post

PeteKight you suggested me the same, but i want to tell you that Blynk.config is no more suppoted with new Blynk 2.0 libraries, and it comes up with the error “no matching function … bla bla”

But why would someone define an auth token and use Blynk.config(auth), when the newer Blynk.Edgent files are available for taking responsibility of connection re-connection and every one is now paying for newer Blynk IOT.

That statement is factually incorrect.

Blynk Edgent is one option when using certain hardware with Blynk IoT, but it’s not possible to use Edgent with all types of hardware.
And, in some situations, people may wish to have a much simplified sketch, use a as ketch they was written for Blynk Legacy, or not allocate a pair of GPIOs to the reset button and LED required by Edgent when reconfiguring the stored credentials.

Even when you allow Edgent to manage your credentials for you, these stored credentials still need to be passed to the Blynk library and then on to the Blynk server to initialise the connection. The only difference is that these credentials are saved in the config store rather than being hard coded.

So, Blynk.begin() or Blynk.config has to be used to establish the Blynk connection, whether this is done explicitly by the user, with either static or dynamic credentials, or deep in the Blynk Edgent sketch using data from the config store, one or other of the commands has to be used.

Pete.

@PeteKnight Yes you are right, many user may still prefer legacy way of doing things, but what if the problem mentioned in this post is occurring with BlynkEdgent.run ???
Neither we can use Blynk.config(auth) manually nor we want to use it, then how the remaining part of code would run ?

Sorry. I don’t understand what you are asking/stating in this sentence

Pete.

I do not understand why we talk about BlynkEdgent.run.
I do not use it.
But I can confirm , that it works fine , what Pete recommend to me.

Pete, meanwhile I have changed my first opinion about Blynk IOT.
First I was disappointed, that so less is for free, now.

But if I start thinking, Blynk provide the complete WEB IOT Service for free.
and this unlimited, today
The littelst Upgrade is r.a 60€ per year.
So and now if I thing what about cost for DynsDNS Service for a year.
Then Blynk looks fair in the complete paket.
We do not can forget that Blynk is also a company which has people and must earn money.
Of course the old Blynk has more widget options for “free” users by the ernergy options.

But the new IOT Version is still fair for the free users and also the smallest Upgrade.

So I use further the Blynk for the WEB based access.