BLYNK
HOME       📲 GETTING STARTED       📗 DOCS       ❓HELP CENTER       👉 SKETCH BUILDER

Arduino Mega 2560 + ESP8266 shield Blynk.connectWiFi(ssid, pass) command not working

Hello there,

After a long time not working on my project and following the threads opened after the issues I had two years ago I am still stuck…

My issues where the same as this one:

My main problem is still to manage if the internet connection is available or not. So I just want my code to work whatever the Wifi state and reconnect when available.

So I decided to try to use instead of blynk.begin:

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

if (Blynk.connectWiFi(ssid, pass)) {
Blynk.connect();
}

And it doesn’t work, it remains stuck at this point whatever the presence of the wifi or not.
And I have a strange character in the serial monitor:
22:38:19.495 -> [1

I do not really understand where is the issue, and I understand that most of the people doesn’t use blynk with this setup…

Thanks,

Furby

Here is the code I am using for test purposes

// ------------------------------------------------------------------------------------
// 20190811
//Test wifi with auto reconnection only blynk
// ------------------------------------------------------------------------------------
 

// Inclure la bibliothèque LCD I2C
#include <LiquidCrystal_I2C.h>

//Librairies BLynk et ESP8266 v2019
#define BLYNK_PRINT Serial

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

//definition de l'adresse du module LCD I2C
// Si le jumper A0 est soudé, l'adresse I2C est 0x3E, sinon utiliser un scanner I2C
//LiquidCrystal_I2C lcd(0x3E, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);  // Set the LCD I2C address
// Pin a connecter SDA/SCL 20/21 sur ARDUINO MEGA
// (16,2) correspondent aux nombres de colonnes,lignes
	LiquidCrystal_I2C lcd(0x3E, 16,2);
 

// Variables de température
static float temp = -10;

// Variable pour la connexion WIFI
	//Variable de dernière connexion wifi
static unsigned long last_wifi_millis = 0;
	// variable de dispo de la connexion
static boolean result_wifi;
static boolean ReCnctFlag;
static boolean ReCnctCount;


// Pin de signe de vie du WIFI
const int pin_wifi = 10;


// WIFI paramètres de connexion
// Set password to "" for open networks.
char ssid[] = "Mikado XZ1";
char pass[] = "41414141";
char auth[] = "Jpzx7sCI4UNL8aeLrzKInulkboQivcb7";
BlynkTimer timer; // Create a Timer object called "timer"! 

// Ouverture de la connexion série de l'ESP sur le port série 1: pins 18/19

#define EspSerial Serial1

// Your ESP8266 baud rate:
#define ESP8266_BAUD 115200

ESP8266 wifi(&EspSerial);
WidgetLED led1(V1);

void setup()
{
	// Debug console
	Serial.begin(9600);
  
	delay(10);	
	Serial.println("Hello, World !");
	Serial.println("I am your new overlord, Songy Automate de Piscine !");
	Serial.println("Bow dozn to me and swer fealty to your new ruler !");
	Serial.println("");

	Serial.println("Setting up LCD lib");
	Wire.begin();
	lcd.begin(16,2); //(colonne, ligne)
	lcd.backlight(); // ajout en V21 pour le lcd i2C sinon pas de backlight
	delay(10);
	lcd.setCursor(0,0);
	lcd.print("  Automate  de  ");
	lcd.setCursor(0,1);
	lcd.print("  Piscine V026  ");

	// Set ESP8266 baud rate
	EspSerial.begin(ESP8266_BAUD); // =serial1.begin
	delay(10);
	Serial.println("ESP serial OK");


	if (Blynk.connectWiFi(ssid, pass)) {
    Blynk.connect();
	Serial.println("WIFI is connected in setup");
	}
	
//  Blynk.begin(auth, wifi, ssid, pass);
  // You can also specify server:
  //Blynk.begin(auth, wifi, ssid, pass, "blynk-cloud.com", 80);
  //Blynk.begin(auth, wifi, ssid, pass, IPAddress(192,168,1,100), 8080);

}

void loop()
{
//	Blynk.run();
	timer.run();
	
  if (Blynk.connected()) {  // If connected run as normal
    Blynk.run();
  } else if (ReCnctFlag == 0) {  // If NOT connected and not already tring to reconnect, set timer to try to reconnect in 30 seconds
    ReCnctFlag = 1;  // Set reconnection Flag
    Serial.println("Starting reconnection timer in 30 seconds...");
    timer.setTimeout(30000L, []() {  // Lambda Reconnection Timer Function
      ReCnctFlag = 0;  // Reset reconnection Flag
      ReCnctCount++;  // Increment reconnection Counter
      Serial.print("Attempting reconnection #");
      Serial.println(ReCnctCount);
      //wifi.setDHCP(1, 1, 1); //Enable dhcp in station mode and save in flash of esp8266
      Blynk.config(wifi, auth);
      Blynk.connect();  // Try to reconnect to the server
      if (Blynk.connectWiFi(ssid, pass)) {
        Blynk.connect();
      }
    });  // END Timer Function
  }
	
	
	Blynk.virtualWrite(V2, temp);
	Blynk.virtualWrite(V5, millis());
}

Maybe this will help: try changing your Blynk.config command to:

Blynk.config(wifi, auth, "blynk-cloud.com", 8442);

The proper hardware port is and has been for some time now, 8080

I simply use this set of commands in all my Blynk sketches…

  WiFi.begin(ssid, pass);  // Non-blocking if no WiFi available
  Blynk.config(auth, server, port);
  Blynk.connect();

Using an ESP as shield can be different then as standalone, but the principle is usually the same…

I use this in my MEGA & ESP-01 sketch…

I always had:

sketch_jul15b:82:3: error: 'WiFi' was not declared in this scope

   WiFi.begin(ssid, pass);

   ^

exit status 1
'WiFi' was not declared in this scope

You need…

#include <WiFi.h>