Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v2.4.0 - ESP8266WebServer missing #4085

Closed
bill-orange opened this issue Jan 4, 2018 · 27 comments
Closed

v2.4.0 - ESP8266WebServer missing #4085

bill-orange opened this issue Jan 4, 2018 · 27 comments

Comments

@bill-orange
Copy link

Hardware: Wemos R2
Core Version: unknown

Description: (see below)

My sketch worked fine with v2.3.0. compiling with 2.4.0 I get:

use of deleted function 'ESP8266WebServer::ESP8266WebServer(const ESP8266WebServer&)

compiling with: 2.4.0 vs 2.3.0

Problem description: Can not compile

Settings in IDE

Module: ESPDurino D2 mini
Flash Size: 4 MB
CPU Frequency: 80Mhz

@igrr
Copy link
Member

igrr commented Jan 4, 2018

Please post the (preferably minimal) sketch which has this problem.

@bill-orange
Copy link
Author

Unfortunately the sketch is large. Perhaps an excerpt will be sufficient. If not here is a link to the whole sketch.

Here is a link to the whole sketch:
https://1drv.ms/u/s!AmXKqAwyCrbxh-BLqssNGUJ4Sdh92Q

excerpt:
`
#include <ESP8266WebServer.h>

ESP8266WebServer server = ESP8266WebServer(port);// create a web server on port 8021

/------------------------------startServerFUNCTIONS----------------------------------/

void startServer() { // Start a HTTP server with a file read handler and an upload handler
server.on("/edit.html", HTTP_POST, { // If a POST request is sent to the /edit.html address,
server.send(200, "text/plain", "hello from esp8266!");
}, handleFileUpload); // go to 'handleFileUpload'

server.onNotFound(handleNotFound); // if someone requests any other file or page, go to function 'handleNotFound'
// and check if the file exists

server.begin(); // start the HTTP server
Serial.println("HTTP server started.");
}

void setup() {
startServer();
}
void loop() {
server.handleClient();
}
`

@igrr
Copy link
Member

igrr commented Jan 4, 2018

Indeed, the issue is with ESP8266WebServer server = ESP8266WebServer(port);

Is there some specific reason why you need to use assignment here, rather than just ESP8266WebServer server(port);?

@bill-orange
Copy link
Author

Probably not. I will test it with this change tomorrow. There are many sample sketches around with the syntax I used.

@bill-orange
Copy link
Author

Worked fine when using v2.4.0 and ESP8266WebServer server(port);

Thanks

@devyte
Copy link
Collaborator

devyte commented Jan 5, 2018

@igrr The compiler seems to think that the copy constructor is deleted, but I don't see that explicitly done in the class. AFAIK, the default copy constructor for a class T is implicitly deleted if one of these conditions is met:

  1. T has non-static data members that cannot be copied (have deleted, inaccessible, or ambiguous copy constructors);
  2. T has direct or virtual base class that cannot be copied (has deleted, inaccessible, or ambiguous copy constructors);
  3. T has direct or virtual base class with a deleted or inaccessible destructor;
  4. T has a user-defined move constructor or move assignment operator;
  5. T is a union-like class and has a variant member with non-trivial copy constructor;
  6. T has a data member of rvalue reference type.

Ref: cppreference

WiFi has multiple inheritance, but I don't see 2, 3, 4, 5, or 6 anywhere, so my guess is 1.: some member was added that the compiler thinks has a non-trivial constructor.

@igrr
Copy link
Member

igrr commented Jan 5, 2018

That's ESP8266WebServer, not WiFi class. It has a unique_ptr member which can not be copied, case 1). In general, copying ESP8266WebServer is not a well defined operation. Should we expect that two web server instances on the same port somehow continue to work after copying? Or only one of them works (in which case this is more like a move operation)?

Possible solutions are:

a) Replace unique_ptr with shared_ptr, make copying possible. This will allow the OPs use case to work, but would allow silent copying of ESP8266WebServer object. Since this object contains some pointers which are managed manually, in general copying it is not a safe thing to do.
This problem (ambiguity of copy operation) was present in earlier versions, hopefully users didn't copy the web server object while request was in progress.

b) Implement move constructor — i think this will also allow the OPs use case to work (not sure, need to check).

c) Don't allow copying at all. This will require the existing sketches to be updated as mentioned above.

@devyte
Copy link
Collaborator

devyte commented Jan 5, 2018

I read ESP8266WebServer but my brain registered ESP8266WiFi. Ok, enough for today, getting some sleep now :p
IMT(ired)O, copying should be allowed, but in a well defined manner.
In contrast, ESP8266WiFi should not allow copy.

@SciLor
Copy link

SciLor commented Jan 7, 2018

@bill-orange
Copy link
Author

I think if you change the line ESP8266WebServer _server = ESP8266WebServer(80); to
ESP8266WebServer _server(80); it should work,

@SciLor
Copy link

SciLor commented Jan 7, 2018

Won't work.

WrapperWebconfig.h:83: error: expected identifier before numeric constant
ESP8266WebServer _server(80);// = ESP8266WebServer(80);

@mdhiggins
Copy link

I too am having issues with this change
With my project users used to have option to load a custom port from WiFiManager settings after they were read from a JSON file and I would reinitialize the EPS8266WebServer as follows:

  if (port != defaultport) {
    Serial.println("Default port changed");
    server = ESP8266WebServer(port);
  }

A way to change the port would be ideal, but this workaround doesn't work anymore with this change

@bill-orange
Copy link
Author

This is not really a work-around but have you tries compiling with v2.4.0 using earlier versions of lwIP?
lwip

@mdhiggins
Copy link

mdhiggins commented Jan 7, 2018

Found a workaround

Had to change

ESP8266WebServer server(port);
...
if (port != 80) {
  Serial.println("Default port changed");
  server = ESP8266WebServer(port);
}

to

ESP8266WebServer *server;
...
server = new ESP8266WebServer(port);

Had to change all syntax from server.* to server->* as well with this formatting but seems to be compiling

@devyte
Copy link
Collaborator

devyte commented Jan 7, 2018

@mdhiggins you have to delete the pointer before doing another new, or it will leak.
There is a PR with a proposal for adding a method that changes the port.
About copy construction (and assignment), it currently doesn't work correctly, so for the time being it's better that it doesn't compile.

@mdhiggins
Copy link

mdhiggins commented Jan 7, 2018

@devyte good point, I just never initialized the first 'new' and removed the conditional to check if the defaultport is set. Do I still need to delete? That would be the first time the server pointer is initialized

@devyte
Copy link
Collaborator

devyte commented Jan 7, 2018

Init the ptr to nullptr, then check it right before you new it if !=nullptr. If so, delete it.

@chun48
Copy link

chun48 commented Jan 7, 2018

Hello, I am not an expert but I had the same problem with a NodeMCU V1.0 and I solved it by installing the version of esp8266 2.4.0-rc2
esp8266rc2

@devyte
Copy link
Collaborator

devyte commented Jan 7, 2018

@chun48 rc2 was a release candidate, and is now superseded by 2.4.0.
To be blunt: any code that copies the webserver object is wrong, as the class was not designed for it.
If what is needed here is to change the port, then there is a PR proposing an implementation. Please test that. If it works, it can be merged.

@devyte
Copy link
Collaborator

devyte commented Jan 7, 2018

Referenced pr is #2716 , adds a begin(port) method.

@igrr
Copy link
Member

igrr commented Jan 8, 2018

@devyte That PR is for WiFiServer, not ESP8266WebServer... However adding an equivalent method for ESP8266WebServer should not be hard once #2716 is merged.

@igrr igrr modified the milestones: 2.5.0, 2.4.1 Jan 16, 2018
@devyte
Copy link
Collaborator

devyte commented Jan 18, 2018

Ok, created PR #4148 for the port method.

@FahadHussain777
Copy link

@bill-orange ESP8266WebServer _server(80) is working in my case

mhaas pushed a commit to mhaas/coffee-arduino-2 that referenced this issue Feb 2, 2018
@devyte devyte self-assigned this Feb 5, 2018
@devyte
Copy link
Collaborator

devyte commented Feb 7, 2018

Closed via #4148 . Don't use.copy constructor anymore, it's still disallowed.

@Kermit66
Copy link

Same problem with version 2.4.1
Ok with version 2.4.0
I use Wemos D1 R2, gizwits module, Adafruit HUZZAH ESP8266 Breakout
The server don't start with version 2.4.1

@d-a-v
Copy link
Collaborator

d-a-v commented May 10, 2018

@Kermit66 have you tried the erase flash options ?

@Kermit66
Copy link

Yes always delete the memory

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

9 participants