-
Notifications
You must be signed in to change notification settings - Fork 13.3k
ESP8266HTTPUpdateServer extracted from WebUpdate example. #837
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
Conversation
If the client connection gets closed during a form upload, the fileUploadHandler is notified with the new UPLOAD_FILE_ABORTED status, and the loop is ended gracefully.
9f71029
to
927d6c9
Compare
#include "ESP8266HTTPUpdateServer.h" | ||
|
||
|
||
const char* ESP8266HTTPUpdateServer::_serverIndex = "<html><body><form method='POST' action='/update' enctype='multipart/form-data'>" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would suggest to store this HTML as a raw string literal
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, sorry, I missed that comment. It seems that My C++ is outdated :) , sounds good to me, will do.
927d6c9
to
04bc0d3
Compare
ESP8266HTTPUpdateServer::~ESP8266HTTPUpdateServer() | ||
{ | ||
if (_server) | ||
delete _server; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't look right in case when ESP8266WebServer instance was allocated statically outside this class. Consider the following code:
void runServer() {
ESP8266WebServer httpServer(80);
ESP8266HTTPUpdateServer updateServer;
updateServer.setup(&httpServer);
while (something) {
httpServer.handleClient();
}
}
Upon exit from this function, ESP8266WebServer will be deleted twice.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch, also like this, we make the dependency explicit, and make sure the user will import the ESP8266WebServer from the main .ino, otherwise, it won't get included/linked since arduino libs can't set dependencies AFAIK.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Btw, nightly builds of IDE already have library dependency tracking!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ohh, nice :)
Another thought is that it would probably make sense to pass ESP8266WebServer instance into web server callbacks — this way you would not need to store a _server pointer in your class. This would allow for pluggable "middleware" classes like in node.js. I'll take a look if we can achieve this without breaking a lot of existing sketches. Edit: |
Thanks Ivan!, will do. Yeah, the passing of server itself via the events would be nice, it's generally a good thing to provide the source of the event. I wonder if there's some way to do it without breaking existing sketches. May be by having ::on overloaded with the different possible callbacks. |
04bc0d3
to
6b9929e
Compare
Hold on, the example is gone away |
6b9929e
to
b7dee8b
Compare
Any idea of why could it be failing like this: /home/travis/build/esp8266/Arduino/build/linux/work/hardware/esp8266com/esp8266/libraries/ESP8266HTTPUpdateServer/src/ESP8266HTTPUpdateServer.cpp:2:24: fatal error: WifiClient.h: No such file or directory ? It does compile locally |
What do you think about renaming the lib to ESP8266HTTPUpdateApp or ESP8266HTTPUpdateHandler? |
b7dee8b
to
c3ce925
Compare
@igrr , any idea of why the travis WebUpdater.ino compilation could be failing?, It executed it locally the same way, and it does provide the -I path to WifiClient :-? |
In ESP8266HTTPUpdateServer.cpp, you need to observe the case in include names, i.e. WiFiClient instead of WifiClient, and others as well. Travis CI runs on Linux, so file names are case sensitive. |
arghhh!, damn case insensitive OSX default, thanks ... |
c3ce925
to
bc087d1
Compare
@iggr I could also do something like this for the DNS_SD_Arduino_OTA if you think that's valuable, and I'd be willing in testing it for robustness, recovery, and all kind of evil stuff we could want to do to it. Is somebody working on that, or can I take it? |
Encapsulating all the update logic into a nice ArduinoOTA library would be an improvement I guess. I don't think anyone is working on it, so if you can do it, that's great. |
This ESP8266HTTPUpdateServer can be instantiated and used more cleanly, it's also able to take or create an ESP8266WebServer to configure the events and /update handler. It's been made more robust by handling upload abort, which depends on fix provided for issue esp8266#833
bc087d1
to
91b1bd4
Compare
ESP8266HTTPUpdateServer extracted from WebUpdate example.
@mangelajo As discussed, i have made a change to ESP8266WebServer to allow writing more self-sufficient handlers. |
ESP8266HTTPUpdateServer extracted from WebUpdate example.
It depends on issue #833 fix.