Blynk not connecting to server if during start-setup time not have wifi connection

Hi,

I dont know it is bug or i am something doing wrong, i relase that BLYNK not connecting to server if during start time not have wifi connection (like all power restarted and arduino started before wifi not ready) .
Blynk.run () command not connecting server and serial monitor wrote about failing connect wifi.

I have waited more than one hour, when I saw that it was not connected to the server, I turned the arduino off and on. After that arduino joined the sever.

Maybe in such cases blynk.begin settings should be re-entered on the loop controlled functions?

You’d be better managing your WiFi connection yourself, with appropriate WiFi connection checking via a timer (not in the void loop), then using Blynk.config and Blynk.connect.

Pete.

Dear Pete,
Thanks for answering.
I will try use while blynk connection not available function inside setup with timer reconnection again.

Inside setup function :
(I am using #include <BlynkSimpleShieldEsp8266.h> library, so i dont find wifi check function, i use just Blynk.connected() command.

       while (!Blynk.connected())
             {
                 timer.setInterval(7000L,ConnectServerAgain); 
             }

And
this function for reconnection to server till succesful connection

 void  ConnectServerAgain() 
  {
    Blynk.begin(auth, wifi, ssid, pass);
    
    }

That’s not the way I’d do it.
Have you tested this fully is a variety of different scenarios?

Pete.

You are right, it is not checking that function.

/ _ )/ /_ _____ / /__
/ _ / / // / _ / '/
/
//_, /////_
/
__/ v1.1.0 on Arduino Mega

#StandWithUkraine https://bit.ly/swua

[521] Connecting to xxxx
[3569] WIFI DISCONNECT
AT version:1.1.0.0(May 11 2016 18:09:56)
SDK version:1.5.4(baaeaebb)
compile time:May 20 2016 15:08:19
OK
[13611] Failed to connect WiFi

That’s because Blynk.begin is a blocking function and will halt all code execution at that point if a connection to WiFi or the Blynk server can’t be established.

That’s why is said…

Pete.

Dear Pete,

Have wifi check function for BlynkSimpleShieldEsp8266.h library ?
Inside library (https://github.com/blynkkk/blynk-library/blob/master/src/BlynkSimpleShieldEsp8266.h) already tested “connectWiFi” , “BlynkWifi” , “wifi”, “WiFi.status()” and all give error.

How are you testing these functions?

Where is your sketch?

How is this connected with the fact that Blynk.begin is a blocking function for all board types?

Pete.

I have turned off wifi router from power supply and started arduino to check connection
Code:

#define BLYNK_TEMPLATE_ID "xxxxxxxx"
#define BLYNK_DEVICE_NAME "xxxxxxxxxxx"
#define BLYNK_AUTH_TOKEN "xxxxxxxxxxx"

// Send Blynk user messages to the hardware serial port…
#define BLYNK_PRINT Serial 

//blynk library
#include <ESP8266_Lib.h>
#include <BlynkSimpleShieldEsp8266.h>

//blynk auth
char auth[] = BLYNK_AUTH_TOKEN;

// wifi password, login
char ssid[] = "xxxx";
char pass[] = "xxxxx";


// Define your ESP8266 baud rate:
#define ESP8266_BAUD 115200

// Tell the Blynk library to use the  Hardware Serial port 1 for WiFi..
ESP8266 wifi(&Serial3);

BlynkTimer timer;

void setup() 

{

   
   // Initialise the debug serial port
      Serial.begin(115200);

   // Initialise the Hardware serial1 port…
      Serial3.begin(ESP8266_BAUD);
      delay(10);
      Blynk.begin(auth, wifi, ssid, pass);
      while ( !Blynk.connected())
            {
                timer.setInterval(7000L,ConnectServerAgain); 
            }
}

  void  ConnectServerAgain() 
 {
   Blynk.begin(auth, wifi, ssid, pass);
   Serial.println("reconnection to server");
   }

And on the Serial monitor i dont see any reconnection to server comments, mean that it is freeze somewhere.

Where is your void loop?

Pete.

Sorry,

void loop() 
{

  Blynk.run();
  timer.run();
}

You don’t seem to understand the concept of a blocking function.

Pete.

On some topic adviced to add Wifi.h library so i added, now i can check WiFi.status()

void setup() 

 {

    //Blink ve serial xeberlesme ucun 
    // Initialise the debug serial port
       Serial.begin(115200);

    // Initialise the Hardware serial1 port…
       Serial3.begin(ESP8266_BAUD);
       delay(10);
       WiFi.begin(ssid, pass);
      while (WiFi.status()!=WL_CONNECTED  )
             {
              delay(500);
              Serial.print(".");
                 timer.setInterval(2000L,ConnectServerAgain); 
             }

             
 if(WiFi.status()==WL_CONNECTED  ) 

 {
   Blynk.begin(auth, wifi, ssid, pass);
  }
}

   void  ConnectServerAgain() 
  {
    WiFi.begin(ssid, pass);
Serial.println("connection to wifi");
    delay(500);
    
    }

Blynk.config(auth) give error .
Upper codes not give any error but device not connection to wifi with this function (WiFi.begin(ssid, pass); , it is strange.

Serial monitor just show “…” comments

Blynk.connectWiFi(ssid, pass); also not work
Serial monitor just continiously show
[510] Connecting to xxxx

Dear Pete,

I’ve looked a little deeper, but there are errors that don’t match with the documentation.
@Gunner wrote in this topic how to solve it

char server[] = "blynk-cloud.com";
unsigned int port = 8080;
  wifi.setDHCP(1, 1, 1); //Enable dhcp in station mode and save in flash of esp8266
  Blynk.config(wifi, auth, server, port);
  if (Blynk.connectWiFi(ssid, pass)) {
    Blynk.connect();
  }

In my case (maybe blynk 2 version something changed) auth not taken

[23] 
    ___  __          __
   / _ )/ /_ _____  / /__
  / _  / / // / _ \/  '_/
 /____/_/\_, /_//_/_/\_\
        /___/ v1.1.0 on Arduino Mega

 #StandWithUkraine    https://bit.ly/swua


[534] Connecting to Ibadovlar
[3582] WIFI CONNECTED
AT version:1.1.0.0(May 11 2016 18:09:56)
SDK version:1.5.4(baaeaebb)
compile time:May 20 2016 15:08:19
OK
[8652] +CIFSR:STAIP,"192.168.1.7"
+CIFSR:STAMAC,"dc:4f:22:22:29:8d"
[8653] Connected to WiFi
[19844] Invalid auth token

Also, i have tried to delay before begin function, it is strange that after a while delay time begin function not working.

Yes, the server is now blynk.cloud and the port is 80

Pete.

1 Like

yes, i found it also from sketch generator.
Thanks

You’d also be well advised to look at how the BlynkTimers are initialised in the Sketch Builder examples.

Pete.

Tested, work normally for now )
Thanks for support

My code like this

  wifi.setDHCP(1, 1, 1); //Enable dhcp in station mode and save in flash of esp8266 - (i dont know what it is ) )))
    Blynk.config(wifi, auth, server, port);
  while (Blynk.connectWiFi(ssid, pass)==false) {
    delay(500);
    Serial.println("repeat checking");

  } 


  while (Blynk.connect() == false) {
    // Wait until connected
  }