mirror of
https://github.com/tzapu/WiFiManager.git
synced 2026-04-27 00:55:52 +03:00
[GH-ISSUE #790] Wifimanager does not work with esp8266webserver #661
Labels
No labels
📶 WiFi
🕸️ HTTP
Branch
DEV Help Wanted
Discussion
Documentation
ESP32
Example
Good First Issue
Hotfix
In Progress
Incomplete
Needs Feeback
Priority
QA
Question
Task
Upstream/Dependancy
bug
duplicate
enhancement
invalid
pull-request
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/WiFiManager#661
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @alemori on GitHub (Dec 20, 2018).
Original GitHub issue: https://github.com/tzapu/WiFiManager/issues/790
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?
@tablatronix commented on GitHub (Dec 20, 2018):
probably because wm uses it and you cannot use it twice
@alemori commented on GitHub (Dec 20, 2018):
and how can I use a server.send that works?
@tablatronix commented on GitHub (Dec 20, 2018):
the development branch allows it
@alemori commented on GitHub (Dec 20, 2018):
How is it done? Can you give me an example? Thank you
@tablatronix commented on GitHub (Dec 21, 2018):
#461
@tablatronix commented on GitHub (Dec 21, 2018):
Development branch dev/ondemandconfigportal should have an example in it
@alemori commented on GitHub (Dec 21, 2018):
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"=====(
<html> <head> </head><! DOCTYPE html>
DATOS DEL ATLETA
Nombre/Equipo
Femenino
Masculino
Edad
@tablatronix commented on GitHub (Dec 21, 2018):
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,
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"
@alemori commented on GitHub (Dec 24, 2018):
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
@tablatronix commented on GitHub (Dec 24, 2018):
You just have to change line of code if you want to do the later
@sarmadsohaib commented on GitHub (Aug 3, 2022):
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?