I note that if I disconnect ethernet cable for only a couple of second, the enc28j60 reconnect without problem.
But if i let it disconnected for a couple of minute, the sketch go on to try connecting whithout success, so I’ve to reboot the arduino to retrieve the connection.
Perhaps is there anywhere on the local server a parameter that can explain that?
@Alx-I presumably during the few seconds it doesn’t miss the Blynk hearbeat.
Study this sketch as you don’t need to reboot an Arduino when you lose connection to a Blynk server.
// BlynkNoBlock.ino for ENC28J60
#define BLYNK_PRINT Serial /* Comment this out to disable prints and save space */
#include <UIPEthernet.h>
#include <BlynkSimpleUIPEthernet.h>
BlynkTimer timer;
char auth[] = "xxxxxxxxxxxxxx";
unsigned int myEthernetTimeout = 5000; // Ethernet Connection Timeout (ECT)
unsigned int blynkInterval = 25000; // Check Server Frequency (CSF)
byte arduino_mac[] = { 0xDE, 0xED, 0xBA, 0xFE, 0xFE, 0xED }; //DE:ED:BA:FE:FE:ED
char server[]= "blynk-cloud.com"; // can use "blynk-cloud.com" or an IP address
IPAddress arduino_ip ( 192, 168, 10, 120);
IPAddress dns_ip ( 192, 168, 10, 90);
IPAddress gateway_ip ( 192, 168, 10, 90);
IPAddress subnet_mask(255, 255, 255, 0);
void setup()
{
Serial.begin(115200); // Debug console, Mega is OK at 115200
Serial.println();
timer.setInterval(myEthernetTimeout, myfunction);
timer.setInterval(blynkInterval, checkBlynk); // check connection to server per blynkInterval
Ethernet.begin(arduino_mac, arduino_ip, dns_ip, gateway_ip, subnet_mask );
Blynk.config(auth, server); // this is OK
Blynk.connect(); // this is OK
}
void myfunction(){
Serial.println("\tLook, no Blynk block.");
if(Blynk.connected()){
Serial.println("\tEthernet still connected.");
Blynk.virtualWrite(V11, millis() / 1000);
}
}
void checkBlynk() {
unsigned long startConnecting = millis();
while(!Blynk.connected()){
Blynk.connect();
if(millis() > startConnecting + myEthernetTimeout){
Serial.println("\tUnable to connect to server. ");
break;
}
}
Serial.print("\tChecking again in ");
Serial.print(blynkInterval / 1000.0);
Serial.println("s.");
}
void loop()
{
if (Blynk.connected()) {
Blynk.run();
}
timer.run();
}
No, the heartbeats are well there because I can see them in the serial…
But after a too long time, it fails to reconnect.
My sketch is similar to yours…
//V1.1: to test stability connection & debug (23648/1357)
//<<LIBRARIES>>
#define BLYNK_PRINT Serial // Comment this out to disable prints and save flash space
#define BLYNK_DEBUG // Optional, this enables lots of prints
#define BLYNK_NO_BUILTIN // Disable built-in analog & digital pin operations to spare flash space
#define BLYNK_NO_FLOAT // Disable float operations to spare flash space
#define BLYNK_NO_INFO // Skip device info to spare flash space
#include <BlynkSimpleUIPEthernet.h> // ENC28J60 ethernet BLYNK library
char auth[] = ".....................
char Flag_Init_Boot='0';
// Mac address should be different for each device in your LAN
//byte arduino_mac[] = { 0xDE, 0xED, 0xBA, 0xFE, 0xFE, 0xED }; //Original mac address
byte mac[] = { 0xDE, 0x................... };
IPAddress localip ( 192, 1......... // your arduino i.p address, through ENC28J60
IPAddress mydns ( 192, ...........
IPAddress gateway ( 192,.........
IPAddress subnet (255..........
IPAddress serverip (109.......... // your local server i.p address 109.89.253.243
void setup() {
Serial.begin(9600); // start serial for output
Blynk.begin(auth, serverip, 8442, localip, mydns, gateway, subnet, mac);
}
void loop(){
while (Blynk.connected()==false) {Blynk.disconnect(); Blynk.connect();}
Blynk.run();
if (Flag_Init_Boot=='0'){
Blynk.email(F("R8"),F("WD"));
Flag_Init_Boot='1';
}
}
I actually use the ENC on a Mega. You are probably out of memory on the Nano and you would need to do the same memory saving adjustments that you have in your original sketch.