arduino Mega+ ethernet shield, problems( Solved)

Hi everyone. I recently got 2 ethernet shields based on the w5100 chip. They just work instantly and then stop working.
I ping them and sometimes I get <1ms(very few times) other times 100-500ms(most of the times).

when I try the standard web server aplication I can see for a second(if I am veeery lucky) how it displays the spected info in the web page, but then it says unable to carge the web... So then, I try to load the web again but I get nothing. And if i wait some time, may be minutes, it can sometimes work again for a second. And again and again....

I connected the shield directly to the router, and I can make tests with my computer connected to the router by wire or with other computers and laptops connecter by ethernet cable or by wifi.

I can do a lot of test if you want... :roll_eyes:

here is the code, It just says for how much ms is the arduino working already:

#include <SPI.h>
#include <Ethernet.h>
  
// Configuración de direccion MAC e IP.
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192,168,0,13);
  
// Inicia la libreria Ethernet server con el puerto 80 (por defecto el puerto HTTP).
EthernetServer server(80);
  
void setup() {
// Inicia el puerto serie.
Serial.begin(9600);
  
// Inicia la conexión Ethernet y el servidor.
Ethernet.begin(mac, ip);
server.begin();
Serial.print("IP local del servidor ");
Serial.println(Ethernet.localIP());
}
  
void loop() {
EthernetClient client = server.available(); // Escucha a los clientes entrantes.
    if (client) { // Si un cliente se conecta al servidor:
    Serial.println("Nuevo cliente");
    boolean currentLineIsBlank = true; // Marcador para enviar la respuesta desde el servidor.
        while (client.connected()) { // Repite mientas existe clientes conectados:
            if (client.available()) {
            char c = client.read();
            Serial.write(c); // Imprime por el puerto serie la petición del cliente (caracter a caracter)
                if (c == '\n' && currentLineIsBlank) { // Se envia la respuesta a una petición de un cliente cuando a finalizado la petición:
                // Respuesta:
                client.println("HTTP/1.1 200 OK"); // Enviar un encabezado de respuesta HTTP estándar
                client.println("Content-Type: text/html");
                client.println("Connection: close"); // Se cerrará la conexiós despues de enviar la respuesta.
                client.println("Refresh: 5"); // Refrescar automáticamente la página después de 5 segundos.
                client.println();
                client.println("<!DOCTYPE HTML>"); // Tipo de documento.
                client.println("<html>"); // Etiqueta html inicio del documento. 
                client.print("Hola soy Arduino!! - ");
                client.print(millis()); // Tiempo de funcionamiento en ms.
                client.print("ms encendido. ");
                client.println("
"); // Etiqueta html salto de linea. 
                client.println("</html>"); // Etiqueta html fin del documento.
                break;
                }
                if (c == '\n') { // Si el caracter es un salto de linea:
                currentLineIsBlank = true; // La petición a terminado, se respondera a dicha peticón en el sigueitne ciclo.
                } 
                else if (c != '\r') { // Si el caracter no es un retorno de carro (la petición no a terminado).
                currentLineIsBlank = false; // Seguimos escuchando la petición.
                }
           }
       }
    delay(1); // Espera para dar tiempo al navegador a recivir los datos.
    client.stop(); // Cierra la conexión.
    Serial.println("Cliente desconectado");
    Serial.println();
    }
}

I recently got 2 ethernet shields based on the w5100 chip. They just work instantly and then stop working.
I ping them and sometimes I get <1ms(very few times) other times 100-500ms(most of the times).

Do you have 2 Megas with ethernet shields connected at the same time? Or just one at a time?

Do you have 2 Megas with ethernet shields connected at the same time? Or just one at a time?

SurferTim, I just got 1 Mega and I am testing the shields.

I know that in the code there is a part where the server disconnects me as a client. But I don't know why I can't connect againg if i want to.

Also I feel like when the leds of the shield are calm, I mean that there are no rx tx blinks and all the yellow ligths are on , that is the time when it works.(I am not completly sure yet)

I think that during the time it is not working the "link" led blinks every time the rx an tx leds blink. So,...who is senthing things to the arduino??? Is it causing delays and malfuctions?

thank you

Do you have a SD card in the ethernet shield's slot?

Are you sure you have the correct network settings? Compile and run this sketch. What does the serial monitor show?

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

byte mac[] = {  0x00, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };

void setup() {
  Serial.begin(9600);

  // disable SD SPI
  pinMode(4,OUTPUT);
  digitalWrite(4,HIGH);

  Serial.print(F("Starting ethernet..."));
  if(!Ethernet.begin(mac)) Serial.println(F("failed"));
  else {
      Serial.print(F("IP: "));
      Serial.println(Ethernet.localIP());
      Serial.print(F("Subnet: "));
      Serial.println(Ethernet.subnetMask());
      Serial.print(F("Gateway: "));
      Serial.println(Ethernet.gatewayIP());
      Serial.print(F("DNS server: "));
      Serial.println(Ethernet.dnsServerIP());
}

void loop() {
}

it said this:

Starting ethernet...IP: 192.168.0.23
Subnet: 255.255.255.0
Gateway: 192.168.0.1
DNS server: 212.142.144.66

Then you have the correct network settings.

Here is a link to my server code on the playground. You might want to try the old server code. It is down near the bottom. Use your network settings with it.
http://playground.arduino.cc/Code/WebServerST

You can also search the forum for zoomkat's server code.

Lord SurferTim
you made
my day!
XD XD XD

I lose sooo many hours and also was quite disappointed with the purchase. But you, with one single tip(with erroneous code :P) solved my problem. arduino has a great community and I love that.

what is your veredict? was I fighting against the router behaviour. I tried to give the arduino and compatible IP which was 192.168.0.13 as at home all the gadgets are 192.168.0.x, but it seem that the router was trying to give me another ip. Does it make sense?

the shields are working for more than 20 minutes without any single error from 2 computers by cable and from a laptop by wifi.

You would laugh if you could see my happy face and movements. so funny...

I will also see your recomendations

but it seem that the router was trying to give me another ip. Does it make sense?

Yes. Typically, you configure the router to always assign a fixed address to the Arduino, and then use that address in the code. If you don't, the router will assign a different address, and then when you make a request, and ask that packets be routed back to the IP address in the code, the router doesn't route them to the Arduino, because that isn't the address it assigned to the Arduino.

You would laugh if you could see my happy face and movements. so funny...

Nope. Been there, done that. Know the feeling.