2

我遇到了与 Stack Overflow 问题Arduino (Uno) Ethernet client connection failed after many client prints中相同的问题。

这个问题的解决方案是使用库Ethernet2。我下载了这个库并将文件夹“Ethernet2”放在文件夹“libraries”中。当我尝试在草图中使用 Arduino 1.0.1 时,它会产生错误。

草图:

/*
 * 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();
    }
}

错误:

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)'

我该如何解决这个问题?

4

1 回答 1

0

从 Arduino IDE 1.5 开始,您可以使用库管​​理器来安装库 - 这个问题应该不会再发生了

于 2020-03-22T10:45:28.127 回答