mirror of https://github.com/arendst/Tasmota.git
Implement WifiConfig 7
This commit is contained in:
parent
60e8aa6466
commit
4993d16ecb
|
@ -212,7 +212,7 @@ enum GetDateAndTimeOptions { DT_LOCAL, DT_UTC, DT_RESTART, DT_ENERGY };
|
|||
|
||||
enum LoggingLevels {LOG_LEVEL_NONE, LOG_LEVEL_ERROR, LOG_LEVEL_INFO, LOG_LEVEL_DEBUG, LOG_LEVEL_DEBUG_MORE, LOG_LEVEL_ALL};
|
||||
|
||||
enum WifiConfigOptions {WIFI_RESTART, WIFI_SMARTCONFIG, WIFI_MANAGER, WIFI_WPSCONFIG, WIFI_RETRY, WIFI_WAIT, WIFI_SERIAL, MAX_WIFI_OPTION};
|
||||
enum WifiConfigOptions {WIFI_RESTART, WIFI_SMARTCONFIG, WIFI_MANAGER, WIFI_WPSCONFIG, WIFI_RETRY, WIFI_WAIT, WIFI_SERIAL, WIFI_MANAGER_RESET_ONLY, MAX_WIFI_OPTION};
|
||||
|
||||
enum SwitchModeOptions {TOGGLE, FOLLOW, FOLLOW_INV, PUSHBUTTON, PUSHBUTTON_INV, PUSHBUTTONHOLD, PUSHBUTTONHOLD_INV, PUSHBUTTON_TOGGLE, MAX_SWITCH_OPTION};
|
||||
|
||||
|
|
|
@ -174,9 +174,9 @@ void WifiConfig(uint8_t type)
|
|||
}
|
||||
#endif // USE_WPS
|
||||
#ifdef USE_WEBSERVER
|
||||
else if (WIFI_MANAGER == wifi_config_type) {
|
||||
else if (WIFI_MANAGER == wifi_config_type || WIFI_MANAGER_RESET_ONLY == wifi_config_type) {
|
||||
AddLog_P(LOG_LEVEL_INFO, S_LOG_WIFI, PSTR(D_WCFG_2_WIFIMANAGER " " D_ACTIVE_FOR_3_MINUTES));
|
||||
WifiManagerBegin();
|
||||
WifiManagerBegin(WIFI_MANAGER_RESET_ONLY == wifi_config_type);
|
||||
}
|
||||
#endif // USE_WEBSERVER
|
||||
}
|
||||
|
|
|
@ -294,12 +294,14 @@ const char HTTP_BTN_RSTRT[] PROGMEM =
|
|||
const char HTTP_BTN_MENU_MODULE[] PROGMEM =
|
||||
"<p><form action='md' method='get'><button>" D_CONFIGURE_MODULE "</button></form></p>"
|
||||
"<p><form action='wi' method='get'><button>" D_CONFIGURE_WIFI "</button></form></p>";
|
||||
const char HTTP_BTN_RESET[] PROGMEM =
|
||||
"<br/>"
|
||||
"<form action='rt' method='get' onsubmit='return confirm(\"" D_CONFIRM_RESET_CONFIGURATION "\");'><button class='button bred'>" D_RESET_CONFIGURATION "</button></form>";
|
||||
const char HTTP_BTN_MENU4[] PROGMEM =
|
||||
"<p><form action='lg' method='get'><button>" D_CONFIGURE_LOGGING "</button></form></p>"
|
||||
"<p><form action='co' method='get'><button>" D_CONFIGURE_OTHER "</button></form></p>"
|
||||
"<p><form action='tp' method='get'><button>" D_CONFIGURE_TEMPLATE "</button></form></p>"
|
||||
"<br/>"
|
||||
"<form action='rt' method='get' onsubmit='return confirm(\"" D_CONFIRM_RESET_CONFIGURATION "\");'><button class='button bred'>" D_RESET_CONFIGURATION "</button></form>"
|
||||
"<p><form action='tp' method='get'><button>" D_CONFIGURE_TEMPLATE "</button></form></p>";
|
||||
const char HTTP_BTN_MENU5[] PROGMEM =
|
||||
"<p><form action='dl' method='get'><button>" D_BACKUP_CONFIGURATION "</button></form></p>"
|
||||
"<p><form action='rs' method='get'><button>" D_RESTORE_CONFIGURATION "</button></form></p>";
|
||||
const char HTTP_BTN_MAIN[] PROGMEM =
|
||||
|
@ -437,7 +439,7 @@ const char HDR_CTYPE_JSON[] PROGMEM = "application/json";
|
|||
const char HDR_CTYPE_STREAM[] PROGMEM = "application/octet-stream";
|
||||
|
||||
#define DNS_PORT 53
|
||||
enum HttpOptions {HTTP_OFF, HTTP_USER, HTTP_ADMIN, HTTP_MANAGER};
|
||||
enum HttpOptions {HTTP_OFF, HTTP_USER, HTTP_ADMIN, HTTP_MANAGER, HTTP_MANAGER_RESET_ONLY};
|
||||
|
||||
DNSServer *DnsServer;
|
||||
ESP8266WebServer *WebServer;
|
||||
|
@ -460,6 +462,10 @@ static void WebGetArg(const char* arg, char* out, size_t max)
|
|||
// out[max-1] = '\0'; // Ensure terminating NUL
|
||||
}
|
||||
|
||||
static bool WifiIsInManagerMode(){
|
||||
return (HTTP_MANAGER == webserver_state || HTTP_MANAGER_RESET_ONLY == webserver_state);
|
||||
}
|
||||
|
||||
void ShowWebSource(int source)
|
||||
{
|
||||
if ((source > 0) && (source < SRC_MAX)) {
|
||||
|
@ -480,8 +486,13 @@ void StartWebserver(int type, IPAddress ipweb)
|
|||
if (!Settings.web_refresh) { Settings.web_refresh = HTTP_REFRESH_TIME; }
|
||||
if (!webserver_state) {
|
||||
if (!WebServer) {
|
||||
WebServer = new ESP8266WebServer((HTTP_MANAGER==type) ? 80 : WEB_PORT);
|
||||
WebServer = new ESP8266WebServer((HTTP_MANAGER==type || HTTP_MANAGER_RESET_ONLY == type) ? 80 : WEB_PORT);
|
||||
WebServer->on("/", HandleRoot);
|
||||
WebServer->onNotFound(HandleNotFound);
|
||||
#ifndef FIRMWARE_MINIMAL
|
||||
WebServer->on("/rt", HandleResetConfiguration);
|
||||
#endif // FIRMWARE_MINIMAL
|
||||
if(HTTP_MANAGER_RESET_ONLY != type){
|
||||
WebServer->on("/up", HandleUpgradeFirmware);
|
||||
WebServer->on("/u1", HandleUpgradeFirmwareStart); // OTA
|
||||
WebServer->on("/u2", HTTP_POST, HandleUploadDone, HandleUploadLoop);
|
||||
|
@ -490,7 +501,6 @@ void StartWebserver(int type, IPAddress ipweb)
|
|||
WebServer->on("/ax", HandleAjaxConsoleRefresh);
|
||||
WebServer->on("/ay", HandleAjaxStatusRefresh);
|
||||
WebServer->on("/cm", HandleHttpCommand);
|
||||
WebServer->onNotFound(HandleNotFound);
|
||||
#ifndef FIRMWARE_MINIMAL
|
||||
WebServer->on("/cn", HandleConfiguration);
|
||||
WebServer->on("/md", HandleModuleConfiguration);
|
||||
|
@ -509,6 +519,7 @@ void StartWebserver(int type, IPAddress ipweb)
|
|||
XsnsCall(FUNC_WEB_ADD_HANDLER);
|
||||
#endif // Not FIRMWARE_MINIMAL
|
||||
}
|
||||
}
|
||||
reset_web_log_flag = false;
|
||||
WebServer->begin(); // Web server start
|
||||
}
|
||||
|
@ -529,7 +540,7 @@ void StopWebserver(void)
|
|||
}
|
||||
}
|
||||
|
||||
void WifiManagerBegin(void)
|
||||
void WifiManagerBegin(bool reset_only)
|
||||
{
|
||||
// setup AP
|
||||
if (!global_state.wifi_down) {
|
||||
|
@ -553,7 +564,7 @@ void WifiManagerBegin(void)
|
|||
DnsServer->setErrorReplyCode(DNSReplyCode::NoError);
|
||||
DnsServer->start(DNS_PORT, "*", WiFi.softAPIP());
|
||||
|
||||
StartWebserver(HTTP_MANAGER, WiFi.softAPIP());
|
||||
StartWebserver((reset_only ? HTTP_MANAGER_RESET_ONLY : HTTP_MANAGER), WiFi.softAPIP());
|
||||
}
|
||||
|
||||
void PollDnsWebserver(void)
|
||||
|
@ -576,7 +587,7 @@ void SetHeader(void)
|
|||
|
||||
bool WebAuthenticate(void)
|
||||
{
|
||||
if (Settings.web_password[0] != 0) {
|
||||
if (Settings.web_password[0] != 0 && HTTP_MANAGER_RESET_ONLY != webserver_state) {
|
||||
return WebServer->authenticate(WEB_USERNAME, Settings.web_password);
|
||||
} else {
|
||||
return true;
|
||||
|
@ -611,7 +622,7 @@ void ShowPage(String &page, bool auth)
|
|||
}
|
||||
page.replace(F("{j}"), info);
|
||||
|
||||
if (HTTP_MANAGER == webserver_state) {
|
||||
if (WifiIsInManagerMode()) {
|
||||
if (WifiConfigCounter()) {
|
||||
page.replace(F("</script>"), FPSTR(HTTP_SCRIPT_COUNTER));
|
||||
page += FPSTR(HTTP_COUNTER);
|
||||
|
@ -690,12 +701,12 @@ void HandleRoot(void)
|
|||
return;
|
||||
}
|
||||
|
||||
if (HTTP_MANAGER == webserver_state) {
|
||||
if (WifiIsInManagerMode()) {
|
||||
#ifndef FIRMWARE_MINIMAL
|
||||
if ((Settings.web_password[0] != 0) && !(WebServer->hasArg("USER1")) && !(WebServer->hasArg("PASS1"))) {
|
||||
if ((Settings.web_password[0] != 0) && !(WebServer->hasArg("USER1")) && !(WebServer->hasArg("PASS1")) && HTTP_MANAGER_RESET_ONLY != webserver_state) {
|
||||
HandleWifiLogin();
|
||||
} else {
|
||||
if (!(Settings.web_password[0] != 0) || ((WebServer->arg("USER1") == WEB_USERNAME ) && (WebServer->arg("PASS1") == Settings.web_password ))) {
|
||||
if (!(Settings.web_password[0] != 0) || ((WebServer->arg("USER1") == WEB_USERNAME ) && (WebServer->arg("PASS1") == Settings.web_password ) || HTTP_MANAGER_RESET_ONLY == webserver_state)) {
|
||||
HandleWifiConfiguration();
|
||||
} else {
|
||||
// wrong user and pass
|
||||
|
@ -874,6 +885,8 @@ void HandleConfiguration(void)
|
|||
page += String(mqtt_data);
|
||||
|
||||
page += FPSTR(HTTP_BTN_MENU4);
|
||||
page += FPSTR(HTTP_BTN_RESET);
|
||||
page += FPSTR(HTTP_BTN_MENU5);
|
||||
page += FPSTR(HTTP_BTN_MAIN);
|
||||
ShowPage(page);
|
||||
}
|
||||
|
@ -1125,7 +1138,7 @@ void HandleWifiConfiguration(void)
|
|||
|
||||
AddLog_P(LOG_LEVEL_DEBUG, S_LOG_HTTP, S_CONFIGURE_WIFI);
|
||||
|
||||
if (WebServer->hasArg("save")) {
|
||||
if (WebServer->hasArg("save") && HTTP_MANAGER_RESET_ONLY != webserver_state) {
|
||||
WifiSaveSettings();
|
||||
WebRestart(2);
|
||||
return;
|
||||
|
@ -1136,6 +1149,8 @@ void HandleWifiConfiguration(void)
|
|||
page += FPSTR(HTTP_SCRIPT_WIFI);
|
||||
page += FPSTR(HTTP_HEAD_STYLE);
|
||||
|
||||
|
||||
if(HTTP_MANAGER_RESET_ONLY != webserver_state){
|
||||
if (WebServer->hasArg("scan")) {
|
||||
#ifdef USE_EMULATION
|
||||
UdpDisconnect();
|
||||
|
@ -1213,13 +1228,17 @@ void HandleWifiConfiguration(void)
|
|||
page.replace(F("{s1"), Settings.sta_ssid[0]);
|
||||
page.replace(F("{s2"), Settings.sta_ssid[1]);
|
||||
page += FPSTR(HTTP_FORM_END);
|
||||
if (HTTP_MANAGER == webserver_state) {
|
||||
}
|
||||
if (WifiIsInManagerMode()) {
|
||||
page += FPSTR(HTTP_BTN_RSTRT);
|
||||
#ifndef FIRMWARE_MINIMAL
|
||||
page += FPSTR(HTTP_BTN_RESET);
|
||||
#endif // FIRMWARE_MINIMAL
|
||||
} else {
|
||||
page += FPSTR(HTTP_BTN_CONF);
|
||||
}
|
||||
// ShowPage(page);
|
||||
ShowPage(page, !(HTTP_MANAGER == webserver_state));
|
||||
ShowPage(page, !(WifiIsInManagerMode()));
|
||||
}
|
||||
|
||||
void WifiSaveSettings(void)
|
||||
|
@ -2089,7 +2108,7 @@ void HandleNotFound(void)
|
|||
/* Redirect to captive portal if we got a request for another domain. Return true in that case so the page handler do not try to handle the request again. */
|
||||
bool CaptivePortal(void)
|
||||
{
|
||||
if ((HTTP_MANAGER == webserver_state) && !ValidIpAddress(WebServer->hostHeader())) {
|
||||
if ((WifiIsInManagerMode()) && !ValidIpAddress(WebServer->hostHeader())) {
|
||||
AddLog_P(LOG_LEVEL_DEBUG, PSTR(D_LOG_HTTP D_REDIRECTED));
|
||||
|
||||
WebServer->sendHeader(F("Location"), String("http://") + WebServer->client().localIP().toString(), true);
|
||||
|
|
Loading…
Reference in New Issue