Continuous connection and disconnection

hello, good morning, I have a slightly strange problem, I have two esp32 in an industrial environment and I have done connection tests outside the factory and I have a pretty good range of 100m but when I put it in the factory they are about 15m from the router when I put it on new ones are fine but after a week they start disconnecting and connecting continuously and lose data. I have two esp 32 to the same router the router is gl-x300b. It has 300mpb and I don’t know if it could be the channel that is too busy. can someone help me to give a solution. Change from an esp8266 with external antenna to an esp 32 with external antenna. I also wanted to ask how you can change the reception channel of the esp 32 in blynk edgent. It’s too complex and I don’t really know where to do it without damaging it. Thanks for your help. all the best.I leave you my code in case there is any problem in it. Thanks for all, greetings

//14 aceite bajo
//35 analogica entrada temperatura 10k a ,masa y potenciometro de 100k puesto a 21k
//4 baliza roja
//12 llamada operario
//32 conteo caja
//33 final de averia
//pantalla lcd 128x64 st 7920---------------
//BLK-GND
//BLA-3,3v
//RST-22
//PBS-GND
//E  -18
//R/W-23
//RS -5
//VCC-5v
//GND-GND 
#define BLYNK_TEMPLATE_ID ""
#define BLYNK_DEVICE_NAME ""
#define BLYNK_FIRMWARE_VERSION        "0.1.0"
#define BLYNK_PRINT Serial
//#define BLYNK_DEBUG
#define APP_DEBUG
#define USE_WROVER_BOARD
#include "BlynkEdgent.h"
#include <Arduino.h>
#include <U8g2lib.h>
#ifdef U8X8_HAVE_HW_SPI
#include <SPI.h>
#endif
#ifdef U8X8_HAVE_HW_I2C
#include <Wire.h>
#endif
unsigned long h;
int i = 0;
int j = 0;
int l = 0;
int n = 0;
int r = 0;
int k = 0;
int o = 0;
int q = 0;
int w = 0;
int x = 0;
int z = 0;
U8G2_ST7920_128X64_F_SW_SPI u8g2(U8G2_R0, /* clock=*/ 18, /* data=*/ 23, /* CS=*/ 5, /* reset=*/ 22); // ESP32 ACTUAL
int luzboton = 21;
int aceitedepo = 14;

unsigned long tiempo_guardado = 0 ;
unsigned long tiempo_guardado1 = 0 ;

int ma = 0;
float temp = 35; //etiqueta para lectura anal�gica PARA SENSOR DE TEMPERAURA
int y = 0;
//---------------------------------pines virtuales para la placa hacia la aplicacion
BLYNK_WRITE(V5) { //luz de botonera
  int pinValue = param.asInt();
  digitalWrite(luzboton, pinValue);
}
BLYNK_WRITE(V6) { //SENSOR MINIMO ACEITE DEL DEPOSITO esta asociada a la aplicacion atraves de V0 y V0 es correo
  int pinValue = param.asInt();//asocia pinValue a un entero en este caso es V0 que es pin 5 de wemos que D1
  digitalWrite(aceitedepo, pinValue);//V0 es correo
}
//-------------------------------------boleanos para los leds de la aplicacion.

BlynkTimer timer;
WidgetLED led3(V2);//ESTE ES EL LED DE LA BALIZA ROJA ES UN BOLEANO QUE VIGILA LA SEÑAL PARA CAMBIAR DE ESSTADO

boolean btnState = false;
void ledblynk()
{

  boolean isPressed = (digitalRead(4) == HIGH);

  if (isPressed != btnState) {
    if (isPressed) {
      led3.on();
      r = 1;
    } else {
      led3.off();
      r = 0;
    }
    btnState = isPressed;
  }
}
WidgetLED led4(V3);//ESTE ES EL LED DE LLAMADA DE OPERARIO ES UN BOLEANO QUE VIGILA LA SEÑAL PARA CAMBIAR DE ESSTADO

boolean btnState1 = false;
void ledblynk1()
{

  boolean isPressed = (digitalRead(12) == HIGH);

  if (isPressed != btnState1) {
    if (isPressed) {
      led4.on();
      k = 1;
    }
    btnState1 = isPressed;
  }
}
WidgetLED led5(V6);//ESTE ES EL LED DE NIVEL MINIMO DE DEPOSITO ES UN BOLEANO QUE VIGILA LA SEÑAL PARA CAMBIAR DE ESSTADO

boolean btnState2 = false;
void ledblynk2()
{

  boolean isPressed = (digitalRead(14) == HIGH);

  if (isPressed != btnState2) {
    if (isPressed) {
      led5.off();
      unsigned long tiempo = millis();
      tiempo_guardado = tiempo;
    } else {
      led5.on();
      q = 0;
    }
    btnState2 = isPressed;
  }
}

WidgetLED led6(V5);//ESTE ES EL LED de conteo de las cajas rodadas

boolean btnState3 = false;
void ledblynk3()
{
unsigned long tiempo = millis();
  boolean isPressed = (digitalRead(32) == LOW);

  if (isPressed != btnState3) {
    if (isPressed) {
      led6.off();    
    } else {
      led6.on();     
      tiempo_guardado1 = tiempo;
      x = 1;
      delay(100);
    }
    btnState3 = isPressed;
  }
}


void setup()
{
   Serial.begin(115200);
  u8g2.begin();
  //-----------------------------------------LOGO DE JOHN DEERE Y SERVEO
  logo();
  delay(1000);
  timer.setInterval(1000L, ledblynk);
  timer.setInterval(1000L, ledblynk1);
  timer.setInterval(1000L, ledblynk2);
  timer.setInterval(1000L, ledblynk3);


  BlynkEdgent.begin();
  pinMode(luzboton, OUTPUT);
  pinMode(4, INPUT_PULLDOWN);
  pinMode(12, INPUT_PULLDOWN);
  pinMode(32, INPUT_PULLDOWN);
  pinMode(33, INPUT_PULLDOWN);
  
}

void loop() {
  BlynkEdgent.run();
   timer.run();
  unsigned long tiempo = millis();
    //--------------------------------pines virtuales a aplicacion.

  int llamadaoperario = 0;
  llamadaoperario = digitalRead(12);//  12 LLAMADA OPERARIO ES U positivo LA SEÑAL ES DE ENTRADA
  if ( (llamadaoperario == HIGH) && ( k == 1) && (o == 0))
  {
    digitalWrite(luzboton, HIGH);
    Serial.println("se ha pulsado boton de llamada");
    Blynk.logEvent("llamaope");
    ledblynk1();
    o = 1;
    Serial.print("estado k llamada    ");
    Serial.println(k);
    Serial.print("estado o llamada    ");
    Serial.println(o);
    delay(5000);

  }
  //--------------------------------------parpadeo del boton cuando esta activa la averia
  int lb = 0;
  lb = digitalRead(21);//parpadeo del la luz de la botonera
  if (lb == HIGH) {
    digitalWrite(luzboton, LOW);
    delay(300);
    digitalWrite(luzboton, HIGH);
    delay(300);
  }
  //--------------------------------------cuenta caja cada vez que se rueda 5 minutos seguidos para llevar preventivos en cuenta


  int cuenta = digitalRead(32);//conteo cajas
  if ((cuenta == 1) && (tiempo - tiempo_guardado1 >= 300000) && (btnState3 == LOW) && (x == 1)) {
    w++;
    z++;
    x = 0;
    delay(200);
    Serial.print("caja rodada ");
    
  }
  Blynk.virtualWrite(V1, w);
  Blynk.virtualWrite(V8, z);
  //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  Blynk.virtualWrite(V7, 33);//  final averia ES positivo LA SEÑAL DE ENTRADA
  int finalaveria = 0;
  finalaveria = digitalRead(33);
  if  ((finalaveria == HIGH) && (o == 1))
  {

    led4.off();

    Serial.println("se ha terminado la averia");
    Blynk.logEvent("finalaveria");
    o = 0;
    digitalWrite(luzboton, LOW);
    delay(5000);
    Serial.print("estado k terminada   ");
    Serial.println(k);
    Serial.print("estado o terminada   ");
    Serial.println(o);

  }
  //++++++++++++++++++++++++++++++++++resear contador dos botones pulsados a la vez pulsado 10 segundos
  if ((finalaveria == HIGH) && (llamadaoperario == HIGH))
  {
    w = 0;
    digitalWrite(luzboton, HIGH);
    delay(200);
    digitalWrite(luzboton, LOW);
    delay(200);
    digitalWrite(luzboton, HIGH);
    delay(200);
    digitalWrite(luzboton, LOW);
  }

  //++++++++++++++++++++++++++++++++++analogica de temperatura
  int pot = 0;
  pot = analogRead(temp);
  y = map(pot, 0, 4095, 0, 100); //funci�n map para escalado
  //delay(1000);
  Blynk.virtualWrite(V0, y);
  //Serial.println(y);
  if ( y >= 80)
  {
    Serial.println("temperatura alta");
    Blynk.logEvent("tempalta");
    delay(100);
  }
  //A ACTVAR CUANDO EL PROTOTIPO ESTE CORRECTO
  /* int ram=0;
    ram=digitalRead(luzboton);
     if ( (ram==HIGH)&&(y<=80))
    {
     digitalWrite(5,HIGH);
      Serial.println("resistencias apagadas manualmante");
      Blynk.logEvent("aparesis");
       delay(2000);
    }
  */


  if ((tiempo - tiempo_guardado >= 10000) && (btnState2 == 1) && (q == 0)) //envia a los 10 segundos de falta de aceite
  { //para evitar parpadeos del sensor
    q = 1;
    Serial.println("bajo  nivel de aceite");
    Blynk.logEvent("minimoaceite");
    delay(100);
    ledblynk2();
    delay(2000);
    Serial.print("estado q llamada    ");
    Serial.println(q);

  }
  int bl = 0;//  D2 BALIZA ROJA ACTIVA  LA SEÑAL DE ENTRADA ES positivo
  bl = digitalRead(4);
  if ( (bl == HIGH) && (r == 0))
  {
    Serial.println("baliza roja encendida");
    Blynk.logEvent("balizaroja");
    ledblynk();
    delay(2000);
    Serial.print("estado r baliza roja ");
    Serial.println(r);
  }
  h = digitalRead(14); // SENSOR DE ACEITE ES POSITIVO LA SEÑAL DE ENTRADA
  i = digitalRead(26); //  CONTEO DE PRUEBAS REALIZADAS
  j = digitalRead(12); //  LLAMADA OPERARIO ES un positivo LA SEÑAL ES DE ENTRADA
  l = digitalRead(4); //   BALIZA ROJA ACTIVA  LA SEÑAL DE ENTRADA ES positivo
  n = digitalRead(33); // final averia ES positivo LA SEÑAL DE ENTRADA
  //-----------------------------------DIBIJO DE CUADROS Y SEÑALES DE ENTRADA Y SALIDA
  u8g2.clearBuffer();
  u8g2.drawRFrame(0, 0, 128, 10, 0);
  u8g2.setFont(u8g2_font_u8glib_4_hr);
  u8g2.drawStr(4, 7, "ENTRADAS Y SALIDAS ");
  u8g2.drawStr(92, 7, "ESTADO");
  u8g2.drawStr(4, 17, "SENSOR DE ACEITE.......");
  u8g2.drawStr(4, 25, "NUMERO DE RODAJES....");
  u8g2.drawStr(4, 33, "LLAMADA OPERARIO.....");
  u8g2.drawStr(4, 41, "BALIZA ROJA........");
  u8g2.drawStr(4, 49, "FINAL AVERIA.............");
  u8g2.drawStr(4, 59, "TEMPERATURA ACEITE");
  u8g2.drawRFrame(0, 9, 90, 55, 0);
  u8g2.drawRFrame(89, 0, 39, 64, 0);
  if (h == 0) {
    u8g2.setCursor(93, 17);
    u8g2.print("LLENO");
  }
  if (h != 0) {
    u8g2.setCursor(93, 17);
    u8g2.print("FALTA");
  }

  u8g2.setCursor(93, 25);
  u8g2.print(w);

  if (j == 0) {
    u8g2.setCursor(93, 33);
    u8g2.print("NO PULS");
  }
  if (j != 0) {
    u8g2.setCursor(93, 33);
    u8g2.print("PULSADO");
  }
  if (l != 0) {
    u8g2.setCursor(93, 41);
    u8g2.print("ACTIVA");
  }
  if (l == 0) {
    u8g2.setCursor(93, 41);
    u8g2.print("NO ACTV");
  }
  if (n != 0) {
    u8g2.setCursor(93, 49);
    u8g2.print("PULSADO");
  }
  if (n == 0) {
    u8g2.setCursor(93, 49);
    u8g2.print("NO PULS");
  }

  u8g2.setFont(u8g2_font_courB10_tf);
  u8g2.setCursor(100, 61);
  u8g2.print(y);
  u8g2.sendBuffer();
  //Serial.print("estado k final  ");
  //Serial.println(k);
  //Serial.print("estado o final  ");
  //Serial.println(o);
  //Serial.print("estado r final  ");
  //Serial.println(r);
  //Serial.print("estado q final    ");
  //Serial.println(q);
  //Serial.print("estado w final    ");
  //Serial.println(w);
}

void logo()
{
  //-----------------------------------------LOGO DE JOHN DEERE Y SERVEO
  u8g2.setFont(u8g2_font_lucasarts_scumm_subtitle_r_tf);
  u8g2.clearBuffer();
  u8g2.drawRFrame(0, 46, 128, 64, 7);
  u8g2.drawStr(4, 60, "SERVEO    ");
  u8g2.drawStr(0, 80, "in association ");
  u8g2.drawStr(0, 100, "  JOHN DEERE  ");
  u8g2.sendBuffer();
  delay(20);
  u8g2.clearBuffer();
  u8g2.sendBuffer();

  u8g2.clearBuffer();
  u8g2.drawRFrame(0, 44, 128, 64, 7);
  u8g2.drawStr(4, 58, "SERVEO     ");
  u8g2.drawStr(0, 78, "in association ");
  u8g2.drawStr(0, 98, "  JOHN DEERE  ");
  u8g2.sendBuffer();
  delay(20);
  u8g2.clearBuffer();
  u8g2.sendBuffer();

  u8g2.clearBuffer();
  u8g2.drawRFrame(0, 42, 128, 64, 7);
  u8g2.drawStr(4, 56, "SERVEO    ");
  u8g2.drawStr(0, 76, "in association ");
  u8g2.drawStr(0, 96, "  JOHN DEERE  ");
  u8g2.sendBuffer();
  delay(20);
  u8g2.clearBuffer();
  u8g2.sendBuffer();


  u8g2.clearBuffer();
  u8g2.drawRFrame(0, 40, 128, 64, 7);
  u8g2.drawStr(4, 54, "SERVEO    ");
  u8g2.drawStr(0, 74, "in association ");
  u8g2.drawStr(0, 94, "  JOHN DEERE  ");
  u8g2.sendBuffer();
  delay(20);
  u8g2.clearBuffer();
  u8g2.sendBuffer();

  u8g2.clearBuffer();
  u8g2.drawRFrame(0, 38, 128, 64, 7);
  u8g2.drawStr(4, 52, "SERVEO    ");
  u8g2.drawStr(0, 72, "in association ");
  u8g2.drawStr(0, 92, "  JOHN DEERE  ");
  u8g2.sendBuffer();
  delay(20);
  u8g2.clearBuffer();
  u8g2.sendBuffer();

  u8g2.clearBuffer();
  u8g2.drawRFrame(0, 36, 128, 64, 7);
  u8g2.drawStr(4, 50, "SERVEO    ");
  u8g2.drawStr(0, 70, "in association ");
  u8g2.drawStr(0, 90, "  JOHN DEERE  ");
  u8g2.sendBuffer();
  delay(20);
  u8g2.clearBuffer();
  u8g2.sendBuffer();

  u8g2.clearBuffer();
  u8g2.drawRFrame(0, 34, 128, 64, 7);
  u8g2.drawStr(4, 48, "SERVEO     ");
  u8g2.drawStr(0, 68, "in association ");
  u8g2.drawStr(0, 88, "  JOHN DEERE  ");
  u8g2.sendBuffer();
  delay(20);
  u8g2.clearBuffer();
  u8g2.sendBuffer();

  u8g2.clearBuffer();
  u8g2.drawRFrame(0, 32, 128, 64, 7);
  u8g2.drawStr(4, 46, "SERVEO   ");
  u8g2.drawStr(0, 66, "in association ");
  u8g2.drawStr(0, 86, "  JOHN DEERE  ");
  u8g2.sendBuffer();
  delay(20);
  u8g2.clearBuffer();
  u8g2.sendBuffer();

  u8g2.clearBuffer();
  u8g2.drawRFrame(0, 30, 128, 64, 7);
  u8g2.drawStr(4, 44, "SERVEO    ");
  u8g2.drawStr(0, 64, "in association ");
  u8g2.drawStr(0, 84, "  JOHN DEERE  ");
  u8g2.sendBuffer();
  delay(20);
  u8g2.clearBuffer();
  u8g2.sendBuffer();

  u8g2.clearBuffer();
  u8g2.drawRFrame(0, 28, 128, 64, 7);
  u8g2.drawStr(4, 42, "SERVEO    ");
  u8g2.drawStr(0, 62, "in association ");
  u8g2.drawStr(0, 82, "  JOHN DEERE  ");
  u8g2.sendBuffer();
  delay(20);
  u8g2.clearBuffer();
  u8g2.sendBuffer();

  u8g2.clearBuffer();
  u8g2.drawRFrame(0, 26, 128, 64, 7);
  u8g2.drawStr(4, 40, "SERVEO   ");
  u8g2.drawStr(0, 60, "in association ");
  u8g2.drawStr(0, 80, "  JOHN DEERE  ");
  u8g2.sendBuffer();
  delay(20);
  u8g2.clearBuffer();
  u8g2.sendBuffer();

  u8g2.clearBuffer();
  u8g2.drawRFrame(0, 24, 128, 64, 7);
  u8g2.drawStr(4, 38, "SERVEO   ");
  u8g2.drawStr(0, 58, "in association ");
  u8g2.drawStr(0, 78, "  JOHN DEERE  ");
  u8g2.sendBuffer();
  delay(20);
  u8g2.clearBuffer();
  u8g2.sendBuffer();

  u8g2.clearBuffer();
  u8g2.drawRFrame(0, 22, 128, 64, 7);
  u8g2.drawStr(4, 36, "SERVEO    ");
  u8g2.drawStr(0, 56, "in association ");
  u8g2.drawStr(0, 76, "  JOHN DEERE  ");
  u8g2.sendBuffer();
  delay(20);
  u8g2.clearBuffer();
  u8g2.sendBuffer();


  u8g2.clearBuffer();
  u8g2.drawRFrame(0, 20, 128, 64, 7);
  u8g2.drawStr(4, 34, "SERVEO    ");
  u8g2.drawStr(0, 54, "in association ");
  u8g2.drawStr(0, 74, "  JOHN DEERE  ");
  u8g2.sendBuffer();
  delay(20);
  u8g2.clearBuffer();
  u8g2.sendBuffer();

  u8g2.clearBuffer();
  u8g2.drawRFrame(0, 18, 128, 64, 7);
  u8g2.drawStr(4, 32, "SERVEO    ");
  u8g2.drawStr(0, 52, "in association ");
  u8g2.drawStr(0, 72, "  JOHN DEERE  ");
  u8g2.sendBuffer();
  delay(20);
  u8g2.clearBuffer();
  u8g2.sendBuffer();

  u8g2.clearBuffer();
  u8g2.drawRFrame(0, 16, 128, 64, 7);
  u8g2.drawStr(4, 30, "SERVEO    ");
  u8g2.drawStr(0, 50, "in association ");
  u8g2.drawStr(0, 70, "  JOHN DEERE  ");
  u8g2.sendBuffer();
  delay(20);
  u8g2.clearBuffer();
  u8g2.sendBuffer();

  u8g2.clearBuffer();
  u8g2.drawRFrame(0, 14, 128, 64, 7);
  u8g2.drawStr(4, 28, "SERVEO    ");
  u8g2.drawStr(0, 48, "in association ");
  u8g2.drawStr(0, 68, "  JOHN DEERE  ");
  u8g2.sendBuffer();
  delay(20);
  u8g2.clearBuffer();
  u8g2.sendBuffer();


  u8g2.clearBuffer();
  u8g2.drawRFrame(0, 12, 128, 64, 7);
  u8g2.drawStr(4, 26, "SERVEO     ");
  u8g2.drawStr(0, 46, "in association ");
  u8g2.drawStr(0, 66, "  JOHN DEERE  ");
  u8g2.sendBuffer();
  delay(20);
  u8g2.clearBuffer();
  u8g2.sendBuffer();
  u8g2.clearBuffer();
  u8g2.drawRFrame(0, 10, 128, 64, 7);
  u8g2.drawStr(4, 24, "SERVEO    ");
  u8g2.drawStr(0, 44, "in association ");
  u8g2.drawStr(0, 64, "  JOHN DEERE  ");
  u8g2.sendBuffer();
  delay(20);
  u8g2.clearBuffer();
  u8g2.sendBuffer();

  u8g2.clearBuffer();
  u8g2.drawRFrame(0, 8, 128, 64, 7);
  u8g2.drawStr(4, 22, "SERVEO     ");
  u8g2.drawStr(0, 42, "in association ");
  u8g2.drawStr(0, 62, "  JOHN DEERE  ");
  u8g2.sendBuffer();
  delay(20);
  u8g2.clearBuffer();
  u8g2.sendBuffer();
  u8g2.clearBuffer();
  u8g2.drawRFrame(0, 6, 128, 64, 7);
  u8g2.drawStr(4, 20, "SERVEO    ");
  u8g2.drawStr(0, 40, "in association ");
  u8g2.drawStr(0, 60, "  JOHN DEERE  ");
  u8g2.sendBuffer();
  delay(20);
  u8g2.clearBuffer();
  u8g2.sendBuffer();

  u8g2.clearBuffer();
  u8g2.drawRFrame(0, 4, 128, 64, 7);
  u8g2.drawStr(4, 18, "SERVEO    ");
  u8g2.drawStr(0, 38, "in association ");
  u8g2.drawStr(0, 58, "  JOHN DEERE  ");
  u8g2.sendBuffer();
  delay(20);
  u8g2.clearBuffer();
  u8g2.sendBuffer();
  u8g2.clearBuffer();
  u8g2.drawRFrame(0, 2, 128, 64, 7);
  u8g2.drawStr(4, 16, "SERVEO     ");
  u8g2.drawStr(0, 36, "in association ");
  u8g2.drawStr(0, 56, "  JOHN DEERE  ");
  u8g2.sendBuffer();
  delay(20);
  u8g2.clearBuffer();
  u8g2.sendBuffer();
  u8g2.clearBuffer();
  u8g2.drawRFrame(0, 0, 128, 64, 7);
  u8g2.drawStr(4, 14, "SERVEO    ");
  u8g2.drawStr(0, 34, "in association ");
  u8g2.drawStr(0, 54, "  JOHN DEERE  ");
  u8g2.sendBuffer();
  delay(2000);

  u8g2.setFont(u8g2_font_squeezed_b6_tr );
  u8g2.clearBuffer();
  u8g2.drawRFrame(0, 0, 128, 64, 7);
  u8g2.drawStr(0, 14, " ANGEL PALACIOS");
  u8g2.drawStr(0, 34, " PATRICK KOLBUSZOWSKI ");
  u8g2.sendBuffer();


}

Https://docs.blynk.io/en/legacy-platform/legacy-articles/keep-your-void-loop-clean

Read this ! :point_up_2:t2::point_up_2:t2::point_up_2:t2::point_up_2:t2::point_up_2:t2::point_up_2:t2:

1 Like

good first of all thanks for answering but I think the program works well the problem is the disconnections that occur due to the environmental network of the place and I have already done more projects in my house on this and they are working perfectly. What I would like to know is how to change the reception port in blynk edgent. and see if someone else has the problem of disconnections. all the best.

Rule #1 - Keep your Void() loop clean
Rule #2 - Don’t use delay()

You may have got lucky before - but these golden rules need to be follwed

billd

Good morning, okay, I understand the problem, but the ESP disconnects if the code has a delay or doesn’t work well? And another thing, could you give me an idea of how to remove the delays from the code and clean the loop because there is little information on the web about the new blynk 2.0 and I come from arduino uno, nano… and the concept of cleaning is difficult for me the loop. I have a project in the factory and I would like it to go ahead because otherwise I will have to give up carrying it out and I will have to unsubscribe from blynk because I cannot continue. Without further ado, if someone can help me, I will appreciate it. Greetings and thank you.

HI, learn to use BlynkTimer (there are many posts about this)

If you are unfamiliar with timers I would recommend starting with a very basic sketch (say blink an led every second), use a timer to do this with a clean loop and no delays. Once you understand this, then apply the principles to your complex sketch.

walk before your run.

billd

The article that you were linked to is a great starting point. It was written for Legacy, but the principals are the same.
You are already using BlynkTimer, but not as well as you should - you are dong a millis() comparison in your void loop which ought be an additional timer process.
You can also use non-blocking delays using BlynkTimer.
More info on all of this here…

The timers that you do have appear to be used to poll physical switches, and I suspect that you’d be better using interrupts with a debounce routine for this.

I’m not sure that it’s possible to dictate the channel that your device can choose in the sketch. I think that this is probably best done in the router or WAP.
I’m guessing that there is electrical noise that is interfering with your devices? Monitoring the reported RSSI would probably be beneficial, possibly via your LCD display?

When you used an ESP8266 with external antenna what exact hardware was this?
If it was a Wemos D1 Mini Pro did you move the zero ohm resistor to enable the external antenna?
What exact hardware are you using now?

Pete.

Hello Pete, good morning, as always, he answers the questions with extreme accuracy, which is appreciated and thank you very much, first of all, for taking the attention. My starter board was the esp 8266 wemos d1 mini pro the resistor,
If I changed it so that the via was the external antenna.
Now I am using the wrover esp32 board with a modified antenna and taking an external antenna out of it.
I will look carefully at the article that you recommend and I will see what I can learn about timers.
What I would like to know is if, due to a bad code, the board disconnects from Wi-Fi or the program would not run normally?
I don’t know if one thing is related to the other.
In any case, I will try to learn from his article to see if I can solve it since I am stuck, greetings and good morning Pete.

As the legacy article explains, blocking delays can cause timeout errors when communicating with the Blynk server, leading to Blynk disconnections, but this won’t have an impact on the WiFi connection.

Is there a reason why you are using the Edgent sketch as the starting point for your project, if you find Edgent so confusing?

Pete.

Hi Pete, I’m using edgent because I have it active in other projects and it doesn’t give me any problems,
even with small delays they work and edgent is useful to me because it has ota and other functions that I don’t have to program. I don’t know if I’m doing it right. You think I should do it without edgent.
I honestly don’t know what I’m doing wrong. but I do not understand the disconnection of the Wi-Fi board even changing the boards.
I’m going to try to put a router closer to the two devices to see if this solves the problem, I’d really be sorry to have to leave the project,
I’ve put a lot of time and mind into it to leave it now, well anyway, thank you very much for your good help bye friend.
By the way, do you think that all the code I have can be solved with timers? Or would there be a problem?

That depends on you. Personally, I prefer to keep things as simple as possible. If you don’t need the provisioning features of Edgent and just want the Blynk.Air OTA then you might be better hard-coding your credentials and using the Blynk.Air minimal OTA code.

As I said, it’s probably caused by electric noise, but monitoring the RSSI would be my starting point.
But, eliminating bad programming practices such as a cluttered void loop and blocking delays would always be my starting point.

There are potentially other architectures you could explore, such as using LoRa to communicate between devices then using a LoRa to Blynk bridge in a less noisy environment, but without more info on the nature of the project and the cause of the problem it’s difficult to say.

Pete.

Well, my good friend Pete, I finally found the problem I was having, you won’t believe it, it was that the sim worked fine, you said that it didn’t have enough bandwidth to update the application data and that’s why the card, although I can’t explain it to myself because the Wi-Fi was working correctly,
the card dropped :flushed: well, I’ve been correcting the code and putting a timer in it and it’s cleaner. Well, what has been said, notice to surfers, if you put in SIM cards, take into account the sufficient bandwidth data.
Greetings and many thanks to all of you, and especially to Pete, who has been a professional helping :wink: the issue is resolved

So are you saying that you are using a 4G router and your mobile data subscription didn’t have sufficient data allowance to support the Blynk cloud connection for the two devices connected to it?

Pete.

That’s right, Pete, I know it’s incredible, but I’m sorry I had this error, but since the sim wasn’t mine, I didn’t know what data plan I had.
so I apologize and I thank you for the help received with special to you Pete, who was very involved. Greetings, I close the topic. Bye friends :upside_down_face: