ethernet pings but webclient is not responding

I'm developing a software with Delphi that get's a web page from one of my arduinos.

This one, is geting values from 3 sensors (DHT, SR04 and TSAL 251) and then it will show results with webserver as solicited.

The problem I'm experience is that after several correct readings from arduino it stops responding to the webclient but it still respond to a normal Ping in Dos window... (I used as web client my Delphi App or Any Browser with same result).

I imagine that it could be my arduino software that hangs but it after the "solution" I have found I don't think so....

I have made a batch file that ping's once my arduino every 10/12 seconds and: "problem solved!". From this point I never get errors geting my pages in my app or web with any browser. I can even ping from any computer in my network to "solve" the problem.

It seems that we need to keep arduino UP every 10/12 seconds or it goes DOWN... is it possíble?

I need to find a solution because it is not a good option to ping every 10/12 seconds all my arduinos :)


José Mendinhos


Ah - its that fault in line 254 again, just replace the $ with a ’ . . . . Oh wait ‘THERE IS NO CODE’ !!!

OPPSSS. You’re correct.

Here is the code.

José Mendinhos

Web_server (8.85 KB)

Is this the last thing displayed on the serial monitor when it stops responding?

Pedido de HTML / Consulta

Networking would have been a better place to post this thread.

Yes. That's the last signal I get...

OK, try these additions to your code. Also you might want to use the F() function to reduce your SRAM requirement. I added the F() function to the first few serial and client prints as examples, but I recommend using that on all your static strings.

void listenForEthernetClients() 
  // listen for incoming clients
  EthernetClient client = server.available();
  if (client) 
    Serial.println(F("Pedido de HTML / Consulta"));    
    // an http request ends with a blank line
    boolean currentLineIsBlank = true;
    while (client.connected()) 
      if (client.available()) 
        char c =;
        // if you've gotten to the end of the line (received a newline character) and the line 
        // is blank, the http request has ended, so you can send a reply
        if (c == '\n' && currentLineIsBlank) {
            // Envio da resposta           

// Add this. If you don't see this, then you are not getting a blank line from the client
              Serial.println(F("Sending response"));

              client.println(F("HTTP/1.1 200 OK"));
              client.println(F("Content-Type: text/html"));
              // meta tag -> Faz refresh ao browser de 20 em 20 segundos
              // client.println(F("<meta http-equiv=\"refresh\" content=\"120\">"));
              // print the current readings, in HTML format:
              client.print("<table align=center width=100%><tr><td>Identificacao do sistema </td><td>Brimarel-001</td><td>");
              client.print( "  Ciclo : </td><td>" );
              client.print( String(ciclo) );
              client.print("<table border=1 align=center width=100%><tr><td>Temperatura(TE)</td><td>Humidade(HU)");
              client.print("</td><td>Nivel do Tanque(NT)</td></tr><tr><td><div id='TE'>");                    
              client.print( String(Temperatura));
              client.print("</div></td><td><div id='HU'>");
              client.print( String(Humidade) );
              client.print("</div></td><td><div id='LU'>");
              client.print("</div></td><td><div id='NT'>");
              // Informação de controlo              
              client.print(" Distancia : ");
              client.print(" - Pin ");
              client.print(" ligado a : ");
              client.print(" Stibs");
              // Informação de Controlo              
         // Fim da resposta
        if (c == '\n') {
          // you're starting a new line
          currentLineIsBlank = true;
        else if (c != '\r') {
          // you've gotten a character on the current line
          currentLineIsBlank = false;
    // give the web browser time to receive the data
    // close the connection:

// Add this. If you don't see this, then you are not finishing the response send to the client

Then run the sketch again and post the last message on the serial monitor when the server quits responding.

Today I manage to solve this problem finnally...

With your help and hours looking to the terminal I notice that some times my blank line was not been captured by the arduino... and then it was waiting for a blank line.

The problem was in my client app, but it was not a ligical error becaus I was (am) sending a blank line in the end of the request. The problem seems to be in the quality of my real connection (not my test connection).

I simply added a very small pause and then I send a blank line in the end of my resquest that is been developed in Delphi that now is like this: .... form1.idTcpClient1.Port := 80 ; form1.idTcpClient1.Host := '' ; form1.idTCPClient1.Connected then form1.idTCPClient1.Connect; form1.idTcpClient1.writeln('GET / HTTP/1.1'); form1.idTcpClient1.writeln('Host:' ); form1.idTcpClient1.writeln( '' ); // This line was already here before // 2 lines added sleep( 5 ); // wait a little form1.idTcpClient1.writeln( '' ); //Send a second blank line ....

Thank's for your help Best regard's José Mendinhos

If your server is exposed to the internet, you may be the target of malevolent clients. I can crash most server code examples with PuTTY, except for zoomkat's and my server code. I can crash zoomkat's server code with my Arduino client code, but I can't crash my server code.

Here is my server code with a timeout in the event it receives no cr/lf at all. The variable loopCount controls the timeout.