2
votes

I have the same problem as in Stack Overflow question Arduino (Uno) Ethernet client connection fails after many client prints.

The solution for this problem is using library Ethernet2. I downloaded this library and put folder "Ethernet2" in folder "libraries". Arduino 1.0.1 produces errors when I try to use it in the sketch.

Sketch:

/*
 * Echo Server
 *
 * Echoes back the headers of the web request.  Good for
 * learning how the HTTP protocol works.
 */

#include <Ethernet2.h>

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 10, 0, 0, 177 };

Server server(80);

void setup()
{
    Client client(255);
    Ethernet.begin(mac, ip);
    Serial.begin(9600);
    server.begin();
}

void loop()
{
    char buf[512];
    int i = 0;
    Client client = server.available();
    if (client) {
        boolean previous_is_newline = false;
        while (client.connected()) {
            if (client.available()) {
                char c = client.read();
                if (c == '\n' && previous_is_newline) {
                    buf[i] = 0;
                    client.println("HTTP/1.1 200 OK");
                    client.println("Content-Type: text/html");
                    client.println();
                    client.println("<pre>");
                    client.println(buf);
                    client.println("</pre>");
                    break;
                }
                if (i < 511)
                    buf[i++] = c;
                if (c == '\n')
                    previous_is_newline = true;
                else if (c != '\r')
                    previous_is_newline = false;
            }
        }
        client.stop();
    }
}

Error:

In file included from C:\Documents and Settings\Admin\Рабочий стол\!!! Arduino\arduino-1.0.1\hardware\arduino\cores\arduino/Arduino.h:193,
                 from Test_Ethernet2_echo.cpp:10:
C:\Documents and Settings\Admin\Рабочий стол\!!! Arduino\arduino-1.0.1\hardware\arduino\cores\arduino/HardwareSerial.h:58: error: conflicting return type specified for 'virtual size_t HardwareSerial::write(uint8_t)'
C:\Documents and Settings\Admin\Рабочий стол\!!! Arduino\arduino-1.0.1\libraries\Ethernet2/Print.h:36: error:   overriding 'virtual void Print::write(uint8_t)'

How can I fix this problem?

1
Try reinstalling the library. It seems like there are two files... did you download both and install it correctly? Also, try updating to a newer version of the IDE.Anonymous Penguin

1 Answers

0
votes

Since Arduino IDE 1.5 you can use the library manager to install libs -This problem should not occure any more