Arduino Ethernet Shield cannot start server

Hey guys,

yesterday I coded the following code. Today I started the arduino and it did not work anymore.

My Laptops IP Adress is: 192.168.178.56

The serial Monitor says "server not available" and "no client".

a ping works fine.

Please help me... :frowning:

 #include <SPI.h> 
 #include <Ethernet.h> 
 
 byte mac[] = { 0xBA, 0xFF, 0xAB, 0xCA, 0xCB, 0xAF };    // MAC ID of your Arduino
 byte ip[] = { 192, 168, 178, 3 };  // The IP address will be dependent on your local network
 

 byte gateway[] = { 192, 168, 178, 1 };
// the subnet:
byte subnet[] = { 255, 255, 255, 0 };


EthernetServer server = EthernetServer(80);
 
 

 String readString;  

    
    
   void setup()
       { 
       
        pinMode(6, OUTPUT);                           
        pinMode(7,OUTPUT);
        Ethernet.begin(mac, ip, gateway, subnet);                      //Start Ethernet connection and Server
        server.begin();  
        Serial.begin(9600); 
        Serial.println("Arduino connected"); //To keep on track 
       }   
        
   void loop(){ 
    
        EthernetClient client = server.available();  //Listen for the incoming ports
        
        if(server.available()){
          Serial.println("server available");
        }else{
          Serial.println("server not available");
        }
        
        
        if (client)                                  //Connects to clinet
        {        
        Serial.println("client available");                        
        while (client.connected()) { 
        if (client.available()) { 
        char c = client.read(); 
        if (readString.length() < 100) {  
        readString += c; 
       } 
    //if HTTP request has ended 
   if (c == '\n') { 
    
    Serial.println(readString);        //Print to serial monitor for debuging 


    
    client.println("HTTP/1.1 200 OK"); //Send new page 
    client.println("Content-Type: text/html"); 
    client.println(); 
    client.println("<HTML>"); 
    client.println("<HEAD>"); 
    //client.println("<meta http-equiv='refresh' content='15'>");
    client.println("<TITLE>Arduino Ethernet LEDn</TITLE>"); 
    client.println("</HEAD>"); 
    client.println("<BODY bgcolor='white'>"); 
    client.println("<H1>Arduino SMART HOME</H1>"); 
    client.println("<hr />"); 
    client.println("
"); 
    client.println("<a href=\"/?light1on\"\">light1 on</a>"); 
    client.println("<a href=\"/?light1off\"\">light1 off</a>


"); 
    client.println("<a href=\"/?light2on\"\">light2 on</a>"); 
    client.println("<a href=\"/?light2off\"\">light2 off</a>
");         
    client.println("</BODY>"); 
    client.println("</HTML>"); 
    
    delay(1); 
    
    //Stoping Client 
    client.stop(); 
    
    //Control Arduino Pin 
    if(readString.indexOf("?light1on") >0) //Checking for ON 
    { 
      digitalWrite(6, LOW);              // Set Pin 6 to HIGH 
      Serial.println("LED On"); 
    } 
    
    if(readString.indexOf("?light1off") >0)//Checking for OFF
    { 
      digitalWrite(6, HIGH);               // Set Pin 6 to LOW 
      Serial.println("LED Off"); 
    } 

    if(readString.indexOf("?light2on") >0) //Checking for ON 
    { 
      digitalWrite(7, LOW);              // Set Pin 6 to HIGH 
      Serial.println("LED On"); 
    } 
    
    if(readString.indexOf("?light2off") >0)//Checking for OFF
    { 
      digitalWrite(7, HIGH);               // Set Pin 6 to LOW 
      Serial.println("LED Off"); 
    } 
    
    readString="";                        //Clearing string for next read 
            } 
          } 
        } 
      }else{
        Serial.println("no client");
      }
    }

I don't know if this is your entire problem, but it is not correct. You omitted the dns server parameter. You can use the gateway IP if you are using a server sketch.

//change this
        Ethernet.begin(mac, ip, gateway, subnet); 

// to this
        Ethernet.begin(mac, ip, gateway, gateway, subnet);

I do not use a dns service. I changed it to Ethernet.begin(mac, ip);

still doesnt work...

Which ethernet shield do you have? Is it a w5100, w5200, w5500?

Did it ever work?

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

I have a w5500. Yes it worked yesterday and there is no sd card in the slot.

Did you import a new library? The ethernet library included with the IDE is not compatible with the w5500. I recommend using this one.

Did it. Still doesnt work.

So you think my code is okay?

Bananajoe3000:
The serial Monitor says "server not available" and "no client".

That is exactly what it should say, repeatedly, until you connect a client to the server.

   void loop(){ 
    
        EthernetClient client = server.available();  //Listen for the incoming ports
        
        if(server.available()){
          Serial.println("server available");  // The server has a new client connection
        }else{
          Serial.println("server not available");  // This just means "No client was waiting to connect"
        }
        
        
        if (client)                                  //Connects to clinet
        {        
        
      }else{
        Serial.println("no client");  // This means no new client was waiting to connect.
      }
    }

Maybe if you take out those two messages repeating many times per second you will be able to see the two messages that indicate that a client connection has arrived.

johnwasser has a point. You might be missing the client connect message.

Except for that, it looks ok, but it is hard to tell from here. Do you have PuTTY installed on your computer? That is what I use to test.

I also use this code to check the sockets for connections. You might need to change the include to utility/w5500.h. Add this to your sketch and call it when you want to check the socket status. If it doesn't show 8 sockets, you are still using the wrong library.

#include <utility/w5100.h>

byte socketStat[MAX_SOCK_NUM];

void ShowSockStatus()
{
  for (int i = 0; i < MAX_SOCK_NUM; i++) {
    Serial.print(F("Socket#"));
    Serial.print(i);
    uint8_t s = W5100.readSnSR(i);
    socketStat[i] = s;
    Serial.print(F(":0x"));
    Serial.print(s,16);
    Serial.print(F(" "));
    Serial.print(W5100.readSnPORT(i));
    Serial.print(F(" D:"));
    uint8_t dip[4];
    W5100.readSnDIPR(i, dip);
    for (int j=0; j<4; j++) {
      Serial.print(dip[j],10);
      if (j<3) Serial.print(".");
    }
    Serial.print(F("("));
    Serial.print(W5100.readSnDPORT(i));
    Serial.println(F(")"));
  }
}

edit: My bad. It should have been utility/w5100.h or utility/w5500.h, not util

mmmhh it took the messages out. Everytime i want to call the arduino in my browser i get a timeout.

Did you switch to the W5500-compatible library? Looks like you would have to change the #include to use the new library instead of Ethernet.h.

johnwasser:
Looks like you would have to change the #include to use the new library instead of Ethernet.h.

ACK!

JHis code includes support for the Arduino Ethernet Shield with a Wiznet W5100 Ethernet chip only!
Arduinos default "Ethernet.h" library, included in IDE distribution files, supports Wiznet W5100 Ethernet shields only,

If he prefers different Ethernet chips, he needs to use different third-party library instead.

The Wiznet library I posted a link to above uses Ethernet.h. It is set to use the w5500 IC as the default, but can be changed to use the w100 or w5200. I'm using it now on my w5100.

but it doessnt help. The question is what could have happened that it worked yesterday. I pulled of the power supply. When i wanted to test it again today, i turned it on and all leds where on like yesterday, but i cannot reach the server. A ping to the ip adress works just fine, but the my browser doesnt loade the site :confused: