-
Notifications
You must be signed in to change notification settings - Fork 2k
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
howto call config page at runtime #525
Comments
for me this isn't working. after rebooting the device it connects back to my wifi network.
|
what version of esp ? |
oh nm, I see it, 2.4.0 has bugged erase config use development version of wm, or staging of esp |
sorry , let me check, you are obviously using dev branch |
ok try this
I forgot I removed it |
have you tried running one webserver on another port , like 81 ? |
not working for me. void resetwifi (){
WiFiManager wifiManager;
wifiManager.resetSettings();
ESP.reset();
} and below this line the whole sketch. /*
To upload through terminal you can use: curl -F "[email protected]" esp8266-webupdate.local/update
*/
#define FIXERASECONFIG
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include <ESP8266mDNS.h>
#include <ESP8266HTTPUpdateServer.h>
#include <WiFiManager.h>
ESP8266WebServer server(80);
ESP8266HTTPUpdateServer httpUpdater;
const int led = 13;
byte value;
void configModeCallback (WiFiManager *myWiFiManager) {
Serial.println("Entered config mode");
Serial.println(WiFi.softAPIP());
//if you used auto generated SSID, print it
Serial.println(myWiFiManager->getConfigPortalSSID());
}
void handleRoot() {
digitalWrite ( led, 1 );
char temp[400];
int sec = millis() / 1000;
int min = sec / 60;
int hr = min / 60;
snprintf ( temp, 400,
"<html>\
<head>\
<meta http-equiv='refresh' content='5'/>\
<title>ESP8266 Demo</title>\
<style>\
body { background-color: #cccccc; font-family: Arial, Helvetica, Sans-Serif; Color: #000088; }\
</style>\
</head>\
<body>\
<h1>Hello from ESP8266!</h1>\
<p>Uptime: %02d:%02d:%02d</p>\
<img src=\"/test.svg\" />\
</body>\
</html>",
hr, min % 60, sec % 60
);
server.send ( 200, "text/html", temp );
digitalWrite ( led, 0 );
}
void handleNotFound() {
digitalWrite ( led, 1 );
String message = "File Not Found\n\n";
message += "URI: ";
message += server.uri();
message += "\nMethod: ";
message += ( server.method() == HTTP_GET ) ? "GET" : "POST";
message += "\nArguments: ";
message += server.args();
message += "\n";
for ( uint8_t i = 0; i < server.args(); i++ ) {
message += " " + server.argName ( i ) + ": " + server.arg ( i ) + "\n";
}
server.send ( 404, "text/plain", message );
digitalWrite ( led, 0 );
}
void resetwifi (){
WiFiManager wifiManager;
wifiManager.resetSettings();
ESP.reset();
}
void setup(void){
WiFiManager wifiManager;
Serial.begin(115200);
Serial.println();
Serial.println("ESP starting .....");
//WiFiManager
//Local intialization. Once its business is done, there is no need to keep it around
wifiManager.setShowStaticFields(true);
wifiManager.setDebugOutput(true);
//set callback that gets called when connecting to previous WiFi fails, and enters Access Point mode
wifiManager.setAPCallback(configModeCallback);
//fetches ssid and pass and tries to connect
//if it does not connect it starts an access point with the specified name
//here "AutoConnectAP"
//and goes into a blocking loop awaiting configuration
if(!wifiManager.autoConnect()) {
Serial.println("failed to connect and hit timeout");
//reset and try again, or maybe put it to deep sleep
ESP.restart();
delay(1000);
}
//if you get here you have connected to the WiFi
Serial.println("WiFi Started.");
Serial.println("local ip");
Serial.println(WiFi.localIP());
httpUpdater.setup(&server);
Serial.println("httpUpdater started.");
server.on ( "/", handleRoot );
server.on ( "/test.svg", drawGraph );
server.on ( "/reset", resetwifi );
server.on ( "/inline", []() {
server.send ( 200, "text/plain", "this works as well" );
} );
server.onNotFound ( handleNotFound );
server.begin();
Serial.println("webserver started.");
Serial.println("Test Sketch v1.0 started");
}
void loop(void){
server.handleClient();
}
void drawGraph() {
String out = "";
char temp[100];
out += "<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\" width=\"400\" height=\"150\">\n";
out += "<rect width=\"400\" height=\"150\" fill=\"rgb(250, 230, 210)\" stroke-width=\"1\" stroke=\"rgb(0, 0, 0)\" />\n";
out += "<g stroke=\"black\">\n";
int y = rand() % 130;
for (int x = 10; x < 390; x+= 10) {
int y2 = rand() % 130;
sprintf(temp, "<line x1=\"%d\" y1=\"%d\" x2=\"%d\" y2=\"%d\" stroke-width=\"1\" />\n", x, 140 - y, x + 10, 140 - y2);
out += temp;
y = y2;
};
out += "</g>\n</svg>\n";
server.send ( 200, "image/svg+xml", out);
} |
use proper code formatting |
don't understand what is wrong with the above code formating. |
What happens if you minimize this to a basic sketch that sets then erases config ? |
The example sketch AutoConnectWithReset is running fine. see code i use for testing. #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>
#define FIXERASECONFIG
ESP8266WebServer server(80);
void handleRoot() {
server.send(200, "text/plain", "hello from esp8266!");
}
void handleReset() {
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 += server.uri();
message += "\nMethod: ";
message += (server.method() == HTTP_GET)?"GET":"POST";
message += "\nArguments: ";
message += server.args();
message += "\n";
for (uint8_t i=0; i<server.args(); i++){
message += " " + server.argName(i) + ": " + server.arg(i) + "\n";
}
server.send(404, "text/plain", message);
}
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println();
//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.onNotFound(handleNotFound);
server.begin();
Serial.println("HTTP server started");
}
void loop() {
// put your main code here, to run repeatedly:
server.handleClient();
} |
Thanks, fixed |
And where do i turn persistent on ? |
I fixed it in development |
i'm using the development brance and need to connect to the config page at runtime.
My problem is that at runtime i already run a webserver.
So calling wifiManager.startWebPortal(); isn't helping.
after calling this one all is hanging.
where i need it for is in case of needed, change the ssid and password and change static ip adres.
The text was updated successfully, but these errors were encountered: