Ethernet reconnection after power came back

Hi,
I have a project with blink, working very good from more than 3years.
Some time the power from the grid is missing and when it’s coming back my Arduino made the setups more faster then the router can assign the IP.
I tried with different setups for the ethernet.begin(Mac,IP), was put in the reconnection of the blynk loop but is not good. Just after 2-3 min one reset solve the problems, if I’m not at home is impossible to reset.
Tried with fixed IP, but is the same thing.

Working of Arduino code is more important than the internet connection, can be solved this with some ethernet setups? Or is better to use a UPS for Arduino?

Thanks
Ferox

UPS is good if you have a lot of power outages.

have you tried the following as the first line of setup()?

delay(longtimeinmilliseconds);

1 Like

I don’t think the problem is actually happening quite the way you’ve described it. These Arduino shields, especially the W5100 ones, are notoriously bad at restarting correctly. If you search this forum for W5100 you’ll see quite a few threads on the issue.
To prove the point, try powering the Arduino on and off several times with the router still powered up. Eventually you’ll see the shield go into a mode where one of the LEDs is flashing rapidly and the shield won’t connect to the internet until you hit the reset button.

Some shields seem better others, and many of the cheap ones are shipped with solder bridges across the pins of the main chip, which doesn’t help.

I have eventually migrated to ESP8266 devices because of this issue, and I’m so glad that I did - they’re much nicer and more powerful to work with, and much smaller. I do have one setup with requires the use of an Arduino and an Ethernet shield and I’ve built a solution where one of the GPIO pins is connected to the Arduino Reset pin. After startup, if I can’t get an internet connection (if I can’t ping an internet server) then I pull the GPIO pin that’s connected to Reset low, causing the Arduino to reboot. It’s not pretty, but it works!

Pete.

Thanks for replying
@Costas
I test it but not good for me.

@Pete
Good to know, the reset was my last though but is ok for now. Easy to implement.

I will rethink my project with ESP 8266.

Ferox

You could also look into ping and WDT with reboot.

hi,
I tried to use resetFunc and is working, after 1 min from start, blynk is conected :sunglasses:
litle to much coding but worked on first upload. If a coder put his finger on this code could be simplier :wink:
I put a counter to have first start after 1min, if router is not working after 2min, 4 min, 8min …something like this to reset again

int  count_blynkOUT   = 0;
int  read_blynkOUT    = 0;
int addressblynkOUT   = 70;

void(* resetFunc) (void) = 0; //declare reset function @ address 0
void setup(){
read_blynkOUT     = EEPROM.read(addressblynkOUT);
}
void reconnectBlynk() {                         // reconnect to server if disconnected, timer checks every 60 seconds
  if (!Blynk.connected()) {
    bool connecting = Blynk.connect(3333);
    resetArduino();
    if(connecting) {
      BLYNK_LOG("Reconnected");
    } else {
      BLYNK_LOG("Not reconnected");
    }
  }
  else{
    if (year() == 1970) {
      setSyncInterval(5);     // interval is declared in seconds
      notsynced = 1;
    }
    if (year() != 1970 && notsynced == 1) {
      setSyncInterval(600);     // interval is declared in seconds
      notsynced = 0;
    }
  }
}

void resetArduino(){         
  if( firstConnect){                                 //if blynk not connected +count
    count_blynkOUT += 1;
    if(count_blynkOUT > read_blynkOUT + 3) {
      EEPROM.write(addressblynkOUT, read_blynkOUT * 2+1);
      resetFunc();  //call reset
    }
  }
  else {                                                  //if blynk connected reset counter
    if(read_blynkOUT != 0){
      count_blynkOUT = 0;
      EEPROM.write(addressblynkOUT, count_blynkOUT);
    }}}

I like this reset is not the same like on the reset pin, I don’t know why.
this is just a part of my code

1 Like

I’m glad that this is working for you. I don’t think a function call to memory location 0 is really the right way to do this, but if it solves the problem then that’s great.
The Arduino EEPROM has limited write capabilities before the memory location you’re using will fail, so the reliability of the solution depends how many times you’re going to need to perform this reset routine.

Pete.