Connection to Blynk server cant be established

hey,
I use Arduino Mega with esp8266 connected through serial I included all the required libraries and tested them with the test example in Blynk library it showed no error. but when i try to run blink example it shows nothing about connecting to server, it connect to WiFi but not to the Blynk server (not local server but the Blynk cloud server). my android app shows the message “wasn’t online yet”. i checked the token its written correctly here is my arduino code:

#define BLYNK_PRINT Serial


#include <ESP8266_Lib.h>
#include <BlynkSimpleShieldEsp8266.h>


char auth[] = "c4f7390b7xxxxxxxxxxxxxxx7b51fc98";


char ssid[] = "xxxxxxxx";
char pass[] = "xxxxxxxx";


#define EspSerial1 Serial1





#define ESP8266_BAUD 115200

ESP8266 wifi(&EspSerial1);

void setup()
{

  Serial.begin(115200);

  delay(10);


  EspSerial1.begin(ESP8266_BAUD);
  delay(10);

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

void loop()
{
  Blynk.run();
}

and my serial monitor stay still to this:

[19] 
    ___  __          __
   / _ )/ /_ _____  / /__
  / _  / / // / _ \/  '_/
 /____/_/\_, /_//_/_/\_\
        /___/ v0.5.4 on Arduino Mega

[527] Connecting to xxxxxxx
[3577] AT version:1.7.0.0(Aug 16 2018 00:57:04)
SDK version:3.0.0(d49923c)
compile time:Aug 23 2018 16:58:12
Bin version(Wroom 02):v1.7.0
OK
[8748] +CIFSR:STAIP,"65.108.105.32"
+CIFSR:STAMAC,"68:c6:3a:a7:42:d3"
[8749] Connected to WiFi

Try this instead…

ESP8266 wifi(&Serial1);  // Pins 18 & 19 on MEGA - For ESP-01 link
Serial1.begin(115200);  // Set baud rate - For ESP-01 link

Thanx for the reply, i did try, same problem.

This is my base starter sketch for my Arduino Mega with ESP-01

//#define BLYNK_DEBUG   // Advanced diagnostic data... also drastically slows entire sketch
#define BLYNK_PRINT Serial // This prints to Serial Monitor
#define BLYNK_USE_128_VPINS
#include <ESP8266_Lib.h>  // For ESP-01 Link
#include <BlynkSimpleShieldEsp8266.h>  // For ESP-01 Link

ESP8266 wifi(&Serial1);  // Pins 18 & 19 on MEGA - For ESP-01 link

BlynkTimer timer;

#define HTB 13  // Set HeartBeat LED pin.

char auth[] = "xxxxxxxxxx";  // Local Server
char ssid[] = "xxxxx";
char pass[] = "xxxxx";
char server[] = "xxx.xxx.xxx.xxx"; // Local Server
// char server[] = "blynk-cloud.com"; // Cloud Server
int port = 8080;



void setup() {
  pinMode(HTB, OUTPUT);  // Setup HeartBeat pin
  Serial.begin(115200);  // BLYNK_PRINT data - For Serial Monitor
  Serial1.begin(115200);  // Set baud rate - For ESP-01 link
  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();
  }
  // Timed Lambda Function - UpTime counter
  timer.setInterval(1000L, []() {  // Run every second
    Blynk.virtualWrite(V127, millis() / 1000);  // Display the UpTime in Seconds
  });  // END Lambda Function
}




void loop() {
  timer.run();  
  digitalWrite(HTB, !digitalRead(HTB));  // Flash HeartBeat LED every loop() cycle
  if (Blynk.connected()) {  // If connected run as normal
    Blynk.run();
  } else {
    Blynk.connect();  // Try to reconnect to the server
  }
}

I’ll try the code with some edits to fit my needs and let you know the results. Do you think blynk cloud server has limited access or no access at all for some regains in the world ? I’m from Iraq. maybe this is why I can’t connect to the server. Again thanx a lot for your time.

It Worked! thank you very much here is the code:

#define BLYNK_PRINT Serial 
#define BLYNK_USE_128_VPINS
#define HTB 13  

#include <ESP8266_Lib.h>  
#include <BlynkSimpleShieldEsp8266.h>  

ESP8266 wifi(&Serial1);  

BlynkTimer timer;

char auth[] = "XXXXXXXXXXXXXXXXXXXXXXXXX";  
char ssid[] = "XXXXXXXX";
char pass[] = "XXXXXXX";
char server[] = "blynk-cloud.com"; 
int port = 80;

void setup() {
  pinMode(HTB, OUTPUT);  
  Serial.begin(115200);  
  Serial1.begin(115200); 
  wifi.setDHCP(1, 1, 1); 
  Blynk.config(wifi, auth, server, port);
  if (Blynk.connectWiFi(ssid, pass)) {
    Blynk.connect();
  }
  timer.setInterval(1000L, []() {  
    Blynk.virtualWrite(V127, millis() / 1000);  
  });  
}

void loop() {
  timer.run();  
  digitalWrite(HTB, !digitalRead(HTB));  
  if (Blynk.connected()) {  
    Blynk.run();
  } else {
    Blynk.connect();  
  }
}

And the output of the serial monitor is:

  ___  __          __
  / _ )/ /_ _____  / /__
 / _  / / // / _ \/  '_/
/____/_/\_, /_//_/_/\_\
       /___/ v0.5.4 on Arduino Mega

[583] Connecting to XXXXXXX
[3635] WIFI GOT IP
AT version:1.7.0.0(Aug 16 2018 00:57:04)
SDK version:3.0.0(d49923c)
compile time:Aug 23 2018 16:58:12
Bin version(Wroom 02):v1.7.0
OK
[10676] +CIFSR:STAIP,"192.168.16.104"
+CIFSR:STAMAC,"68:c6:3a:a7:42:d3"
[10677] Connected to WiFi
[22531] Ready (ping: 17ms).
[124471] Ready (ping: 17ms).
[156400] Ready (ping: 1856ms).

I think the problem was the connection to the server is interrupted due to bad Internet connection so, we must see if it’s connected to the server if not then connect again. and we must repeat it in the loop. As your code here:

  if (Blynk.connected()) {  
    Blynk.run();
  } else {
    Blynk.connect();  
  }

Not like the the example included in the library which run like this:

void loop()
{
 Blynk.run();
}

It is just an example and assumes a solid connection. As for my reconnection method, it is just one way of doing it, thus left for others to find what works for them.