BLYNK
BLYNK.IO       馃摬 GETTING STARTED       馃摋 DOCS       馃憠 SKETCH BUILDER

Reconectar blynk

Hola, alguien sabe como puedo reconectar mi ESP32 al servidor de blynk luego de que se corte el internet? ya que cuando el internet vuelve no se reconecta, prob茅 usar la funci贸n Blynk.connect() cuando se detecte que se perdi贸 la conexi贸n pero no me funcion贸.

Hi, (I used Google Translate so read your post.

Blynk should automatically reconnect when your Internet connection is restored.

First - post your code so we can see what you have done.

billd

Resulta que despu茅s de estar unas horas desconectado, blynk no vuelve a reconectar.
Pero consegu铆 resolver el problema con este c贸digo:

int lastConnected;
BlynkTimer timer;

void reconnectBlynk() {
  if (!Blynk.connected()) {
    Serial.println("Lost connection");
    if(Blynk.connect()) Serial.println("Reconnected");
    else Serial.println("Not reconnected");
  }
}
void setup()
{
  WiFi.begin(ssid, pass);
  Blynk.config(auth);
  Serial.begin(9600);
  timer.setInterval(60*1000, reconnectBlynk);
}

void loop()
{
  if(Blynk.connected()){
  Blynk.run();
  lastConnected = millis();
  }  
  else{
    if (millis() > (lastConnected+120000)) {      // if it has been 2 minutes or more since the last connection or last attempt to connect to Blynk Server
      Blynk.connectWiFi(ssid, pass);
      if (WiFi.status() == WL_CONNECTED){
        Blynk.config(auth);
        Blynk.connect();
  }
    }
}
timer.run();
}

If you include Blynk.begin(auth, ssid, pass); in setup, and Blynk.run(); in the loop, you should not need all that other code.

Billd

Intent茅 hacer eso, fue mi primera opci贸n, pero no consegu铆 hacerlo funcionar, el problema lo ten铆a cuando internet estaba conectado pero en alg煤n momento dejaba de funcionar, cuando volv铆a no se reconectaba mi ESP32, ten铆a que ir a reiniciar la placa.

Strange . . . Blynk.run(); should take care of the reconnect. Do you have the latest Blynk library installed?

Tengo instalada la versi贸n 0.6.1

That鈥檚 the latest. What about your ESP32? Latest library for your specific board?

Para ESP32 tengo instalada la de espressif systems 1.0.4, seg煤n el gestor de tarjetas es la 煤ltima versi贸n.

That鈥檚 the latest. Do you have anything else running in your setup)( or loop() ?

Solamente tengo
Timer.run();
Timer2.run();
Y en el setup es lo que publique en el c贸digo de arriba.

Can you post the FULL code that does NOT work (the one with Blynk.begin()?

Este es el codigo que intente usar pero no se reconectaba:

#define BLYNK_PRINT Serial
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
bool Estado;
bool funcionando = false;
#define EXTRACTOR 13
char auth[] = "******";
char ssid[] = "*******";
char pass[] = "******";

BlynkTimer timer;
WidgetLED led1(V4); 
BLYNK_CONNECTED(){
Blynk.syncAll();
}

BLYNK_WRITE(V5) 
  {
    Estado = param.asInt();
    if(Estado == true && funcionando == false){
     timer.setTimeout(1000L, Confirmar);
    }
  }

void Confirmar(){
  if(Estado == true){ 
    digitalWrite(EXTRACTOR, HIGH);
    led1.on();
    funcionando = true;
    timer.setTimeout(10000L, RelayOff); 
  }
}

void RelayOff(){
  digitalWrite(EXTRACTOR, LOW);
  led1.off();
  funcionando = false;
}

void setup()
{
  Serial.begin(9600);
  Blynk.begin(auth, ssid, pass);
  pinMode(EXTRACTOR, OUTPUT);
}

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

The only thing I see is that you are using

In two of your functions - effectively delays . . . Blynk doesn鈥檛 like deles, this may be causing Blynk.run() to stop . . . have youe tried a basic example (LED and button) without any timers?

Pero ese tipo de timer no est谩 basado en la librer铆a SimpleTimer.h? Seg煤n tengo entendido la funci贸n timer.setTimeout usa millis().

Possibly (likely) - I鈥檓 just trying to eliminate possibilities.

De igual forma ese timer se activa desde la app, as铆 que solo funciona cuando yo lo activo, no creo que le cause alg煤n problema a blynk.run()

I鈥檓 stumped . . . I鈥檝e got about 20 ESP8266/32 devices connected on my network, and they always re-connect when I have interruptions.

I can鈥檛 think of anything else other than try a very basic sketch, then keep adding code elements to see what is stopping Blunk.run() from working properly.

Ma帽ana voy a intentar lo que decis y ver que resultados obtengo.
Puede ser alg煤n problema en mi ESP32? Tengo la versi贸n de 38 pines

It could be . . . there are many, many boards, some are low quality . . . when I get strange issues like these I always go back to basic sketch, and try with another device - it helps to eliminate unknown issues.

Good Luck.

billd