HELP continuous reconnection

Hello,
in my sketch I send an email when blynk is connected:

BLYNK_CONNECTED() {     Blynk.email("xxxxxxxx@gmail.com", "Connessione Blynk", "Arduino Mega si è collegato al server Local Blynk");
}

This is my setting:
-blynk local server running on raspberry (v0.41.5)
-arduino mega with ENC28J60
-v0.6.1 library

The past two days I received at about 4-5 emails each days (so I suppose that arduino lost the connection with the server for the same times).
Now, I’m receiving email each minute… Nothing is changed…

What should I check?

Please post your complete sketch, always easier :slight_smile: Have you enabled debug? Could give some valuable information about what’s going on.

This is the sketch…

#define BLYNK_PRINT Serial
#define RECUPERATORE 34   // RECUPERATORE
#define VEL_REC 12   // VELOCITA' RECUPERATORE
#define PDC_RISC 38  // PDC RISCALDAMENTO
#define PDC_RAFFR 40   // PDC RAFFRESCAMENTO
#define DEUM 35  // DEUMIDIFICATORE
#define VALVOLA_DEUM 43   // VALVOLA DEUMIDIFICATORE
#define TESTINE_CASA 41   // TESTINE CASA
#define TESTINE_CAMERA 39   // TESTINE CAMERA
#define TESTINE_TAVERNA 36   // TESTINE TAVERNA
#define TESTINE_BAGNO_TAVERNA 37   // TESTINE BAGNO TAVERNA

#define T1_UP 22   // TAPPARELLA 1 SU
#define T1_DOWN 23   // TAPPARELLA 1 GIU
#define T2_UP 24   // TAPPARELLA 2 SU
#define T2_DOWN 25   // TAPPARELLA 2 GIU
#define T3_UP 28   // TAPPARELLA 3 SU
#define T3_DOWN 27   // TAPPARELLA 3 GIU
#define T4_UP 26   // TAPPARELLA 4 SU
#define T4_DOWN 29   // TAPPARELLA 4 GIU
#define T5_UP 30   // TAPPARELLA 5 SU
#define T5_DOWN 31   // TAPPARELLA 5 GIU
#define T6_UP 32   // TAPPARELLA 6 SU
#define T6_DOWN 33   // TAPPARELLA 6 GIU
#define ISTERESI_T 0.5   // ISTERESI TEMPERATURA
#define ISTERESI_H 5   // ISTERESI UMIDITA

#include <UIPEthernet.h>
#include <BlynkSimpleUIPEthernet.h>
/*
#include <ESP8266_Lib.h>
#include <BlynkSimpleShieldEsp8266.h>
char ssid[] = "FESSO_CHI_LEGGE";
char pass[] = "xxxxxxxxxxxxxxx";
#define EspSerial Serial1
#define ESP8266_BAUD 115200
ESP8266 wifi(&EspSerial);
*/
#include <DHT.h>
#include <PZEM004T.h>
#include <TimeLib.h>
#include <WidgetRTC.h>
IPAddress ip(192,168,1,1);

char auth[] = "xxxxxxxxxxxxxxx";
//il server è 192, 168, 0, 10. forwarding da 192, 168, 10, 4

IPAddress server_ip (192, 168, 10, 4);
byte arduino_mac[] = { 0xDE, 0xED, 0xBA, 0xFE, 0xFE, 0xED };
IPAddress arduino_ip ( 192,   168,   10,  5);
IPAddress dns_ip     (  8,   8,   8,   8);
IPAddress gateway_ip ( 192,   168,   10,   1);
IPAddress subnet_mask(255, 255, 255,   0);

#define DHTCAMERAPIN 3          // SENSORE CAMERA
#define DHTCASAPIN 4          // SENSORE CASA
#define DHTTAVERBAPIN 9          // SENSORE TAVERNA
#define DHTEXTPIN 2          // SENSORE ESTERNO
#define DHTTYPE DHT22   // DHT 22, AM2302, AM2321

DHT sensore_camera(DHTCAMERAPIN, DHTTYPE);
DHT sensore_casa(DHTCASAPIN, DHT11);
DHT sensore_taverna(DHTTAVERBAPIN, DHTTYPE);
DHT sensore_ext(DHTEXTPIN, DHTTYPE);
BlynkTimer timer;
WidgetRTC rtc;

PZEM004T pzem(10,11);  // (RX,TX) connect to TX,RX of PZEM

bool autom, flaginvio;

unsigned long intervallo_rec;
int mode, velocita, velocita1, velocita2, velocita3, velocita4, count,setpointh;
void stop_clima();
void on_inverno();
void on_estate();
void stop_rec(),tempo_recuperatore(),on_rec();
void opentap(),closetap(),offtap();
float h_cam,t_cam,h_tav,t_tav,h_casa,t_casa,h_ext,t_ext,e, energia=0,setpointtaverna, setpointcamera;
int t1_h,t1_m,t2_h,t2_m,t3_h,t3_m,t1stop_h,t1stop_m,t2stop_h,t2stop_m,t3stop_h,t3stop_m;

int dayinvio=10;
int eprec=0;
int euro=24;

/////////////////////////////////////////////////////IFTT////////////////////////////////////////////////////////////////////////////////
BLYNK_WRITE(V36){                          
  switch (param.asInt()) {
    
      case 1: //pulsante accensione spot recuperatore
                            velocita=velocita1;   //imposto la velocità spot
                            autom=LOW;            //disabilito modalita auto per abilitare counter
                            on_rec();            //chiamo funzione per accendere
                            break;
      
      case 2: //pulsante alza tap
                            opentap(); 
                            delay (1000); 
                            offtap(); 
                            break;
                            
      case 3: //pulsante abbassa tap
                            closetap(); 
                            delay (1000); 
                            offtap(); 
                            break;                            
                            
      case 4: //pulsante abbassa tap
                            closetap(); 
                            delay (500); 
                            offtap(); 
                            break;                            
                            } 
} 
/////////////////////////////////////////////////////INVIO MAIL////////////////////////////////////////////////////////////////////////////////
void invio_mail()
{
  String currentTime = String(hour()) + ":" + minute() + ":" + second();      //orario e data
  String currentDate = String(day()) + " " + month() + " " + year();
  Blynk.virtualWrite(V40, currentTime);
  Blynk.virtualWrite(V41, currentDate);

  if(hour()==dayinvio&&flaginvio==true){Serial.println("INVIO!!");              //controllo che si il giorno dell'invio e che non sia già stata inviata
                      flaginvio=false;
                      String body = String("Energia consumata nel mese ") + month() + String("= ") + e + " wh.";
                      Blynk.email("xxxxxxxxxxxxx@gmail.com", "Consumo mensile Energia", body);
                      }
  if(hour()!=dayinvio){flaginvio=true;}
   
}

/////////////////////////////////////////////////////AMPEROMETRICA////////////////////////////////////////////////////////////////////////////////
void amp(){
  
  e = pzem.energy(ip);                                          //energia  
  if(e >= 0.0){ Serial.print(e);Serial.print("Wh; "); 
                      Blynk.virtualWrite(V37, e*0.001);
                      Blynk.virtualWrite(V38, e*euro*0.01*0.001);     //energia*euro
                      }
  float p = pzem.power(ip);                                           //potenza
  if(p >= 0.0){ Serial.print(p);Serial.print("W; "); 
                Blynk.virtualWrite(V39, p);}
  Serial.println();
}

/////////////////////////////////////////////////////TAPPARELLE////////////////////////////////////////////////////////////////////////////////
BLYNK_WRITE(V32) {    opentap(); 
                      delay (1000); 
                      offtap(); 
                      Blynk.virtualWrite(V32, LOW);}      //apri, dopo 500ms spegni rele e spegni pulsante 
                      
BLYNK_WRITE(V33) {    opentap(); 
                      delay (500); 
                      offtap();                                       //apri, dopo 100ms spegni rele serve per fermare
                      //timer.setTimeout(4000L, []() {closetap();delay (500);offtap();} );          //dopo 4s: chiudi, dopo 500ms spegni rele                
                      Blynk.virtualWrite(V33, LOW);                       }  
                      
BLYNK_WRITE(V34) {    closetap(); 
                      delay (1000); 
                      offtap(); 
                      Blynk.virtualWrite(V34, LOW);}     //chiudi, dopo 500ms spegni rele e spegni pulsante 



/////////////////////////////////////////////////////SENSORI////////////////////////////////////////////////////////////////////////////////
void sendSensor()
      { h_cam = sensore_camera.readHumidity();        //lettura sensori
        t_cam = sensore_camera.readTemperature(); 
        h_tav = sensore_taverna.readHumidity();
        t_tav = sensore_taverna.readTemperature();
        h_casa = sensore_casa.readHumidity();
        t_casa = sensore_casa.readTemperature();
        h_ext = sensore_ext.readHumidity();
        t_ext = sensore_ext.readTemperature();
        
        if (isnan(h_cam)||isnan(t_cam)||isnan(h_casa)||isnan(t_casa)||isnan(h_ext)||isnan(t_ext)||isnan(h_tav)||isnan(t_tav)) { Serial.println("Failed to read from DHT sensor!");}

        Blynk.virtualWrite(V5, h_cam);                //scrittura su widget
        Blynk.virtualWrite(V6, t_cam);
        Blynk.virtualWrite(V29, h_casa);
        Blynk.virtualWrite(V28, t_casa);
        Blynk.virtualWrite(V27, h_ext);
        Blynk.virtualWrite(V26, t_ext);
        Blynk.virtualWrite(V15, t_tav);
        Blynk.virtualWrite(V14, h_tav);
      }

/////////////////////////////////////////////////////CLIMA////////////////////////////////////////////////////////////////////////////////
void ctrl()
{  if (mode==2){ on_inverno();
                                       if (t_cam<=setpointcamera-ISTERESI_T){ digitalWrite (TESTINE_CAMERA, HIGH);
                                                              Blynk.virtualWrite(V11, 1);
                                                              }
                                       if (t_cam>=setpointcamera){ digitalWrite (TESTINE_CAMERA, LOW);
                                                                   Blynk.virtualWrite(V11, 0);
                                                                   }
                                       if (t_tav<=setpointtaverna-ISTERESI_T){ digitalWrite (TESTINE_TAVERNA, HIGH);
                                                                              Blynk.virtualWrite(V13, 1);
                                                                              }
                                       if (t_tav>=setpointtaverna){ digitalWrite (TESTINE_TAVERNA, LOW);
                                                                    Blynk.virtualWrite(V13, 0);
                                                                    }}
                                                                    
  if (mode==3){ on_estate();
                                       if (h_casa<=setpointh){   digitalWrite (DEUM, LOW);
                                                                            digitalWrite (VALVOLA_DEUM, LOW);
                                                                            Blynk.virtualWrite(V25, 0);
                                                                            }
                                       if (h_casa>=setpointh+ISTERESI_H){   digitalWrite (DEUM, HIGH);
                                                                             digitalWrite (VALVOLA_DEUM, HIGH);
                                                                             Blynk.virtualWrite(V25, 1);
                                                                             }}                               
  if (mode==1)stop_clima();
}

BLYNK_WRITE(V10) {    setpointcamera=param.asFloat();}
BLYNK_WRITE(V12) {    setpointtaverna=param.asFloat();}
BLYNK_WRITE(V35) {    setpointh=param.asInt();}
BLYNK_WRITE(V0) {      mode=param.asInt();  }             //widget selezione modalita

//////////////////////////////////////////////////////////////////RECUPERATORE/////////////////////////////////////////////////////////////////////////////////////////

BLYNK_WRITE(V1){                                  //pulsante accensione spot recuperatore
  if (param.asInt()==HIGH) {velocita=velocita1;   //imposto la velocità spot
                            autom=LOW;            //disabilito modalita auto per abilitare counter
                            on_rec();            //chiamo funzione per accendere
                            }
  else stop_rec();
}           

void ctrl_recuperatore()                                       //funzione controllo timer
{  
  if (t1_h==hour()&&t1_m==minute()&&digitalRead(RECUPERATORE)==LOW){autom=HIGH;                      //abilito modalita auto per non entrare nel counter 
                                                       velocita=velocita2;              //imposto la velocità 
                                                       on_rec();   } 
  if (t2_h==hour()&&t2_m==minute()&&digitalRead(RECUPERATORE)==LOW){autom=HIGH;                      //abilito modalita auto per non entrare nel counter 
                                                       velocita=velocita3;              //imposto la velocità 
                                                        on_rec();   } 
  if (t3_h==hour()&&t3_m==minute()&&digitalRead(RECUPERATORE)==LOW){autom=HIGH;                      //abilito modalita auto per non entrare nel counter 
                                                       velocita=velocita4;              //imposto la velocità 
                                                        on_rec();   } 


  if ((t1stop_h==hour()&&t1stop_m==minute()&&digitalRead(RECUPERATORE)==HIGH)||
      (t2stop_h==hour()&&t2stop_m==minute()&&digitalRead(RECUPERATORE)==HIGH)||
      (t3stop_h==hour()&&t3stop_m==minute()&&digitalRead(RECUPERATORE)==HIGH))stop_rec();

  Blynk.virtualWrite(V22, digitalRead (RECUPERATORE)*velocita/51);                     //grafico il pin di comando al rec
} 
 
void on_rec()
{  Blynk.virtualWrite(V1, 1);            //accendo pulsante 
   digitalWrite (RECUPERATORE, HIGH);   //accendo recuperatore
   analogWrite (VEL_REC,velocita );      //imposto velocita
   Blynk.virtualWrite(V7, velocita/51);}  //scrivo velocita su widget                                                                                
 
void stop_rec()
{  digitalWrite (RECUPERATORE, LOW);       //spengo recuperatore
   Blynk.virtualWrite(V1, 0);               //spengo pulsante
   autom=HIGH;                              //abilito modalita auto per non entrare nel counter
   Blynk.virtualWrite(V7, 0);               //scrivo vel 0%
   count=0;}
   
void tempo_recuperatore()                                       //funzione per spegnere rec dopo tot tempo
{  if (autom==LOW){ if (count>=intervallo_rec){stop_rec();      //inizio a contare se la modalita auto è disabilitata
                                               count=0;
                                               }
                    else count++;}}
     
BLYNK_WRITE(V4){velocita1 = 51*param.asInt();}             //slider velocità spot, 5 velocità->51*5=255
BLYNK_WRITE(V9){velocita2 = 51*param.asInt();}             //slider velocità orario 1, 5 velocità->51*5=255
BLYNK_WRITE(V18){velocita3 = 51*param.asInt();}             //slider velocità orario 2, 5 velocità->51*5=255
BLYNK_WRITE(V20){velocita4 = 51*param.asInt();}             //slider velocità orario 3, 5 velocità->51*5=255
BLYNK_WRITE(V8){intervallo_rec = param.asInt();}            //tempo attività recuperatore modalità spot

BLYNK_WRITE(V42) {TimeInputParam t(param);
                  t1_h=t.getStartHour();
                  t1_m=t.getStartMinute();
                  t1stop_h=t.getStopHour();
                  t1stop_m=t.getStopMinute();}
BLYNK_WRITE(V43) {TimeInputParam t(param);
                  t2_h=t.getStartHour();
                  t2_m=t.getStartMinute();
                  t2stop_h=t.getStopHour();
                  t2stop_m=t.getStopMinute();}
BLYNK_WRITE(V44) {TimeInputParam t(param);
                  t3_h=t.getStartHour();
                  t3_m=t.getStartMinute();
                  t3stop_h=t.getStopHour();
                  t3stop_m=t.getStopMinute();}
void graph()
{ 
  Blynk.virtualWrite(V22, digitalRead (RECUPERATORE)*velocita/51);         //grafico il pin di comando al rec
}


void setup()
{
  Serial.begin(9600);
//LAN
  //Blynk.begin(auth, "192.168.10.4", 8080);    
  //Blynk.begin(auth, "192.168.0.10", 8080);
  Blynk.begin(auth, server_ip, 8080, arduino_ip, dns_ip, gateway_ip, subnet_mask, arduino_mac);
/*
//wifi
  EspSerial.begin(ESP8266_BAUD);
  delay(10);
  Blynk.begin(auth, wifi, ssid, pass, "192.168.0.10", 8080);
*/
//sincronizzazione orario
  setSyncInterval(10 * 60);                               // Sync interval per il controllo del tempo(10 minutes)

//inizializazine pin uscita
  pinMode(PDC_RISC, OUTPUT);
  digitalWrite (PDC_RISC, LOW);
  pinMode(PDC_RAFFR, OUTPUT);
  digitalWrite (PDC_RAFFR, LOW);
  pinMode(DEUM, OUTPUT);
  digitalWrite (DEUM, LOW);
  pinMode(VALVOLA_DEUM, OUTPUT);
  digitalWrite (VALVOLA_DEUM, LOW);
  pinMode(TESTINE_CASA, OUTPUT);
  digitalWrite (TESTINE_CASA, LOW);
  pinMode(TESTINE_CAMERA, OUTPUT);
  digitalWrite (TESTINE_CAMERA, LOW);
  pinMode(TESTINE_TAVERNA, OUTPUT);
  digitalWrite (TESTINE_TAVERNA, LOW);
  pinMode(TESTINE_BAGNO_TAVERNA, OUTPUT);
  digitalWrite (TESTINE_BAGNO_TAVERNA, LOW);
  pinMode(T1_UP, OUTPUT);
  digitalWrite (T1_UP, LOW);
  pinMode(T1_DOWN, OUTPUT);
  digitalWrite (T1_DOWN, LOW);
  pinMode(T2_UP, OUTPUT);
  digitalWrite (T2_UP, LOW);
  pinMode(T2_DOWN, OUTPUT);
  digitalWrite (T2_DOWN, LOW);
  pinMode(T3_UP, OUTPUT);
  digitalWrite (T3_UP, LOW);
  pinMode(T3_DOWN, OUTPUT);
  digitalWrite (T3_DOWN, LOW);
  pinMode(T4_UP, OUTPUT);
  digitalWrite (T4_UP, LOW);
  pinMode(T4_DOWN, OUTPUT);
  digitalWrite (T4_DOWN, LOW);
  pinMode(T5_UP, OUTPUT);
  digitalWrite (T5_UP, LOW);
  pinMode(T5_DOWN, OUTPUT);
  digitalWrite (T5_DOWN, LOW);
  pinMode(T6_UP, OUTPUT);
  digitalWrite (T6_UP, LOW);
  pinMode(T6_DOWN, OUTPUT);
  digitalWrite (T6_DOWN, LOW);
  
//inizializazine sensori temp h
  sensore_camera.begin();
  sensore_taverna.begin();
  sensore_casa.begin();
  sensore_ext.begin();
  
//richiamo funzioni ogni tot ms 
  timer.setInterval(10000L, invio_mail);        //frequenza controllo invio mail
  flaginvio=true;
  timer.setInterval(10000L, sendSensor);     //frequenza aggiornamento sensori
  timer.setInterval(10000L, ctrl);           //frequenza aggiornamento controllo clima
  timer.setInterval(5000L, amp);           //frequenza aggiornamento consumi elettrici
  
//recuperatore
  pinMode(RECUPERATORE, OUTPUT);
  pinMode(VEL_REC, OUTPUT);
  count=0;
  autom=HIGH;
  timer.setInterval(60000L, tempo_recuperatore);    //contatore recuperatore ogni minuto modalità spot
  timer.setInterval(3000L, ctrl_recuperatore);    //controllo tempo timer recuperatore ogni 3s
  
}

BLYNK_CONNECTED() {                                                             //sincronizza le variabili appena arduino si connette al server
          Blynk.syncVirtual(V4,V9,V18,V20,V8,V1,V42,V43,V44); //RECUPERATORE
          Blynk.syncVirtual(V0,V10,V12,V35); //CLIMA 
          rtc.begin();
          Blynk.email("xxxxxxxxxxxx@gmail.com", "Connessione Blynk", "Arduino Mega si è collegato al server Local Blynk");
}

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

void on_inverno(){
  digitalWrite (PDC_RISC, HIGH);
  Blynk.virtualWrite(V23, 1);
  digitalWrite (PDC_RAFFR, LOW);
  Blynk.virtualWrite(V24, 0);
  digitalWrite (DEUM, LOW);
  digitalWrite (VALVOLA_DEUM, LOW);
  Blynk.virtualWrite(V25, 0);
  digitalWrite (TESTINE_CASA, HIGH);
  Blynk.virtualWrite(V30, 1);
 // digitalWrite (TESTINE_CAMERA, !HIGH);
  //Blynk.virtualWrite(V11, 1);
//  digitalWrite (TESTINE_TAVERNA, !HIGH);
  digitalWrite (TESTINE_BAGNO_TAVERNA, HIGH);
  Blynk.virtualWrite(V31, 1);
    }

void on_estate(){
  digitalWrite (PDC_RISC, LOW);
  Blynk.virtualWrite(V23, 0);
  digitalWrite (PDC_RAFFR, HIGH);
  Blynk.virtualWrite(V24, 1);
  //digitalWrite (DEUM, !HIGH);
  //digitalWrite (VALVOLA_DEUM, !HIGH);
  digitalWrite (TESTINE_CASA, HIGH);
  Blynk.virtualWrite(V30, 1);
  digitalWrite (TESTINE_CAMERA, HIGH);
  Blynk.virtualWrite(V11, 1);
  digitalWrite (TESTINE_TAVERNA, LOW);
  Blynk.virtualWrite(V13, 0);
  digitalWrite (TESTINE_BAGNO_TAVERNA, LOW);
  Blynk.virtualWrite(V31, 0);
    }

void stop_clima(){
  digitalWrite (PDC_RISC, LOW);
  Blynk.virtualWrite(V23, 0);
  digitalWrite (PDC_RAFFR, LOW);
  Blynk.virtualWrite(V24, 0);
  digitalWrite (DEUM, LOW);
  digitalWrite (VALVOLA_DEUM, LOW);
  Blynk.virtualWrite(V25, 0);
  digitalWrite (TESTINE_CASA, LOW);
  Blynk.virtualWrite(V30, 0);
  digitalWrite (TESTINE_CAMERA, LOW);
  Blynk.virtualWrite(V11, 0);
  digitalWrite (TESTINE_TAVERNA, LOW);
  Blynk.virtualWrite(V13, 0);
  digitalWrite (TESTINE_BAGNO_TAVERNA, LOW);
  Blynk.virtualWrite(V31, 0);
    }

void opentap(){
  Serial.println("ALZA");
  digitalWrite (T1_UP, HIGH);
  digitalWrite (T1_DOWN, LOW);
  digitalWrite (T2_UP, HIGH);
  digitalWrite (T2_DOWN, LOW);
  digitalWrite (T3_UP, HIGH);
  digitalWrite (T3_DOWN, LOW);
  digitalWrite (T4_UP, HIGH);
  digitalWrite (T4_DOWN, LOW);
  digitalWrite (T5_UP, HIGH);
  digitalWrite (T5_DOWN, LOW);
//  digitalWrite (T6_UP, HIGH);
//  digitalWrite (T6_DOWN, LOW);
    }    

void closetap(){
  Serial.println("ABBASSA");
  digitalWrite (T1_UP, LOW);
  digitalWrite (T1_DOWN, HIGH);
  digitalWrite (T2_UP, LOW);
  digitalWrite (T2_DOWN, HIGH);
  digitalWrite (T3_UP, LOW);
  digitalWrite (T3_DOWN, HIGH);
  digitalWrite (T4_UP, LOW);
  digitalWrite (T4_DOWN, HIGH);
  digitalWrite (T5_UP, LOW);
  digitalWrite (T5_DOWN, HIGH);
//  digitalWrite (T6_UP, LOW);
//  digitalWrite (T6_DOWN, HIGH);
    }   

void offtap(){
  Serial.println("FERMA");
  digitalWrite (T1_UP, LOW);
  digitalWrite (T1_DOWN, LOW);
  digitalWrite (T2_UP, LOW);
  digitalWrite (T2_DOWN, LOW);
  digitalWrite (T3_UP, LOW);
  digitalWrite (T3_DOWN, LOW);
  digitalWrite (T4_UP, LOW);
  digitalWrite (T4_DOWN, LOW);
  digitalWrite (T5_UP, LOW);
  digitalWrite (T5_DOWN, LOW);
//  digitalWrite (T6_UP, LOW);
//  digitalWrite (T6_DOWN, LOW);
    }

I tried to compile my sketch with another pc with a new installation of the arduino ide…
After I installed the blynk library 0.6.1 and when I compile the sketch I see this error:
UIPEthernet.h no such file or directory…

But this library isn’t included in the blynk one?
Could be this the cause of the reconnection problem?

For three days I leave connected arduino mega in the pc, so the power supply was given by usb of the pc (the ENC28J60 is powered by the arduino mega ). For three days the disconnection/reconnection happend about twice a day… So reasonable…

Now I feed again energy to arduino mega with an external power supply (12VDC and the ENC28J60 is powered by the arduino mega) and again it starts to disconnect/reconnect often…
So the problem is the power supply? what is the best way to power supply arduino/ENC28J60 to avoid the reconnection?

Please help, thanks

Please read the datasheets :wink:

According to Arduino, a Mega R3 has a very limited current output:

DC Current for 3.3V Pin 50 mA

Looking at the datasheet for ENC28J60 we find this:

image

So you’ll probably don’t get enough juice in the wires. Why it’s working when powered thru USB seems very strange to me.

At a glance I think your sketch looks ok, but I’m always allergic to delays (you have some on V36 that’s a second long).

So my guesses: Not enough current to eth or the ENC28J60 is a crappy outdated controller that even I have thrown on the garbage heap! :smiley:

2 Likes

Thanks for your reply…
Now I feed energy to the ENC28J60 by an external 5VDC power supply…
With this configuration I have “only” about 2-3 reconnection per day…
Is it normal? Is it possible to eliminate totaly the reconnections? In a normal blynk project, how often reconnections happens?

What is a best ethernet board?

In my experience, the best Ethernet board is no Ethernet board at all.

Much better to go for a stand-alone ESP8266 or ESP32, or if you insist, an ESP-01 as a Wi-Fi modem for your Mega.

Pete.

On average, 2-3 drops a day for anything connected seems feasible to me [as long as it’s not your Mega rebooting]. There’s just too many factors you can’t control to eliminate them completely.

But… If I am reading your sketch correctly and you have 5 DHT’s that are read every 10 seconds “together”? I think the consensus among Blynkers are that they should be read with an interval equal to or greater than 5 seconds per sensor. @Gunner, @PeteKnight, do we have a consensus? :wink:

I don’t know which is the best, but the ENC28J60 have never been good :stuck_out_tongue: . Old components and a very heavy library!

I’m using the W5100 shield for my “long running” Blynk project and it haven’t failed yet (AFAIK).

:grin: But some of us favors cable! :wink:

1 Like

You have too many delay() commands in your active code!! They stop ALL processing, including Blynk communication, for the duration of the delay.

Yes. @Erik_Castelli The only valid place for a delay() (unless you really know what you are doing) is a short one (50-200ms perhaps) in between timers to help space them out from calling their respective functions simultaneously… thus adding to the “disconnection” factor.

1 Like

THANK YOU! :kissing_heart:

I’m still somewhat annoyed that the Blynk example browser still has a 1 Hz timer for the DHT11. It’s been proven over and over again that it’s too fast to work with Blynk (which I informed the founding fathers about in like 2017)!

According to myself :innocent: some libraries are slower than others:

And as always, who need to get a temperature reading every second? Unless your house is on fire, every 5 minutes is good enough :rofl:

Thanks for the replies.

So, I’ll remove the delays().
I think to modify the reading of the sensor like this:

in the setup function only:
timer.setInterval(20000L,readsensor1);

void readsensor1()
      { h_cam = sensore_camera.readHumidity();        //lettura sensori
        t_cam = sensore_camera.readTemperature(); 
       
        if (isnan(h_cam)||isnan(t_cam)) { Serial.println("Failed to read from DHT sensor!");}

        Blynk.virtualWrite(V5, h_cam);                //scrittura su widget
        Blynk.virtualWrite(V6, t_cam);
        timer.setTimeout(5000L,readsensor2());
      }

void readsensor2()
      { .........
        timer.setTimeout(5000L,readsensor3());
      }

..............

Could be a good idea to adopt this system (only ONE function called each n seconds and the other are called with the timer.setTimeout) with all my functions?
In this way I will be shure that each function has enough time to complete all the jobs…