ESP8266 Project with Blynk, Programm do not start in if Blynk Server is not connected

Hello everybody,
I use Blynk in my Project and all works fine.

Last night the Accesspoint for WLAN ,and this is the accesspoint for the ESP8266 and Blynk is fall out.
This was because of power lose in the main town.

So what happens.
The Main Power was lost for WLAN Accespoint and also the Power for ESP 8266.
After Power come up the Accespoint with Wlan hang up.
The ESP8266 starts normal , but do not can connect to the WLAN, because the Wlan hang up.

What I See is, that the whole Programm in ESP 8266 do not work, while the WLAN connection is missing.

Iám a little bit afraid, because I thing the measure and control Programm what the ESP8266 has to do should be the first Priority …and the great Blynk features should be only for watching and viewing what is going on.

I do not thing , that the main Programm do not works if a connection to Wlan become failed.

Is there a solution how I can make a bridge over this situation, so that the connection was some few times was proved and if it not can connect, the the Main programm start nevertheless?

For the Blynk routines I only take all this was recommended here on the side.

Best regards
Rainer

I assume that you’re using Blynk.begin in your void setup?
This is a blocking function and will halt all code execution if the WiFi connection or the connection to the Blynk server cannot be established.

This has been discussed many times before on the forum, search for “Blynk.config” and “Blynk.connect” for information about how to overcome this.

Pete.

Yes, I will do so.
Thanks for the hint and I go to search with your Keywords.
Thanks a lot, Pete !

Dear Pete,
now I read and serach about the “Blynk.config” and “Blynk.connect”.
But I do not really sure how to adapt this to me. and I do not understand some topic how to adapt this to my problem.
I try something with Blynk connect and false but, it do not works.
Do you can forward me a tip or topic were is similar to my problem?
This would be great.
Thanks Rainer

I found
bool result = Blynk.connect();
bool result = Blynk.connect(timeout);
and so on, but I do not know how to use this for me in script.

Best regards Rainer

With

bool result = Blynk.connected();

I get a false, but how must I say in Sript that the Programm gos further after that step ?

{

Serial.begin(9600);
Blynk.begin(auth, ssid, pass);

bool result = Blynk.connect(20);
if  (result == false)         
{
  // What must stand here to go further in script without connection ??? 
} 
else {};



Wire.begin();                             //  FRAM
Wire.setClock(400000); // 400kHz          //  FRAM```

i Also try this without result:
´´´void setup()
{

Serial.begin(9600);
// Blynk.begin(auth, ssid, pass);

Blynk.config(auth);
Blynk.connectWiFi(ssid, pass);

bool result = Blynk.connect(20);
if (result == false)
{
Serial.println(“Hallo”);

}
else {};

Wire.begin(); // FRAM
Wire.setClock(400000); // 400kHz // FRAM´´´

Anybody who can help me , please ?

Step 1, connect to WiFi using non-Blynk processes
Step 2, define the Blynk connection parameter with Blynk.config
Step 3, connect to the Blynk server using Blynk.connect

Blynk.connected is a test, to see if the device is connected to the server or not. This is very different to Blynk.connect.

Pete.

Dear Pete,
thanks,
I do this and now I have the problem on the site of the Standard Wifi.
In den Lib in Keywords, there should be possible to say Wifi.End(). Buit this do not work.
Do you have a Idea , also how i can Stop the Wifi.begin after 25 tries ?

WiFi.begin(ssid, password);             // Connect to the network
  Serial.print("Connecting to ");
  Serial.print(ssid); Serial.println(" ...");

   int i = 0;
    while (WiFi.status() != WL_CONNECTED) { // Wait for the Wi-Fi to connect
    delay(1000);
    if (i >= 25) {
      Serial.print("Timeout");
      // WiFi.end();     <-------------do not works , but keyword are in Lib
    }
    Serial.print(++i); Serial.print(' ');
       
    }

  Serial.println('\n');
  Serial.println("Connection erfolgreich");  
  Serial.print("IP address:\t");
  Serial.println(WiFi.localIP());         // Send the IP address of the ESP8266 to the computer

  
  Blynk.config(auth);
  Blynk.connect(30);

This is your problem. If the while statement is not true then the loop will never end.
Replace while with a for loop.

Pete.

Yes, exactly this is the problem,
But how to close the Wifi.begin after make a for loop?
Rainer

Hi Pete, thanks for your inspiration of your listed Steps.
So I come to the Solution.
Now it works…

  WiFi.begin(ssid, password);               //  Connect to the network
  
  Serial.print("Connecting to ");
  Serial.print(ssid); Serial.println(" ...");

   int i = 0;
    while (WiFi.status() != WL_CONNECTED) { // Wait for the Wi-Fi to connect
    delay(1000);
    if (i >= 25) {
      break;
      Serial.print("Timeout");
      WiFi.mode(WIFI_OFF);
    }
    Serial.print(++i); Serial.print(' ');
       
    }

  Serial.println('\n');
  Serial.println("Connection ok ");  
  Serial.print("IP address:\t");
  Serial.println(WiFi.localIP());         // Send the IP address of the ESP8266 to the computer

  // ...................Blynk Parameter
  Blynk.config(auth);
  Blynk.connect(30);````

Why are you doing this???

and this…

Pete.

in this combination, the Wifi.beginn try 25 times to connect.
If not then Wifi was set off because there is no Wifi.
So the Wifi.beginn stops fur sure and the normal programm runs.

In my situation it must be sure that a lost WLAN or Blynk connection do not stop the Main programm.
The sketch I post al last works perfect for me and the situation.

If Wifi was set of , i also set blynk.disabled…
So everthing works like no Blynk and Wlan was never set… High Priorty to work Main Program.

I have the same requirements, but I never use WiFi.mode(WIFI_OFF); and avoid while loops in favour of for loops. 100% reliable for me.

Pete.

I try to do my best as beginner.
It might be not perfect, but without code help, only hints… i think it works.

if you have the same requirements:
Please show me and other interesstet pepole your code , your solution !!

I use Blynk in a very different way, so my code will be meaningless.

I’d suggest that you do quite a bit more testing of various scenarios to ensure that you are correct,

Connecting an ESP8266 to WiFi is a standard non-Blynk process and there are thousands of examples on the internet of how to do this, including many with limited connection attempts to allow stand-alone functionality.

Pete.

Pete.

I regret that you don’t want to share your code or approach with us.

but it doesn’t matter, i found a solution for myself. Of course it will be tested …

The instructions from you about the steps and the separation of WIFI and Blynk were important

Thank you for that