WiFiManager
WiFiManager copied to clipboard
Wifimanager does not work with esp8266webserver
I'm using wifimanager version 0.14 with esp8266webserver version 1.0.0 and when I send html pages with server.send, it doesn't work for me and in the debug appears Request redirected to captive portal. What can it be?
probably because wm uses it and you cannot use it twice
and how can I use a server.send that works?
the development branch allows it
How is it done? Can you give me an example? Thank you
#461
Development branch dev/ondemandconfigportal should have an example in it
I went to Development branch dev/ondemandconfigportal, but only wifimanager is used there. I also wanted to compile the .ino and gave me errors, I guess the error is mine, because I do not know how to work with the development code. What I need is to be able to write the html interface using the ESP8266webserver facility. If there is any example that you can give me, I would appreciate it. I copy the code that I'm trying to make work, and for example when I invoke 192.168.4.1/pepepe, it doesn't give me anything back.
#include <FS.h> // this needs to be first, or it all crashes and burns... #include <WiFiManager.h> // https://github.com/tzapu/WiFiManager #include <ESP8266WebServer.h> #include <ESP8266mDNS.h> #include "index.h" ESP8266WebServer server2(81); String s1 = MAIN_page; //Read HTML contents
void handleRoot() { //server.setContentLength(CONTENT_LENGTH_UNKNOWN); server.send(200, "text/plain", "hello from esp8266!"); } void pepe(){ Serial.print("Entro a handleRoot"); //server.setContentLength(CONTENT_LENGTH_UNKNOWN); server.send(200, "text/html", s1); //Send web page } void handleReset() { //server.setContentLength(CONTENT_LENGTH_UNKNOWN); server.send(200, "text/plain", "Resetting!"); //Serial.println("diconnecting client and wifi"); //client.disconnect(); wifi_station_disconnect();
WiFiManager wifiManager; wifiManager.resetSettings(); ESP.reset();
}
void handleNotFound(){ String message = "File Not Found\n\n"; message += "URI: "; message += server2.uri(); message += "\nMethod: "; message += (server2.method() == HTTP_GET)?"GET":"POST"; message += "\nArguments: "; message += server2.args(); message += "\n"; for (uint8_t i=0; i<server2.args(); i++){ message += " " + server2.argName(i) + ": " + server2.arg(i) + "\n"; } server2.send(404, "text/plain", message); }
void setup() { // put your setup code here, to run once: Serial.begin(115200); Serial.println(); // Serial.setDebugOutput(true);
//WiFiManager //Local intialization. Once its business is done, there is no need to keep it around WiFiManager wifiManager;
//exit after config instead of connecting wifiManager.setBreakAfterConfig(true); //reset settings - for testing //wifiManager.resetSettings();
//tries to connect to last known settings //if it does not connect it starts an access point with the specified name //here "AutoConnectAP" with password "password" //and goes into a blocking loop awaiting configuration if (!wifiManager.autoConnect("AutoConnectAP", "password")) { Serial.println("failed to connect, we should reset as see if it connects"); delay(3000); ESP.restart(); delay(5000); }
//if you get here you have connected to the WiFi Serial.println(""); Serial.print("Connected to "); Serial.print("IP address: "); Serial.println(WiFi.localIP());
if (MDNS.begin("esp8266")) { Serial.println("MDNS responder started"); }
server.on("/", handleRoot);
server.on("/inline", { server.send(200, "text/plain", "this works as well"); }); server.on("/resetwifi", handleReset); server.on("/pepe", pepe); server.onNotFound(handleNotFound);
// server.begin(); server.begin(); Serial.println("HTTP server started");
}
void loop() { // put your main code here, to run repeatedly: server.handleClient();
}
===================== INDEX.h
const char MAIN_page[] PROGMEM = R"=====( <! DOCTYPE html>
The webserver is built in...
You either need to start your own webserver when wm is not running or out of scope, so the webservers do not clash.
or use the webserver provided by wm
It is in the example I noted
https://github.com/tzapu/WiFiManager/blob/development/examples/DEV/OnDemandConfigPortal/OnDemandConfigPortal.ino#L39
wm is used global, and the server is used, else use your own server when wm is unloaded.
also you didnt use code blocks in your comment, code is unreadable,
wm.setWebServerCallback(bindServerCallback); // we use this callback so we know the webserver is running
void bindServerCallback(){
wm.server->on("/custom",handleRoute);
// wm.server->on("/info",handleRoute); // can override wm!
}
void handleRoute(){
Serial.println("[HTTP] handle route");
wm.server->send(200, "text/plain", "hello from user code");
}
The alternative is do what others have and just change the webserver from private to public in the code an use the stable version of wm
Sorry there are no docs yet on this, it is new and obviously "in development"
I'm going to wait for it to be incorporated into the library, since I don't want to use the development banch. Thank you
You just have to change line of code if you want to do the later
I am late on this but experiencing exactly the same problem. Can you please tell me how to change the webserver from private to public in the code?