BLYNK
BLYNK.IO       📲 GETTING STARTED       📗 DOCS       👉 SKETCH BUILDER

Reconectar blynk

That’s 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’t 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’m 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’m stumped . . . I’ve got about 20 ESP8266/32 devices connected on my network, and they always re-connect when I have interruptions.

I can’t 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

Bueno, lo intente en mi ESP8266 y resulta que vuelve a reconectarse normalmente.
Luego lo intente en mi ESP32 y este no se reconecta automaticamente, tengo que reiniciarlo para que vuelva a conectarse a internet. en la comunicacion serial dice esto:

[117147] Connecting to blynk-cloud.com:80
[122148] Connecting to blynk-cloud.com:80
[127149] Connecting to blynk-cloud.com:80
[132150] Connecting to blynk-cloud.com:80
[137151] Connecting to blynk-cloud.com:80
[142152] Connecting to blynk-cloud.com:80
[147153] Connecting to blynk-cloud.com:80
[152154] Connecting to blynk-cloud.com:80
[157155] Connecting to blynk-cloud.com:80
[162156] Connecting to blynk-cloud.com:80

Permanece diciendolo hasta que lo reinicias, asi que supongo que debe ser un problema en la placa.

Blynk.begin(auth, ssid, pass); is a blocking function, and may not allow your program to run if there is a problem with internet during start-up (and possibly after). It is better to use the Blynk.config(auth); to establish connection. This allows your program to continue to operate if the wifi sgnal is lost.

Take a look at this example, I have used it in many of my projects with great success. Although, I do not run any esp32’s. All of my projects are based off of the esp8266.

Hope this helps.

Claro, eso fue lo que hice para solucionarlo, como mostré en el primer código que subí, yo lo que decia es que con mi esp8266 funciona perfecto, se reconecta cuando vuelve el internet, pero en mi ESP32 eso no sucede, se queda intentando reconectar.

If that fixes it, then I would go with that approach. It probably has something to do with the BLYNK library, as I believe it was developed prior to the ESP32. I do not think that there will ever really be a fix from the BLYNK staff for the current BLYNK 1.0 version. It may be fixed in the BLYNK 2.0 version, but don’t hold your breath for BLYNK 2.0 as the developers have been silent about its release date for a very long time.

1 Like

Hola Luciano. Te consulto. Si te funcionó el código que pusiste. Yo lo copie en el mio pero no tuve caso. Yo mis datos los ingreso mediante el wifimanager. Me pasa lo mismo que a vos que si se cae el wifi o se desconecta por cualquier motivo el módem la única solución es ir y tocar el reset de la placa. En mi caso un wemos d1 mini. Que me recomendás?

Hola @Gonzalo_Robles disculpa la demora hacía demasiado que no entraba al foro de blynk, mirá yo al final opte por usar la librería Blynk_WM y logré solucionar los problemas, está misma maneja la reconexión automática del ESP32 y quedó funcionando perfecto. Saludos

could you upload an example with Blynk_WM.Thank you

Hi, could you solve your problem … I have the same mess and I can’t solve it … the strange thing is that it happens to me with some routers

I think you shoud copy you connect code like in setup() in your “void reconnectBlynk()”.
Your “void reconnectBlynk()” can’t work if wifi connection is lost but only in case of just a blynk connexion lost. I had the same issue and i wrote this function which is called like your “void reconnectBlynk()”… See below for example !
The delay control with break is used to avoid being blocked in the connection phase if it is not possible to connect.

void connectWifi() 
{
  unsigned long blynkTimeout = 4000;    // Temps donné pour la connexion
  unsigned long blynkStart = millis();

  Serial.println("Connecting Wifi/Blynk");

  while (!Blynk.connected())
  {
    WiFi.begin(ssid, pass);
    Blynk.config(auth);
    Blynk.connect(); 

    if (millis()>blynkStart+blynkTimeout) break;
  }

  Connected2Blynk = Blynk.connected();
}