Add a way to test Wifi Config in AP mode
This commit is contained in:
parent
2515e577a6
commit
810c9b881c
@ -141,9 +141,15 @@ void WebHandleSave() {
|
|||||||
WebSendError("Cannot Save Credentials (Too long ?Contains \";\"?)\r\n");
|
WebSendError("Cannot Save Credentials (Too long ?Contains \";\"?)\r\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if(WiFi.softAPIP() != IPAddress((uint32_t)0)){
|
||||||
server.send(200, "text/html", "<h1>Configuration Saved</h1><br/>"
|
//In STA mode, we can test the AP connection
|
||||||
"<a href=\"/reboot\">Reboot</a><br/>");
|
WiFi.begin(server.arg("ssid").c_str(), server.arg("password").c_str());
|
||||||
|
server.send(200, "text/html", "<h1>Configuration Saved</h1><br/>"
|
||||||
|
"<a href=\"/wifiStatus\">Check Wifi Configuration</a><br/>");
|
||||||
|
}else{
|
||||||
|
server.send(200, "text/html", "<h1>Configuration Saved</h1><br/>"
|
||||||
|
"<a href=\"/reboot\">Reboot</a><br/>");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebHandleOTA() {
|
void WebHandleOTA() {
|
||||||
@ -175,6 +181,40 @@ void WebHandleReboot() {
|
|||||||
ESP.restart();
|
ESP.restart();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String statusToString(wl_status_t status) {
|
||||||
|
switch(status){
|
||||||
|
case WL_IDLE_STATUS: return String("Idle");
|
||||||
|
case WL_NO_SSID_AVAIL: return String("Wifi not found");
|
||||||
|
case WL_CONNECTED: return String("Connected");
|
||||||
|
case WL_CONNECT_FAILED: return String("Connection failed (Wrong password ?)");
|
||||||
|
case WL_CONNECTION_LOST: return String("Connection Lost");
|
||||||
|
case WL_DISCONNECTED: return String("Connecting");
|
||||||
|
default: return String(status);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void WebHandleWifiStatus() {
|
||||||
|
|
||||||
|
String message;
|
||||||
|
if(WiFi.status() == WL_DISCONNECTED)
|
||||||
|
message += "<head><meta http-equiv=\"refresh\" content=\"1\" ></head>";
|
||||||
|
message += "<h1>Wifi Connection Status</h1><br/>";
|
||||||
|
message += "Connection to ";
|
||||||
|
message += WiFi.SSID();
|
||||||
|
message += ":<br/>";
|
||||||
|
message += statusToString(WiFi.status());
|
||||||
|
message += "<br/>";
|
||||||
|
if(mode == BOOTMODE_SETUP && WiFi.status() == WL_CONNECTED){
|
||||||
|
message += "Wifi correctly setup!, you can reboot now<br/>";
|
||||||
|
message += "<a href=\"/reboot\">Reboot</a><br/>";
|
||||||
|
}
|
||||||
|
if(WiFi.status() == WL_CONNECT_FAILED || WiFi.status() == WL_NO_SSID_AVAIL){
|
||||||
|
message += "Try to reconfigure you WiFi details<br/>";
|
||||||
|
message += "<a href=\"/setup\">Enter Setup</a><br/>";
|
||||||
|
}
|
||||||
|
server.send(200, "text/html", message);
|
||||||
|
}
|
||||||
|
|
||||||
void WebSetupServer(int ) {
|
void WebSetupServer(int ) {
|
||||||
server.on("/", WebHandleRoot);
|
server.on("/", WebHandleRoot);
|
||||||
server.on("/setup", WebHandleSetup);
|
server.on("/setup", WebHandleSetup);
|
||||||
@ -182,6 +222,7 @@ void WebSetupServer(int ) {
|
|||||||
server.on("/gpio", WebHandleGpio);
|
server.on("/gpio", WebHandleGpio);
|
||||||
server.on("/otamode", WebHandleOTA);
|
server.on("/otamode", WebHandleOTA);
|
||||||
server.on("/reboot", WebHandleReboot);
|
server.on("/reboot", WebHandleReboot);
|
||||||
|
server.on("/wifiStatus", WebHandleWifiStatus);
|
||||||
|
|
||||||
server.onNotFound(WebHandleNotFound);
|
server.onNotFound(WebHandleNotFound);
|
||||||
server.begin();
|
server.begin();
|
||||||
|
Loading…
Reference in New Issue
Block a user