Problem with Ethernet shield

Don't print "poczatek petli" for every single character that is received.

Code:

    //ARDUINO 1.0+ ONLY
    //ARDUINO 1.0+ ONLY
    #include <Ethernet.h>
    #include <SPI.h>

    ////////////////////////////////////////////////////////////////////////
    //CONFIGURE
    ////////////////////////////////////////////////////////////////////////
    byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
    byte ip[] = { 192, 168, 0, 110 };
    byte dnss[] = { 8, 8, 8, 8 };

    EthernetClient client;
    char outputred[32];
    char clienterr[] = "error";
    char msgConnectionFailed[] = "connectfailed";
    char server[] = "kaska3er.ugu.pl";
    //The location to go to on the server
    //make sure to keep HTTP/1.0 at the end, this is telling it what type of file it is
    char location[] = "/siema.txt HTTP/1.0";



    char inString[32]; // string for incoming serial data
    int stringPos = 0; // string index counter
    boolean startRead = false; // is reading?

    void setup(){
      Ethernet.begin(mac, ip, dnss);
      Serial.begin(9600);
      pinMode(6, OUTPUT);
    }

    void loop(){
      char *pageValue = connectAndRead(); //connect to the server and read the output
      Serial.println(pageValue); //print out the findings.
      if(strcmp(pageValue, "wlacz") == 0)
      {
        digitalWrite(6, HIGH);
      }
      else if(strcmp(pageValue, "wylacz") == 0)
      {
        digitalWrite(6, LOW);
      }
      delay(5000); //wait 5 seconds before connecting again
    }

    char *connectAndRead(){
      //connect to the server

      Serial.println("connecting...");

      //port 80 is typical of a www page
      if (client.connect(server, 80)) {
        Serial.println("connected");
        client.println("GET http://kaska3er.ugu.pl/siema.txt HTTP/1.0");
        client.println("Host: kaska3er.ugu.pl");
        client.println();

        //Connected - Read the page
          return readPage(); //go and read the output


      }else{
           return (msgConnectionFailed);
      }

    }

    char *readPage()
    {
        //read the page, and capture & return everything between '<' and '>'
        stringPos = 0;
        memset(inString, 0, 32 ); //clear inString memory
        while(true)
        {
          if (client.available()) 
          {
            char c = client.read();
            if (c == '<' ) 
            { //'<' is our begining character
              startRead = true; //Ready to start reading the part
            }
            else if(startRead)
            {
              if(c != '>')
              { //'>' is our ending character
                inString[stringPos] = c;
                stringPos ++;
              }
              else
              {
                //got what we need here! We can disconnect now
                startRead = false;
                client.flush();
                client.stop();
                Serial.println("disconnecting.");
                return inString;
              }
            }
          }
          else
          {
            return (clienterr);
          }
  
        }

    }

Serial monitor:

connecting...
connectfailed
connecting...
connected
error
connecting...
connectfailed
connecting...
connectfailed
connecting...
connectfailed
connecting...
connectfailed
connecting...
connectfailed
connecting...
connectfailed
connecting...
connectfailed
connecting...
connectfailed
connecting...
connected
disconnecting.
wlacz
connecting...
connected
error
connecting...
connectfailed

Website works normally
Anybody can test in in his arduino?

Success!

connecting...
connected

available=234

HTTP/1.1 200 OK
Date: Sun, 21 Sep 2014 18:08:08 GMT
Server: Apache
Last-Modified: Sun, 21 Sep 2014 16:11:23 GMT
Accept-Ranges: bytes
Vary: Accept-Encoding
Content-Length: 7
Connection: close
Content-Type: text/plain

disconnecting. wlacz

I used my normal Arduino setup, in linux with Arduino IDE 1.5.7, with Arduino Mega 2560 and Ethernet Shield. I have changed many things, before I got it.
It turns out that connecting to the website was no problem, but the file 'siema.txt' was not available. After I added an delay of 50ms the file was available !

Add "delay(50);" before the "while(true)"

The 'GET' should only request the file, not the whole url.
Change the request for the file into this:

    client.println("GET /siema.txt HTTP/1.0");
    client.println("Host: kaska3er.ugu.pl");
    client.println();

Remove the "client.flush()". I think it is not needed, but I'm not sure about this.

The client has to be stopped, when the file was not available. So I added it.

    else
    {
      client.stop();
      return (clienterr);
    }

THank you for your spent time but it isn't working.
Serial monitor:

connected
error
connecting...
connected
error
connecting...
connected
error
connecting...
connected
error
connecting...
connected
error
connecting...
connected
error
connecting...
connected
error

Code:

    //ARDUINO 1.0+ ONLY
    //ARDUINO 1.0+ ONLY
    #include <Ethernet.h>
    #include <SPI.h>

    ////////////////////////////////////////////////////////////////////////
    //CONFIGURE
    ////////////////////////////////////////////////////////////////////////
    byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
    byte ip[] = { 192, 168, 0, 110 };
    byte dnss[] = { 8, 8, 8, 8 };

    EthernetClient client;
    char outputred[32];
    char clienterr[] = "error";
    char msgConnectionFailed[] = "connectfailed";
    char server[] = "kaska3er.ugu.pl";
    //The location to go to on the server
    //make sure to keep HTTP/1.0 at the end, this is telling it what type of file it is
    char location[] = "/siema.txt HTTP/1.0";



    char inString[32]; // string for incoming serial data
    int stringPos = 0; // string index counter
    boolean startRead = false; // is reading?

    void setup(){
      Ethernet.begin(mac, ip, dnss);
      Serial.begin(9600);
      pinMode(6, OUTPUT);
    }

    void loop(){
      char *pageValue = connectAndRead(); //connect to the server and read the output
      Serial.println(pageValue); //print out the findings.
      if(strcmp(pageValue, "wlacz") == 0)
      {
        digitalWrite(6, HIGH);
      }
      else if(strcmp(pageValue, "wylacz") == 0)
      {
        digitalWrite(6, LOW);
      }
      delay(5000); //wait 5 seconds before connecting again
    }

    char *connectAndRead(){
      //connect to the server

      Serial.println("connecting...");

      //port 80 is typical of a www page
      if (client.connect(server, 80)) {
        Serial.println("connected");
        client.println("GET /siema.txt HTTP/1.0");
        client.println("Host: kaska3er.ugu.pl");
        client.println();

        //Connected - Read the page
          return readPage(); //go and read the output


      }else{
           return (msgConnectionFailed);
      }

    }

    char *readPage()
    {
        //read the page, and capture & return everything between '<' and '>'
        stringPos = 0;
        memset(inString, 0, 32 ); //clear inString memory
        delay(50);
        while(true)
        {
          if (client.available()) 
          {
            char c = client.read();
            if (c == '<' ) 
            { //'<' is our begining character
              startRead = true; //Ready to start reading the part
            }
            else if(startRead)
            {
              if(c != '>')
              { //'>' is our ending character
                inString[stringPos] = c;
                stringPos ++;
              }
              else
              {
                //got what we need here! We can disconnect now
                startRead = false;
                client.stop();
                Serial.println("disconnecting.");
                return inString;
              }
            }
          }
          else
          {
            client.stop();
            return (clienterr);
          }
  
        }

    }

I have to check that later, I'm on another computer now.
Can you try a delay of 200 perhaps ?

Yea it work but I leave it powered for a night and i check this morning is it working

That means I can't keep the same sketch running ... :roll_eyes: I don't want to put more stress on the server.

Yea it works I tested it this morning and it works.
Thank you Peter_n
I must buy heatsink for w5100 because it's hot after night.

I'm glad it is working now. I think there was a memory issue when you had the String mixed with char array.
The W5100 is getting hot, sometimes too hot to keep your finger on it. It seems to be normal :roll_eyes: