Reconnect to the network

I am working with an Arduino Mega anb Ethernet Shield.
I am looking for a way to reconnect to the network.
If my device boots fine and has a network, everything is fine. If at some point the network goes down and my Arduino does not restart, it detects that I have lost the connection to the network service but I do not know how to restart the connection, without resetting my Arduino.

client.connect(ping,3306)

The network service I'm polling is a MySQL server port.
Summary, I am looking for the system to reset the network, without restarting the arduino.
I am attaching the program I am using to do the tests.
Thanks.

#include <SPI.h>
#include <Ethernet.h>

byte mac[] = { 0x00, 0xAA, 0xBB, 0xCC, 0xFF, 0x06};
IPAddress ping(192, 168, 102, 9);  //MySQL Server a enquestar  port 3306
EthernetClient client;

void setup() 
  {
  Serial.begin(9600);  
  Serial.println("Initialize Ethernet with DHCP:");
  //Ethernet.maintain() ;
  if (Ethernet.begin(mac) == 0)   // retorna 1 conexió amb DHCP amb exit, 0 Sense exit.
    {
    Serial.println("Failed to configure Ethernet using DHCP");
    if (Ethernet.hardwareStatus() == EthernetNoHardware) 
      {
      Serial.println("Ethernet shield was not found.  Sorry, can't run without hardware. :(");
      } 
    else if (Ethernet.linkStatus() == LinkOFF) 
      {
      Serial.println("Ethernet cable is not connected.");
      }
    }
  // print your local IP address:
  Serial.print("My IP address: ");
  Serial.println(Ethernet.localIP()); 

  }

void loop()
  {
  if (client.connect(ping,3306)) 
    {
    Serial.println("Ping server BD OK");
    }
  else
    {
    Serial.println("Ping server BD KO !!!");      
    }   
  delay(5000);
  }

What does "goes down" mean? Do you disconnect the Arduino from the network? This isn't WiFi where disconnect may happen, an Ethernet connection shouldn't go up and down in normal usage.

You can check your link status with Ethernet.linkStatus() anytime. If this got lost and restored later on you can call Ethernet.begin() again to re-establish the IP layer.

Thanks.
Yes, it's ethernet and it shouldn't be lost, but if the remote computer disconnects temporarily I want to know.
I'll try what you say, maybe I'll be fine.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.