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);
}