I try to use this library and example code to run on my ESP32 ArduinoOTA/examples/OTEthernet/OTEthernet.ino at master · JAndrassy/ArduinoOTA · GitHub
anyone here have some experience with ESP32 Ethernet OTA
I have
Hello @duong_007
take a look at this thread.
It handles updating the sketch through EThernet using W5500 and ESP32.
It doesn't work on my esp32 do I have to add other library other then ArduinoOTA.h?
can u share you code ?
Hello @duong_007
please don't take an image of the error.
try to copy and paste your error message complete here so we can read it and help.
Here is my code:
#include <WiFi.h>
#include <WebServer.h>
//#include <ArduinoOTA.h> //if you want update over WiFi
#include <Update.h>
#include <StreamString.h>
#include <SPI.h>
#include <EthernetWebServer.h>
#include "Ethernet_Generic.h"
#define A0 0
#define W5500_CS 10
#define SPI_FRQ 32000000 // better than the 1 or 4MHz default
const char* ssid = "use yours";
const char* password = "use yours";
const char* update_path = "/firmware";
String IP_ADDRESS;
static const char pageheader[] PROGMEM = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">";
static const char htmlhead[] PROGMEM = "<html><head><title>HttpUpdater</title><meta http-equiv=\"Content-Type\" content=\"text/html;charset=utf-8\" ></head>";
static const char bodystyle[] PROGMEM = "<body style=\"color: dimgray; background-color: palegoldenrod; font-size: 12pt; font-family: sans-serif;\">";
static const char htmlclose[] PROGMEM = "</body></html>";
byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED}; //byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x01};
IPAddress ip(x, x, x, x); // Use yours
uint8_t ipByte[4];
EthernetWebServer ethernetServer(80);
WebServer wifiServer(80);
void handleEthernetRoot() {
//ethernetServer.send(200, "text/plain", "Hello from ESP32 Ethernet!");
ethernetServer.send(200, "text/plain", "Hello from ESP32 Ethernet!, The upload worked !!");
}
void handleWiFiRoot() {
wifiServer.send(200, "text/plain", "Hello from ESP32 WiFi!");
}
void setup() {
//Initialize serial and wait for port to open:
Serial.begin(115200);
while (!Serial && millis() < 5000);
delay(100);
//OTAUpdateSetup();
ipByte[0] = ip[0];
ipByte[1] = ip[1];
ipByte[2] = ip[2];
ipByte[3] = ip[3];
SPI.setFrequency(SPI_FRQ);
Ethernet.init (W5500_CS);
// start the ethernet connection and the server:
//Ethernet.begin(mac); //For DHCP
Ethernet.begin(mac, ip);
if (Ethernet.hardwareStatus() == EthernetNoHardware)
{
Serial.println("No Ethernet found. Stay here forever");
while (true)
{
delay(1); // do nothing, no point running without Ethernet hardware
}
}
Serial.print("Ethernet Chip ID: ");
if(Ethernet.hardwareStatus() == EthernetW5500){
Serial.println("W5500");
}
if (Ethernet.linkStatus() == 2)
{
Serial.println("Not connected Ethernet cable");
}
Serial.println("Currently Used SPI pinout:");
Serial.print("MOSI: ");
Serial.print(MOSI);
Serial.print(", MISO: ");
Serial.print(MISO);
Serial.print(", SCK: ");
Serial.print(SCK);
Serial.print(", CS/SS: ");
Serial.println(W5500_CS);
Serial.print(F("Speed: "));
Serial.print(Ethernet.speedReport());
Serial.print(F(", Duplex: "));
Serial.print(Ethernet.duplexReport());
Serial.print(F(", Link status: "));
Serial.println(Ethernet.linkReport());
//ethernetServer.on("/", handleEthernetRoot);
// ethernetServer.on(update_path, HTTP_GET, handleUpdate);
// ethernetServer.on(update_path, HTTP_POST, handlePostUpdate, handleFileUpload);
ethernetServer.on("/", HTTP_GET, handleUpdate);
ethernetServer.on("/", HTTP_POST, handlePostUpdate, handleFileUpload);
ethernetServer.begin();;
IP_ADDRESS = Ethernet.localIP().toString();
Serial.print("HTTP EthernetWebServer is @ IP : ");
Serial.println("IP_ADDRESS");
void loop() {
//ArduinoOTA.handle();
ethernetServer.handleClient();
}
//----------------------------------------- Firmware Update Pages -----------------------------------------------------
void handleUpdate() {
if (!ethernetServer.authenticate("admin", "password"))
return ethernetServer.requestAuthentication();
String s = "";
s += FPSTR(pageheader);
s += FPSTR(htmlhead);
s += FPSTR(bodystyle);
s += "<h1>OTEthernet Firmware Update</h1>";
s += "<pre><form method='post' action='' enctype='multipart/form-data'>";
s += "<input type='file' name='update'>";
s += " <input type='submit' value=' Update '>";
s += " <a href='/analog'> Read RGBC color sensor </a><br>";
s += " <input type='reset'></form></pre>";
// s += " <input type='submit' value=' Update '></form></pre>";
// s += "<a href='/analog'>Read RGBC color sensor</a><br>";
s += FPSTR(htmlclose);
ethernetServer.send(200, "text/html", s);
}
void handlePostUpdate() {
if (!ethernetServer.authenticate("admin", "password"))
return ethernetServer.requestAuthentication();
if (Update.hasError()) {
StreamString str;
Update.printError(str);
str;
String s = "";
s += FPSTR(pageheader);
s += FPSTR(htmlhead);
s += FPSTR(bodystyle);
s += "<h1>Update Error </h1>";
s += str;
s += FPSTR(htmlclose);
ethernetServer.send(200, "text / html", s);
Serial.prinln("Failure updating!!");
}
else {
String s = "";
s += FPSTR(pageheader);
s += FPSTR(htmlhead);
s += FPSTR(bodystyle);
s += "<META http-equiv='refresh' content='5;URL=/'>Update Success ! Rebooting...\n"; //content= '30;
s += (htmlclose);
//ethernetServer.client().setNoDelay(true);
ethernetServer.send(200, "text / html", s);
ethernetServer.client().stop();
ESP.restart();
}
}
void handleFileUpload() {
if (!ethernetServer.authenticate("admin", "password"))
return ethernetServer.requestAuthentication();
ethernetHTTPUpload& upload = ethernetServer.upload();
String updateerror = "";
if (upload.status == UPLOAD_FILE_START) {
//EthernetUDP::stop();
uint32_t maxSketchSpace = (ESP.getFreeSketchSpace() - 0x1000) & 0xFFFFF000;
if (!Update.begin(maxSketchSpace)) { //start with max available size
StreamString str;
Update.printError(str);
updateerror = str;
}
}
else if (upload.status == UPLOAD_FILE_WRITE) {
if (Update.write(upload.buf, upload.currentSize) != upload.currentSize) {
StreamString str;
Update.printError(str);
updateerror = str;
}
}
else if (upload.status == UPLOAD_FILE_END) {
if (Update.end(true)) { //true to set the size to the current progress
StreamString str;
Update.printError(str);
updateerror = str;
}
}
else if (upload.status == UPLOAD_FILE_ABORTED) {
Update.end();
}
yield();
}
}
//-------------------------------------------- OTA Uploader Functions ---------------------------------------
/*void OTAUpdateSetup() {
ArduinoOTA.setHostname("update");
ArduinoOTA.setPassword("yes");
ArduinoOTA.onStart([]() {
String type;
if (ArduinoOTA.getCommand() == U_FLASH) {
}
else { // U_SPIFFS
type = "filesystem";
//if (spiffsmounted) {
//SPIFFS.end();
//spiffsmounted = false;
//}
}
// NOTE: if updating SPIFFS this would be the place to unmount SPIFFS using SPIFFS.end()
// Serial.println("Start updating " + type);
});
ArduinoOTA.onEnd([]() {
//if (!spiffsmounted) spiffsmounted = SPIFFS.begin();
delay(1000);
// Serial.println("\nEnd");
});
ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) {
// Serial.printf("Progress: % u % % \r", (progress / (total / 100)));
});
ArduinoOTA.onError([](ota_error_t error) {
//Serial.printf("Error[ % u]: ", error);
if (error == OTA_AUTH_ERROR) {
// Serial.println("Auth Failed");
}
else if (error == OTA_BEGIN_ERROR) {
//Serial.println("Begin Failed");
}
else if (error == OTA_CONNECT_ERROR) {
//Serial.println("Connect Failed");
}
else if (error == OTA_RECEIVE_ERROR) {
//Serial.println("Receive Failed");
} else if (error == OTA_END_ERROR) {
//Serial.println("End Failed");
}
});
ArduinoOTA.begin();
}*/
#include <WiFi.h>
#include <WebServer.h>
//#include <ArduinoOTA.h> //if you want update over WiFi
#include <Update.h>
#include <StreamString.h>
#include <SPI.h>
#include <EthernetWebServer.h>
#include "Ethernet_Generic.h"
#define A0 0
#define W5500_CS 10
#define SPI_FRQ 32000000 // better than the 1 or 4MHz default
const char* ssid = "use yours";
const char* password = "use yours";
const char* update_path = "/firmware";
String IP_ADDRESS;
static const char pageheader[] PROGMEM = "";
static const char htmlhead[] PROGMEM = "HttpUpdater<meta http-equiv="Content-Type" content="text/html;charset=utf-8" >";
static const char bodystyle[] PROGMEM = "<body style="color: dimgray; background-color: palegoldenrod; font-size: 12pt; font-family: sans-serif;">";
static const char htmlclose[] PROGMEM = "";
byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED}; //byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x01};
IPAddress ip(192, 168, 0, 1); // Use yours
uint8_t ipByte[4];
EthernetWebServer ethernetServer(80);
WebServer wifiServer(80);
void handleEthernetRoot() {
//ethernetServer.send(200, "text/plain", "Hello from ESP32 Ethernet!");
ethernetServer.send(200, "text/plain", "Hello from ESP32 Ethernet!, The upload worked !!");
}
void handleWiFiRoot() {
wifiServer.send(200, "text/plain", "Hello from ESP32 WiFi!");
}
void setup() {
//Initialize serial and wait for port to open:
Serial.begin(115200);
while (!Serial && millis() < 5000);
delay(100);
//OTAUpdateSetup();
ipByte[0] = ip[0];
ipByte[1] = ip[1];
ipByte[2] = ip[2];
ipByte[3] = ip[3];
SPI.setFrequency(SPI_FRQ);
Ethernet.init (W5500_CS);
// start the ethernet connection and the server:
//Ethernet.begin(mac); //For DHCP
Ethernet.begin(mac, ip);
if (Ethernet.hardwareStatus() == EthernetNoHardware)
{
Serial.println("No Ethernet found. Stay here forever");
while (true)
{
delay(1); // do nothing, no point running without Ethernet hardware
}
}
Serial.print("Ethernet Chip ID: ");
if(Ethernet.hardwareStatus() == EthernetW5500){
Serial.println("W5500");
}
if (Ethernet.linkStatus() == 2)
{
Serial.println("Not connected Ethernet cable");
}
Serial.println("Currently Used SPI pinout:");
Serial.print("MOSI: ");
Serial.print(MOSI);
Serial.print(", MISO: ");
Serial.print(MISO);
Serial.print(", SCK: ");
Serial.print(SCK);
Serial.print(", CS/SS: ");
Serial.println(W5500_CS);
Serial.print(F("Speed: "));
Serial.print(Ethernet.speedReport());
Serial.print(F(", Duplex: "));
Serial.print(Ethernet.duplexReport());
Serial.print(F(", Link status: "));
Serial.println(Ethernet.linkReport());
//ethernetServer.on("/", handleEthernetRoot);
// ethernetServer.on(update_path, HTTP_GET, handleUpdate);
// ethernetServer.on(update_path, HTTP_POST, handlePostUpdate, handleFileUpload);
ethernetServer.on("/", HTTP_GET, handleUpdate);
ethernetServer.on("/", HTTP_POST, handlePostUpdate, handleFileUpload);
ethernetServer.begin();;
IP_ADDRESS = Ethernet.localIP().toString();
Serial.print("HTTP EthernetWebServer is @ IP : ");
Serial.println("IP_ADDRESS");
}
void loop() {
//ArduinoOTA.handle();
ethernetServer.handleClient();
}
//----------------------------------------- Firmware Update Pages -----------------------------------------------------
void handleUpdate() {
if (!ethernetServer.authenticate("admin", "password"))
return ethernetServer.requestAuthentication();
String s = "";
s += FPSTR(pageheader);
s += FPSTR(htmlhead);
s += FPSTR(bodystyle);
s += "
OTEthernet Firmware Update
";s += "
";";
s += "";
s += " ";
s += " Read RGBC color sensor
";
s += "
// s += " ";
// s += "Read RGBC color sensor
";
s += FPSTR(htmlclose);
ethernetServer.send(200, "text/html", s);
}
void handlePostUpdate() {
if (!ethernetServer.authenticate("admin", "password"))
return ethernetServer.requestAuthentication();
if (Update.hasError()) {
StreamString str;
Update.printError(str);
str;
String s = "";
s += FPSTR(pageheader);
s += FPSTR(htmlhead);
s += FPSTR(bodystyle);
s += "
Update Error
";s += str;
s += FPSTR(htmlclose);
ethernetServer.send(200, "text / html", s);
Serial.println("Failure updating!!");
}
else {
String s = "";
s += FPSTR(pageheader);
s += FPSTR(htmlhead);
s += FPSTR(bodystyle);
s += "Update Success ! Rebooting...\n"; //content= '30;
s += (htmlclose);
//ethernetServer.client().setNoDelay(true);
ethernetServer.send(200, "text / html", s);
ethernetServer.client().stop();
ESP.restart();
}
}
void handleFileUpload() {
if (!ethernetServer.authenticate("admin", "password"))
return ethernetServer.requestAuthentication();
ethernetHTTPUpload& upload = ethernetServer.upload();
String updateerror = "";
if (upload.status == UPLOAD_FILE_START) {
//EthernetUDP::stop();
uint32_t maxSketchSpace = (ESP.getFreeSketchSpace() - 0x1000) & 0xFFFFF000;
if (!Update.begin(maxSketchSpace)) { //start with max available size
StreamString str;
Update.printError(str);
updateerror = str;
}
}
else if (upload.status == UPLOAD_FILE_WRITE) {
if (Update.write(upload.buf, upload.currentSize) != upload.currentSize) {
StreamString str;
Update.printError(str);
updateerror = str;
}
}
else if (upload.status == UPLOAD_FILE_END) {
if (Update.end(true)) { //true to set the size to the current progress
StreamString str;
Update.printError(str);
updateerror = str;
}
}
else if (upload.status == UPLOAD_FILE_ABORTED) {
Update.end();
}
yield();
}
//-------------------------------------------- OTA Uploader Functions ---------------------------------------
/*void OTAUpdateSetup() {
ArduinoOTA.setHostname("update");
ArduinoOTA.setPassword("yes");
ArduinoOTA.onStart( {
String type;
if (ArduinoOTA.getCommand() == U_FLASH) {
}
else { // U_SPIFFS
type = "filesystem";
//if (spiffsmounted) {
//SPIFFS.end();
//spiffsmounted = false;
//}
}
// NOTE: if updating SPIFFS this would be the place to unmount SPIFFS using SPIFFS.end()
// Serial.println("Start updating " + type);
});
ArduinoOTA.onEnd( {
//if (!spiffsmounted) spiffsmounted = SPIFFS.begin();
delay(1000);
// Serial.println("\nEnd");
});
ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) {
// Serial.printf("Progress: % u % % \r", (progress / (total / 100)));
});
ArduinoOTA.onError([](ota_error_t error) {
//Serial.printf("Error[ % u]: ", error);
if (error == OTA_AUTH_ERROR) {
// Serial.println("Auth Failed");
}
else if (error == OTA_BEGIN_ERROR) {
//Serial.println("Begin Failed");
}
else if (error == OTA_CONNECT_ERROR) {
//Serial.println("Connect Failed");
}
else if (error == OTA_RECEIVE_ERROR) {
//Serial.println("Receive Failed");
} else if (error == OTA_END_ERROR) {
//Serial.println("End Failed");
}
});
ArduinoOTA.begin();
}*/
error///
In file included from c:\Users\God Slayer\Documents\Arduino\libraries\EthernetWebServer\src/EthernetWebServer.h:67,
from C:\Users\God Slayer\AppData\Local\Temp.arduinoIDE-unsaved2024312-18932-13py7dh.076h\sketch_apr12a\sketch_apr12a.ino:7:
c:\Users\God Slayer\Documents\Arduino\libraries\EthernetWebServer\src/EthernetWebServer.hpp:576:22: error: cannot declare field 'EthernetWebServer::_server' to be of abstract type 'EthernetServer'
EthernetServer _server;
^~~~~~~
In file included from c:\Users\God Slayer\Documents\Arduino\libraries\Ethernet_Generic\src/Ethernet_Generic.h:84,
from c:\Users\God Slayer\Documents\Arduino\libraries\EthernetWebServer\src/EthernetWebServer.h:58,
from C:\Users\God Slayer\AppData\Local\Temp.arduinoIDE-unsaved2024312-18932-13py7dh.076h\sketch_apr12a\sketch_apr12a.ino:7:
c:\Users\God Slayer\Documents\Arduino\libraries\Ethernet_Generic\src/Ethernet_Generic.hpp:532:7: note: because the following virtual functions are pure within 'EthernetServer':
class EthernetServer : public Server
^~~~~~~~~~~~~~
In file included from C:\Users\God Slayer\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.14\cores\esp32/Arduino.h:182,
from C:\Users\God Slayer\AppData\Local\Temp\arduino\sketches\28B9761F5BCBB2402AFA2905B00D6E51\sketch\sketch_apr12a.ino.cpp:1:
C:\Users\God Slayer\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.14\cores\esp32/Server.h:28:18: note: 'virtual void Server::begin(uint16_t)'
virtual void begin(uint16_t port=0) =0;
^~~~~
exit status 1
Compilation error: exit status 1
error///
In file included from c:\Users\God Slayer\Documents\Arduino\libraries\EthernetWebServer\src/EthernetWebServer.h:67,
from C:\Users\God Slayer\AppData\Local\Temp.arduinoIDE-unsaved2024312-18932-13py7dh.076h\sketch_apr12a\sketch_apr12a.ino:7:
c:\Users\God Slayer\Documents\Arduino\libraries\EthernetWebServer\src/EthernetWebServer.hpp:576:22: error: cannot declare field 'EthernetWebServer::_server' to be of abstract type 'EthernetServer'
EthernetServer _server;
^~~~~~~
In file included from c:\Users\God Slayer\Documents\Arduino\libraries\Ethernet_Generic\src/Ethernet_Generic.h:84,
from c:\Users\God Slayer\Documents\Arduino\libraries\EthernetWebServer\src/EthernetWebServer.h:58,
from C:\Users\God Slayer\AppData\Local\Temp.arduinoIDE-unsaved2024312-18932-13py7dh.076h\sketch_apr12a\sketch_apr12a.ino:7:
c:\Users\God Slayer\Documents\Arduino\libraries\Ethernet_Generic\src/Ethernet_Generic.hpp:532:7: note: because the following virtual functions are pure within 'EthernetServer':
class EthernetServer : public Server
^~~~~~~~~~~~~~
In file included from C:\Users\God Slayer\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.14\cores\esp32/Arduino.h:182,
from C:\Users\God Slayer\AppData\Local\Temp\arduino\sketches\28B9761F5BCBB2402AFA2905B00D6E51\sketch\sketch_apr12a.ino.cpp:1:
C:\Users\God Slayer\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.14\cores\esp32/Server.h:28:18: note: 'virtual void Server::begin(uint16_t)'
virtual void begin(uint16_t port=0) =0;
^~~~~
exit status 1
Compilation error: exit status 1
Have you installed all the libraries being used here?
And please when posting code or error messages, use the icon for code in menu bar.
in Ethernet library in Ethernet.h remove public Server
from class EthernetServer
declaration
In file included from c:\Users\God Slayer\Documents\Arduino\libraries\Ethernet_Generic\src/Ethernet_Generic_Impl.h:64,
from c:\Users\God Slayer\Documents\Arduino\libraries\Ethernet_Generic\src/Ethernet_Generic.h:85,
from c:\Users\God Slayer\Documents\Arduino\libraries\EthernetWebServer\src/EthernetWebServer.h:58,
from C:\Users\God Slayer\AppData\Local\Temp.arduinoIDE-unsaved2024312-18932-1qrw30p.7an7\sketch_apr12c\sketch_apr12c.ino:7:
c:\Users\God Slayer\Documents\Arduino\libraries\Ethernet_Generic\src/EthernetServer_Impl.h:60:50: error: invalid use of incomplete type 'class EthernetServer'
uint16_t EthernetServer::server_port[MAX_SOCK_NUM];
^
In file included from c:\Users\God Slayer\Documents\Arduino\libraries\Ethernet_Generic\src/Ethernet_Generic.h:84,
from c:\Users\God Slayer\Documents\Arduino\libraries\EthernetWebServer\src/EthernetWebServer.h:58,
from C:\Users\God Slayer\AppData\Local\Temp.arduinoIDE-unsaved2024312-18932-1qrw30p.7an7\sketch_apr12c\sketch_apr12c.ino:7:
c:\Users\God Slayer\Documents\Arduino\libraries\Ethernet_Generic\src/Ethernet_Generic.hpp:185:7: note: forward declaration of 'class EthernetServer'
class EthernetServer;
^~~~~~~~~~~~~~
In file included from c:\Users\God Slayer\Documents\Arduino\libraries\Ethernet_Generic\src/Ethernet_Generic_Impl.h:64,
from c:\Users\God Slayer\Documents\Arduino\libraries\Ethernet_Generic\src/Ethernet_Generic.h:85,
from c:\Users\God Slayer\Documents\Arduino\libraries\EthernetWebServer\src/EthernetWebServer.h:58,
from C:\Users\God Slayer\AppData\Local\Temp.arduinoIDE-unsaved2024312-18932-1qrw30p.7an7\sketch_apr12c\sketch_apr12c.ino:7:
c:\Users\God Slayer\Documents\Arduino\libraries\Ethernet_Generic\src/EthernetServer_Impl.h:64:28: error: invalid use of incomplete type 'class EthernetServer'
void EthernetServer::begin()
^
In file included from c:\Users\God Slayer\Documents\Arduino\libraries\Ethernet_Generic\src/Ethernet_Generic.h:84,
from c:\Users\God Slayer\Documents\Arduino\libraries\EthernetWebServer\src/EthernetWebServer.h:58,
from C:\Users\God Slayer\AppData\Local\Temp.arduinoIDE-unsaved2024312-18932-1qrw30p.7an7\sketch_apr12c\sketch_apr12c.ino:7:
c:\Users\God Slayer\Documents\Arduino\libraries\Ethernet_Generic\src/Ethernet_Generic.hpp:185:7: note: forward declaration of 'class EthernetServer'
class EthernetServer;
^~~~~~~~~~~~~~
In file included from c:\Users\God Slayer\Documents\Arduino\libraries\Ethernet_Generic\src/Ethernet_Generic_Impl.h:64,
from c:\Users\God Slayer\Documents\Arduino\libraries\Ethernet_Generic\src/Ethernet_Generic.h:85,
from c:\Users\God Slayer\Documents\Arduino\libraries\EthernetWebServer\src/EthernetWebServer.h:58,
from C:\Users\God Slayer\AppData\Local\Temp.arduinoIDE-unsaved2024312-18932-1qrw30p.7an7\sketch_apr12c\sketch_apr12c.ino:7:
c:\Users\God Slayer\Documents\Arduino\libraries\Ethernet_Generic\src/EthernetServer_Impl.h:83:42: error: invalid use of incomplete type 'class EthernetServer'
EthernetClient EthernetServer::available()
^
In file included from c:\Users\God Slayer\Documents\Arduino\libraries\Ethernet_Generic\src/Ethernet_Generic.h:84,
from c:\Users\God Slayer\Documents\Arduino\libraries\EthernetWebServer\src/EthernetWebServer.h:58,
from C:\Users\God Slayer\AppData\Local\Temp.arduinoIDE-unsaved2024312-18932-1qrw30p.7an7\sketch_apr12c\sketch_apr12c.ino:7:
c:\Users\God Slayer\Documents\Arduino\libraries\Ethernet_Generic\src/Ethernet_Generic.hpp:185:7: note: forward declaration of 'class EthernetServer'
class EthernetServer;
^~~~~~~~~~~~~~
In file included from c:\Users\God Slayer\Documents\Arduino\libraries\Ethernet_Generic\src/Ethernet_Generic_Impl.h:64,
from c:\Users\God Slayer\Documents\Arduino\libraries\Ethernet_Generic\src/Ethernet_Generic.h:85,
from c:\Users\God Slayer\Documents\Arduino\libraries\EthernetWebServer\src/EthernetWebServer.h:58,
from C:\Users\God Slayer\AppData\Local\Temp.arduinoIDE-unsaved2024312-18932-1qrw30p.7an7\sketch_apr12c\sketch_apr12c.ino:7:
c:\Users\God Slayer\Documents\Arduino\libraries\Ethernet_Generic\src/EthernetServer_Impl.h:143:39: error: invalid use of incomplete type 'class EthernetServer'
EthernetClient EthernetServer::accept()
^
In file included from c:\Users\God Slayer\Documents\Arduino\libraries\Ethernet_Generic\src/Ethernet_Generic.h:84,
from c:\Users\God Slayer\Documents\Arduino\libraries\EthernetWebServer\src/EthernetWebServer.h:58,
from C:\Users\God Slayer\AppData\Local\Temp.arduinoIDE-unsaved2024312-18932-1qrw30p.7an7\sketch_apr12c\sketch_apr12c.ino:7:
c:\Users\God Slayer\Documents\Arduino\libraries\Ethernet_Generic\src/Ethernet_Generic.hpp:185:7: note: forward declaration of 'class EthernetServer'
class EthernetServer;
^~~~~~~~~~~~~~
In file included from c:\Users\God Slayer\Documents\Arduino\libraries\Ethernet_Generic\src/Ethernet_Generic_Impl.h:64,
from c:\Users\God Slayer\Documents\Arduino\libraries\Ethernet_Generic\src/Ethernet_Generic.h:85,
from c:\Users\God Slayer\Documents\Arduino\libraries\EthernetWebServer\src/EthernetWebServer.h:58,
from C:\Users\God Slayer\AppData\Local\Temp.arduinoIDE-unsaved2024312-18932-1qrw30p.7an7\sketch_apr12c\sketch_apr12c.ino:7:
c:\Users\God Slayer\Documents\Arduino\libraries\Ethernet_Generic\src/EthernetServer_Impl.h:195:31: error: invalid use of incomplete type 'class EthernetServer'
EthernetServer::operator bool()
^
In file included from c:\Users\God Slayer\Documents\Arduino\libraries\Ethernet_Generic\src/Ethernet_Generic.h:84,
from c:\Users\God Slayer\Documents\Arduino\libraries\EthernetWebServer\src/EthernetWebServer.h:58,
from C:\Users\God Slayer\AppData\Local\Temp.arduinoIDE-unsaved2024312-18932-1qrw30p.7an7\sketch_apr12c\sketch_apr12c.ino:7:
c:\Users\God Slayer\Documents\Arduino\libraries\Ethernet_Generic\src/Ethernet_Generic.hpp:185:7: note: forward declaration of 'class EthernetServer'
class EthernetServer;
^~~~~~~~~~~~~~
In file included from c:\Users\God Slayer\Documents\Arduino\libraries\Ethernet_Generic\src/Ethernet_Generic_Impl.h:64,
from c:\Users\God Slayer\Documents\Arduino\libraries\Ethernet_Generic\src/Ethernet_Generic.h:85,
from c:\Users\God Slayer\Documents\Arduino\libraries\EthernetWebServer\src/EthernetWebServer.h:58,
from C:\Users\God Slayer\AppData\Local\Temp.arduinoIDE-unsaved2024312-18932-1qrw30p.7an7\sketch_apr12c\sketch_apr12c.ino:7:
c:\Users\God Slayer\Documents\Arduino\libraries\Ethernet_Generic\src/EthernetServer_Impl.h:225:35: error: invalid use of incomplete type 'class EthernetServer'
void EthernetServer::statusreport()
^
In file included from c:\Users\God Slayer\Documents\Arduino\libraries\Ethernet_Generic\src/Ethernet_Generic.h:84,
from c:\Users\God Slayer\Documents\Arduino\libraries\EthernetWebServer\src/EthernetWebServer.h:58,
from C:\Users\God Slayer\AppData\Local\Temp.arduinoIDE-unsaved2024312-18932-1qrw30p.7an7\sketch_apr12c\sketch_apr12c.ino:7:
c:\Users\God Slayer\Documents\Arduino\libraries\Ethernet_Generic\src/Ethernet_Generic.hpp:185:7: note: forward declaration of 'class EthernetServer'
class EthernetServer;
^~~~~~~~~~~~~~
In file included from c:\Users\God Slayer\Documents\Arduino\libraries\Ethernet_Generic\src/Ethernet_Generic_Impl.h:64,
from c:\Users\God Slayer\Documents\Arduino\libraries\Ethernet_Generic\src/Ethernet_Generic.h:85,
from c:\Users\God Slayer\Documents\Arduino\libraries\EthernetWebServer\src/EthernetWebServer.h:58,
from C:\Users\God Slayer\AppData\Local\Temp.arduinoIDE-unsaved2024312-18932-1qrw30p.7an7\sketch_apr12c\sketch_apr12c.ino:7:
c:\Users\God Slayer\Documents\Arduino\libraries\Ethernet_Generic\src/EthernetServer_Impl.h:310:39: error: invalid use of incomplete type 'class EthernetServer'
size_t EthernetServer::write(uint8_t b)
^
In file included from c:\Users\God Slayer\Documents\Arduino\libraries\Ethernet_Generic\src/Ethernet_Generic.h:84,
from c:\Users\God Slayer\Documents\Arduino\libraries\EthernetWebServer\src/EthernetWebServer.h:58,
from C:\Users\God Slayer\AppData\Local\Temp.arduinoIDE-unsaved2024312-18932-1qrw30p.7an7\sketch_apr12c\sketch_apr12c.ino:7:
c:\Users\God Slayer\Documents\Arduino\libraries\Ethernet_Generic\src/Ethernet_Generic.hpp:185:7: note: forward declaration of 'class EthernetServer'
class EthernetServer;
^~~~~~~~~~~~~~
In file included from c:\Users\God Slayer\Documents\Arduino\libraries\Ethernet_Generic\src/Ethernet_Generic_Impl.h:64,
from c:\Users\God Slayer\Documents\Arduino\libraries\Ethernet_Generic\src/Ethernet_Generic.h:85,
from c:\Users\God Slayer\Documents\Arduino\libraries\EthernetWebServer\src/EthernetWebServer.h:58,
from C:\Users\God Slayer\AppData\Local\Temp.arduinoIDE-unsaved2024312-18932-1qrw30p.7an7\sketch_apr12c\sketch_apr12c.ino:7:
c:\Users\God Slayer\Documents\Arduino\libraries\Ethernet_Generic\src/EthernetServer_Impl.h:324:87: error: invalid use of incomplete type 'class EthernetServer'
size_t EthernetServer::_write(const uint8_t sockindex, const uint8_t *buf, size_t size)
^
In file included from c:\Users\God Slayer\Documents\Arduino\libraries\Ethernet_Generic\src/Ethernet_Generic.h:84,
from c:\Users\God Slayer\Documents\Arduino\libraries\EthernetWebServer\src/EthernetWebServer.h:58,
from C:\Users\God Slayer\AppData\Local\Temp.arduinoIDE-unsaved2024312-18932-1qrw30p.7an7\sketch_apr12c\sketch_apr12c.ino:7:
c:\Users\God Slayer\Documents\Arduino\libraries\Ethernet_Generic\src/Ethernet_Generic.hpp:185:7: note: forward declaration of 'class EthernetServer'
class EthernetServer;
^~~~~~~~~~~~~~
In file included from c:\Users\God Slayer\Documents\Arduino\libraries\Ethernet_Generic\src/Ethernet_Generic_Impl.h:64,
from c:\Users\God Slayer\Documents\Arduino\libraries\Ethernet_Generic\src/Ethernet_Generic.h:85,
from c:\Users\God Slayer\Documents\Arduino\libraries\EthernetWebServer\src/EthernetWebServer.h:58,
from C:\Users\God Slayer\AppData\Local\Temp.arduinoIDE-unsaved2024312-18932-1qrw30p.7an7\sketch_apr12c\sketch_apr12c.ino:7:
c:\Users\God Slayer\Documents\Arduino\libraries\Ethernet_Generic\src/EthernetServer_Impl.h:392:64: error: invalid use of incomplete type 'class EthernetServer'
size_t EthernetServer::write(const uint8_t *buffer, size_t size)
^
In file included from c:\Users\God Slayer\Documents\Arduino\libraries\Ethernet_Generic\src/Ethernet_Generic.h:84,
from c:\Users\God Slayer\Documents\Arduino\libraries\EthernetWebServer\src/EthernetWebServer.h:58,
from C:\Users\God Slayer\AppData\Local\Temp.arduinoIDE-unsaved2024312-18932-1qrw30p.7an7\sketch_apr12c\sketch_apr12c.ino:7:
c:\Users\God Slayer\Documents\Arduino\libraries\Ethernet_Generic\src/Ethernet_Generic.hpp:185:7: note: forward declaration of 'class EthernetServer'
class EthernetServer;
^~~~~~~~~~~~~~
In file included from c:\Users\God Slayer\Documents\Arduino\libraries\Ethernet_Generic\src/Ethernet_Generic_Impl.h:66,
from c:\Users\God Slayer\Documents\Arduino\libraries\Ethernet_Generic\src/Ethernet_Generic.h:85,
from c:\Users\God Slayer\Documents\Arduino\libraries\EthernetWebServer\src/EthernetWebServer.h:58,
from C:\Users\God Slayer\AppData\Local\Temp.arduinoIDE-unsaved2024312-18932-1qrw30p.7an7\sketch_apr12c\sketch_apr12c.ino:7:
c:\Users\God Slayer\Documents\Arduino\libraries\Ethernet_Generic\src/socket_Impl.h: In member function 'uint8_t EthernetClass::socketBegin(uint8_t, uint16_t)':
c:\Users\God Slayer\Documents\Arduino\libraries\Ethernet_Generic\src/socket_Impl.h:174:19: error: incomplete type 'EthernetServer' used in nested name specifier
EthernetServer::server_port[s] = 0;
^~~~~~~~~~~
c:\Users\God Slayer\Documents\Arduino\libraries\Ethernet_Generic\src/socket_Impl.h: In member function 'uint8_t EthernetClass::socketBeginMulticast(uint8_t, IPAddress, uint16_t)':
c:\Users\God Slayer\Documents\Arduino\libraries\Ethernet_Generic\src/socket_Impl.h:275:19: error: incomplete type 'EthernetServer' used in nested name specifier
EthernetServer::server_port[s] = 0;
^~~~~~~~~~~
In file included from c:\Users\God Slayer\Documents\Arduino\libraries\EthernetWebServer\src/EthernetWebServer.h:67,
from C:\Users\God Slayer\AppData\Local\Temp.arduinoIDE-unsaved2024312-18932-1qrw30p.7an7\sketch_apr12c\sketch_apr12c.ino:7:
c:\Users\God Slayer\Documents\Arduino\libraries\EthernetWebServer\src/EthernetWebServer.hpp: At global scope:
c:\Users\God Slayer\Documents\Arduino\libraries\EthernetWebServer\src/EthernetWebServer.hpp:576:22: error: field '_server' has incomplete type 'EthernetServer'
EthernetServer _server;
^~~~~~~
In file included from c:\Users\God Slayer\Documents\Arduino\libraries\Ethernet_Generic\src/Ethernet_Generic.h:84,
from c:\Users\God Slayer\Documents\Arduino\libraries\EthernetWebServer\src/EthernetWebServer.h:58,
from C:\Users\God Slayer\AppData\Local\Temp.arduinoIDE-unsaved2024312-18932-1qrw30p.7an7\sketch_apr12c\sketch_apr12c.ino:7:
c:\Users\God Slayer\Documents\Arduino\libraries\Ethernet_Generic\src/Ethernet_Generic.hpp:185:7: note: forward declaration of 'class EthernetServer'
class EthernetServer;
^~~~~~~~~~~~~~
exit status 1
Compilation error: exit status 1
I got those error after I remove that class
Yeah there was something about modding the Server.h, can't remember the details.
Ah yes.
- For fixing ESP32 compile error
To fix ESP32 compile error
, just copy the following file into the ESP32
cores/esp32 directory (e.g. ./arduino-1.8.19/hardware/espressif/cores/esp32) to overwrite the old file:
@duong_007 "For crying out loud, please use code tags to post code or error messages !
Many thanks to @Juraj & @hamokhalil for responding to this thread.
Don't remove the whole 'Server' class, just modify the class to look like this
class Server: public Print
{
public:
// KH, change to fix compiler error for EthernetWebServer
// error: cannot declare field 'EthernetWebServer::_server' to be of abstract type 'EthernetServer'
// virtual void begin(uint16_t port=0) =0;
//virtual void begin() = 0;
void begin() {};
};
sorry for the wrong instruction
in Ethernet.h replace
class EthernetServer : public Server {
with
class EthernetServer : public Print {
That does the same thing in the end i suppose since
class Server: public Print
Thank you everyone for helping me solve my problem
'''
#include <WiFi.h>
#include <WebServer.h>
#include <Update.h>
#include <StreamString.h>
#include <SPI.h>
#include <EthernetWebServer.h>
#include "Ethernet_Generic.h"
#define W5500_CS 5
#define SPI_FRQ 32000000 // better than the 1 or 4MHz default
const char* update_path = "/firmware";
const char* username = "admin";
const char* pass = "password";
String IP_ADDRESS;
static const char pageheader[] PROGMEM = "";
static const char htmlhead[] PROGMEM = "HttpUpdater<meta http-equiv="Content-Type" content="text/html;charset=utf-8" >";
static const char bodystyle[] PROGMEM = "<body style="color: dimgray; background-color: palegoldenrod; font-size: 12pt; font-family: sans-serif;">";
static const char htmlclose[] PROGMEM = "";
byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED}; //byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x01};
IPAddress ip(192, 168, 1, 15); // Use yours
uint8_t ipByte[4];
long lastmsg =0;
bool flag = false;
EthernetWebServer ethernetServer(80);
WebServer wifiServer(80);
void handleEthernetRoot() {
//ethernetServer.send(200, "text/plain", "Hello from ESP32 Ethernet!");
ethernetServer.send(200, "text/plain", "Hello from ESP32 Ethernet!, The upload worked !!");
}
void setup() {
//Initialize serial and wait for port to open:
Serial.begin(115200);
pinMode(2,OUTPUT);
while (!Serial && millis() < 5000);
delay(100);
//OTAUpdateSetup();
ipByte[0] = ip[0];
ipByte[1] = ip[1];
ipByte[2] = ip[2];
ipByte[3] = ip[3];
SPI.setFrequency(SPI_FRQ);
Ethernet.init (W5500_CS);
// start the ethernet connection and the server:
//Ethernet.begin(mac); //For DHCP
Ethernet.begin(mac, ip);
if (Ethernet.hardwareStatus() == EthernetNoHardware)
{
Serial.println("No Ethernet found. Stay here forever");
// while (true)
// {
// delay(1); // do nothing, no point running without Ethernet hardware
// }
}
Serial.print("Ethernet Chip ID: ");
if(Ethernet.hardwareStatus() == EthernetW5500){
Serial.println("W5500");
}
if (Ethernet.linkStatus() == 2)
{
Serial.println("Not connected Ethernet cable");
}
Serial.println("Currently Used SPI pinout:");
Serial.print("MOSI: ");
Serial.print(MOSI);
Serial.print(", MISO: ");
Serial.print(MISO);
Serial.print(", SCK: ");
Serial.print(SCK);
Serial.print(", CS/SS: ");
Serial.println(W5500_CS);
Serial.print(F("Speed: "));
Serial.print(Ethernet.speedReport());
Serial.print(F(", Duplex: "));
Serial.print(Ethernet.duplexReport());
Serial.print(F(", Link status: "));
Serial.println(Ethernet.linkReport());
//ethernetServer.on("/", handleEthernetRoot);
// ethernetServer.on(update_path, HTTP_GET, handleUpdate);
// ethernetServer.on(update_path, HTTP_POST, handlePostUpdate, handleFileUpload);
ethernetServer.on("/", HTTP_GET, handleUpdate);
ethernetServer.on("/", HTTP_POST, handlePostUpdate, handleFileUpload);
ethernetServer.begin();;
IP_ADDRESS = Ethernet.localIP().toString();
Serial.print("HTTP EthernetWebServer is @ IP : ");
Serial.println(IP_ADDRESS);
}
void loop() {
//ArduinoOTA.handle();
ethernetServer.handleClient();
long now = millis();
while(now - lastmsg >1000){
flag = !flag;
digitalWrite(2,flag);
lastmsg = now;
}
}
//----------------------------------------- Firmware Update Pages -----------------------------------------------------
void handleUpdate() {
if (!ethernetServer.authenticate(username, pass))
return ethernetServer.requestAuthentication();
String s = "";
s += FPSTR(pageheader);
s += FPSTR(htmlhead);
s += FPSTR(bodystyle);
s += "
OTEthernet Firmware Update
";s += "
";";
s += "";
// s += " ";
// s += " Read RGBC color sensor
";
// s += "
s += " ";
// s += "Read RGBC color sensor
";
s += FPSTR(htmlclose);
ethernetServer.send(200, "text/html", s);
}
void handlePostUpdate() {
if (!ethernetServer.authenticate(username, pass))
return ethernetServer.requestAuthentication();
if (Update.hasError()) {
StreamString str;
Update.printError(str);
str;
String s = "";
s += FPSTR(pageheader);
s += FPSTR(htmlhead);
s += FPSTR(bodystyle);
s += "
Update Error
";s += str;
s += FPSTR(htmlclose);
ethernetServer.send(200, "text / html", s);
Serial.println("Failure updating!!");
}
else {
String s = "";
s += FPSTR(pageheader);
s += FPSTR(htmlhead);
s += FPSTR(bodystyle);
s += "Update Success ! Rebooting...\n"; //content= '30;
s += (htmlclose);
//ethernetServer.client().setNoDelay(true);
ethernetServer.send(200, "text / html", s);
ethernetServer.client().stop();
ESP.restart();
}
}
void handleFileUpload() {
if (!ethernetServer.authenticate(username, pass))
return ethernetServer.requestAuthentication();
ethernetHTTPUpload& upload = ethernetServer.upload();
String updateerror = "";
if (upload.status == UPLOAD_FILE_START) {
//EthernetUDP::stop();
uint32_t maxSketchSpace = (ESP.getFreeSketchSpace() - 0x1000) & 0xFFFFF000;
if (!Update.begin(maxSketchSpace)) { //start with max available size
StreamString str;
Update.printError(str);
updateerror = str;
}
}
else if (upload.status == UPLOAD_FILE_WRITE) {
if (Update.write(upload.buf, upload.currentSize) != upload.currentSize) {
StreamString str;
Update.printError(str);
updateerror = str;
}
}
else if (upload.status == UPLOAD_FILE_END) {
if (Update.end(true)) { //true to set the size to the current progress
StreamString str;
Update.printError(str);
updateerror = str;
}
}
else if (upload.status == UPLOAD_FILE_ABORTED) {
Update.end();
}
yield();
}
''''
class EthernetWebServer :: pulic Server {
....
}
I remove public Server so it become
Class EthernetWebServer {
....
}
@Juraj I use it with MQTTs server but since Ethernet_Generic.h doesn't support ESP_SSLClient.h so do you have any solution with this problem ?