mirror of
https://github.com/arendst/Tasmota.git
synced 2025-07-29 21:56:35 +00:00
Merge pull request #5297 from netpok/wificonfig-7
WifiConfig 7, a reset only WifiManager for smart bulbs
This commit is contained in:
commit
8df6bb76d1
@ -248,6 +248,7 @@
|
|||||||
#define D_WCFG_4_RETRY "Retry"
|
#define D_WCFG_4_RETRY "Retry"
|
||||||
#define D_WCFG_5_WAIT "Wait"
|
#define D_WCFG_5_WAIT "Wait"
|
||||||
#define D_WCFG_6_SERIAL "Serial"
|
#define D_WCFG_6_SERIAL "Serial"
|
||||||
|
#define D_WCFG_7_WIFIMANAGER_RESET_ONLY "ManagerRst"
|
||||||
#define D_CMND_FRIENDLYNAME "FriendlyName"
|
#define D_CMND_FRIENDLYNAME "FriendlyName"
|
||||||
#define D_CMND_SWITCHMODE "SwitchMode"
|
#define D_CMND_SWITCHMODE "SwitchMode"
|
||||||
#define D_CMND_INTERLOCK "Interlock"
|
#define D_CMND_INTERLOCK "Interlock"
|
||||||
@ -540,7 +541,8 @@ const char kWifiConfig[MAX_WIFI_OPTION][WCFG_MAX_STRING_LENGTH] PROGMEM = {
|
|||||||
D_WCFG_3_WPSCONFIG,
|
D_WCFG_3_WPSCONFIG,
|
||||||
D_WCFG_4_RETRY,
|
D_WCFG_4_RETRY,
|
||||||
D_WCFG_5_WAIT,
|
D_WCFG_5_WAIT,
|
||||||
D_WCFG_6_SERIAL };
|
D_WCFG_6_SERIAL,
|
||||||
|
D_WCFG_7_WIFIMANAGER_RESET_ONLY };
|
||||||
const char kPrefixes[3][PRFX_MAX_STRING_LENGTH] PROGMEM = {
|
const char kPrefixes[3][PRFX_MAX_STRING_LENGTH] PROGMEM = {
|
||||||
D_CMND,
|
D_CMND,
|
||||||
D_STAT,
|
D_STAT,
|
||||||
|
@ -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 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};
|
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
|
#endif // USE_WPS
|
||||||
#ifdef USE_WEBSERVER
|
#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));
|
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
|
#endif // USE_WEBSERVER
|
||||||
}
|
}
|
||||||
|
@ -294,12 +294,14 @@ const char HTTP_BTN_RSTRT[] PROGMEM =
|
|||||||
const char HTTP_BTN_MENU_MODULE[] PROGMEM =
|
const char HTTP_BTN_MENU_MODULE[] PROGMEM =
|
||||||
"<p><form action='md' method='get'><button>" D_CONFIGURE_MODULE "</button></form></p>"
|
"<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>";
|
"<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 =
|
const char HTTP_BTN_MENU4[] PROGMEM =
|
||||||
"<p><form action='lg' method='get'><button>" D_CONFIGURE_LOGGING "</button></form></p>"
|
"<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='co' method='get'><button>" D_CONFIGURE_OTHER "</button></form></p>"
|
||||||
"<p><form action='tp' method='get'><button>" D_CONFIGURE_TEMPLATE "</button></form></p>"
|
"<p><form action='tp' method='get'><button>" D_CONFIGURE_TEMPLATE "</button></form></p>";
|
||||||
"<br/>"
|
const char HTTP_BTN_MENU5[] PROGMEM =
|
||||||
"<form action='rt' method='get' onsubmit='return confirm(\"" D_CONFIRM_RESET_CONFIGURATION "\");'><button class='button bred'>" D_RESET_CONFIGURATION "</button></form>"
|
|
||||||
"<p><form action='dl' method='get'><button>" D_BACKUP_CONFIGURATION "</button></form></p>"
|
"<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>";
|
"<p><form action='rs' method='get'><button>" D_RESTORE_CONFIGURATION "</button></form></p>";
|
||||||
const char HTTP_BTN_MAIN[] PROGMEM =
|
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";
|
const char HDR_CTYPE_STREAM[] PROGMEM = "application/octet-stream";
|
||||||
|
|
||||||
#define DNS_PORT 53
|
#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;
|
DNSServer *DnsServer;
|
||||||
ESP8266WebServer *WebServer;
|
ESP8266WebServer *WebServer;
|
||||||
@ -460,6 +462,10 @@ static void WebGetArg(const char* arg, char* out, size_t max)
|
|||||||
// out[max-1] = '\0'; // Ensure terminating NUL
|
// 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)
|
void ShowWebSource(int source)
|
||||||
{
|
{
|
||||||
if ((source > 0) && (source < SRC_MAX)) {
|
if ((source > 0) && (source < SRC_MAX)) {
|
||||||
@ -480,34 +486,39 @@ void StartWebserver(int type, IPAddress ipweb)
|
|||||||
if (!Settings.web_refresh) { Settings.web_refresh = HTTP_REFRESH_TIME; }
|
if (!Settings.web_refresh) { Settings.web_refresh = HTTP_REFRESH_TIME; }
|
||||||
if (!webserver_state) {
|
if (!webserver_state) {
|
||||||
if (!WebServer) {
|
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->on("/", HandleRoot);
|
||||||
WebServer->on("/up", HandleUpgradeFirmware);
|
|
||||||
WebServer->on("/u1", HandleUpgradeFirmwareStart); // OTA
|
|
||||||
WebServer->on("/u2", HTTP_POST, HandleUploadDone, HandleUploadLoop);
|
|
||||||
WebServer->on("/u2", HTTP_OPTIONS, HandlePreflightRequest);
|
|
||||||
WebServer->on("/cs", HandleConsole);
|
|
||||||
WebServer->on("/ax", HandleAjaxConsoleRefresh);
|
|
||||||
WebServer->on("/ay", HandleAjaxStatusRefresh);
|
|
||||||
WebServer->on("/cm", HandleHttpCommand);
|
|
||||||
WebServer->onNotFound(HandleNotFound);
|
WebServer->onNotFound(HandleNotFound);
|
||||||
#ifndef FIRMWARE_MINIMAL
|
#ifndef FIRMWARE_MINIMAL
|
||||||
WebServer->on("/cn", HandleConfiguration);
|
|
||||||
WebServer->on("/md", HandleModuleConfiguration);
|
|
||||||
WebServer->on("/wi", HandleWifiConfiguration);
|
|
||||||
WebServer->on("/lg", HandleLoggingConfiguration);
|
|
||||||
WebServer->on("/tp", HandleTemplateConfiguration);
|
|
||||||
WebServer->on("/co", HandleOtherConfiguration);
|
|
||||||
WebServer->on("/dl", HandleBackupConfiguration);
|
|
||||||
WebServer->on("/rs", HandleRestoreConfiguration);
|
|
||||||
WebServer->on("/rt", HandleResetConfiguration);
|
WebServer->on("/rt", HandleResetConfiguration);
|
||||||
WebServer->on("/in", HandleInformation);
|
#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);
|
||||||
|
WebServer->on("/u2", HTTP_OPTIONS, HandlePreflightRequest);
|
||||||
|
WebServer->on("/cs", HandleConsole);
|
||||||
|
WebServer->on("/ax", HandleAjaxConsoleRefresh);
|
||||||
|
WebServer->on("/ay", HandleAjaxStatusRefresh);
|
||||||
|
WebServer->on("/cm", HandleHttpCommand);
|
||||||
|
#ifndef FIRMWARE_MINIMAL
|
||||||
|
WebServer->on("/cn", HandleConfiguration);
|
||||||
|
WebServer->on("/md", HandleModuleConfiguration);
|
||||||
|
WebServer->on("/wi", HandleWifiConfiguration);
|
||||||
|
WebServer->on("/lg", HandleLoggingConfiguration);
|
||||||
|
WebServer->on("/tp", HandleTemplateConfiguration);
|
||||||
|
WebServer->on("/co", HandleOtherConfiguration);
|
||||||
|
WebServer->on("/dl", HandleBackupConfiguration);
|
||||||
|
WebServer->on("/rs", HandleRestoreConfiguration);
|
||||||
|
WebServer->on("/rt", HandleResetConfiguration);
|
||||||
|
WebServer->on("/in", HandleInformation);
|
||||||
#ifdef USE_EMULATION
|
#ifdef USE_EMULATION
|
||||||
HueWemoAddHandlers();
|
HueWemoAddHandlers();
|
||||||
#endif // USE_EMULATION
|
#endif // USE_EMULATION
|
||||||
XdrvCall(FUNC_WEB_ADD_HANDLER);
|
XdrvCall(FUNC_WEB_ADD_HANDLER);
|
||||||
XsnsCall(FUNC_WEB_ADD_HANDLER);
|
XsnsCall(FUNC_WEB_ADD_HANDLER);
|
||||||
#endif // Not FIRMWARE_MINIMAL
|
#endif // Not FIRMWARE_MINIMAL
|
||||||
|
}
|
||||||
}
|
}
|
||||||
reset_web_log_flag = false;
|
reset_web_log_flag = false;
|
||||||
WebServer->begin(); // Web server start
|
WebServer->begin(); // Web server start
|
||||||
@ -529,7 +540,7 @@ void StopWebserver(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void WifiManagerBegin(void)
|
void WifiManagerBegin(bool reset_only)
|
||||||
{
|
{
|
||||||
// setup AP
|
// setup AP
|
||||||
if (!global_state.wifi_down) {
|
if (!global_state.wifi_down) {
|
||||||
@ -553,7 +564,7 @@ void WifiManagerBegin(void)
|
|||||||
DnsServer->setErrorReplyCode(DNSReplyCode::NoError);
|
DnsServer->setErrorReplyCode(DNSReplyCode::NoError);
|
||||||
DnsServer->start(DNS_PORT, "*", WiFi.softAPIP());
|
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)
|
void PollDnsWebserver(void)
|
||||||
@ -576,7 +587,7 @@ void SetHeader(void)
|
|||||||
|
|
||||||
bool WebAuthenticate(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);
|
return WebServer->authenticate(WEB_USERNAME, Settings.web_password);
|
||||||
} else {
|
} else {
|
||||||
return true;
|
return true;
|
||||||
@ -611,7 +622,7 @@ void ShowPage(String &page, bool auth)
|
|||||||
}
|
}
|
||||||
page.replace(F("{j}"), info);
|
page.replace(F("{j}"), info);
|
||||||
|
|
||||||
if (HTTP_MANAGER == webserver_state) {
|
if (WifiIsInManagerMode()) {
|
||||||
if (WifiConfigCounter()) {
|
if (WifiConfigCounter()) {
|
||||||
page.replace(F("</script>"), FPSTR(HTTP_SCRIPT_COUNTER));
|
page.replace(F("</script>"), FPSTR(HTTP_SCRIPT_COUNTER));
|
||||||
page += FPSTR(HTTP_COUNTER);
|
page += FPSTR(HTTP_COUNTER);
|
||||||
@ -655,14 +666,16 @@ void WebRestart(uint8_t type)
|
|||||||
page.replace(F("{v}"), FPSTR(S_RESTART));
|
page.replace(F("{v}"), FPSTR(S_RESTART));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool reset_only = (HTTP_MANAGER_RESET_ONLY == webserver_state);
|
||||||
|
|
||||||
page += FPSTR(HTTP_MSG_RSTRT);
|
page += FPSTR(HTTP_MSG_RSTRT);
|
||||||
if (HTTP_MANAGER == webserver_state) {
|
if (HTTP_MANAGER == webserver_state || reset_only) {
|
||||||
webserver_state = HTTP_ADMIN;
|
webserver_state = HTTP_ADMIN;
|
||||||
} else {
|
} else {
|
||||||
page += FPSTR(HTTP_BTN_MAIN);
|
page += FPSTR(HTTP_BTN_MAIN);
|
||||||
}
|
}
|
||||||
page.replace(F("</script>"), FPSTR(HTTP_SCRIPT_RELOAD));
|
page.replace(F("</script>"), FPSTR(HTTP_SCRIPT_RELOAD));
|
||||||
ShowPage(page);
|
ShowPage(page, !reset_only);
|
||||||
|
|
||||||
ShowWebSource(SRC_WEBGUI);
|
ShowWebSource(SRC_WEBGUI);
|
||||||
restart_flag = 2;
|
restart_flag = 2;
|
||||||
@ -690,12 +703,12 @@ void HandleRoot(void)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (HTTP_MANAGER == webserver_state) {
|
if (WifiIsInManagerMode()) {
|
||||||
#ifndef FIRMWARE_MINIMAL
|
#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();
|
HandleWifiLogin();
|
||||||
} else {
|
} 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();
|
HandleWifiConfiguration();
|
||||||
} else {
|
} else {
|
||||||
// wrong user and pass
|
// wrong user and pass
|
||||||
@ -874,6 +887,8 @@ void HandleConfiguration(void)
|
|||||||
page += String(mqtt_data);
|
page += String(mqtt_data);
|
||||||
|
|
||||||
page += FPSTR(HTTP_BTN_MENU4);
|
page += FPSTR(HTTP_BTN_MENU4);
|
||||||
|
page += FPSTR(HTTP_BTN_RESET);
|
||||||
|
page += FPSTR(HTTP_BTN_MENU5);
|
||||||
page += FPSTR(HTTP_BTN_MAIN);
|
page += FPSTR(HTTP_BTN_MAIN);
|
||||||
ShowPage(page);
|
ShowPage(page);
|
||||||
}
|
}
|
||||||
@ -1125,7 +1140,7 @@ void HandleWifiConfiguration(void)
|
|||||||
|
|
||||||
AddLog_P(LOG_LEVEL_DEBUG, S_LOG_HTTP, S_CONFIGURE_WIFI);
|
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();
|
WifiSaveSettings();
|
||||||
WebRestart(2);
|
WebRestart(2);
|
||||||
return;
|
return;
|
||||||
@ -1136,90 +1151,96 @@ void HandleWifiConfiguration(void)
|
|||||||
page += FPSTR(HTTP_SCRIPT_WIFI);
|
page += FPSTR(HTTP_SCRIPT_WIFI);
|
||||||
page += FPSTR(HTTP_HEAD_STYLE);
|
page += FPSTR(HTTP_HEAD_STYLE);
|
||||||
|
|
||||||
if (WebServer->hasArg("scan")) {
|
|
||||||
#ifdef USE_EMULATION
|
|
||||||
UdpDisconnect();
|
|
||||||
#endif // USE_EMULATION
|
|
||||||
int n = WiFi.scanNetworks();
|
|
||||||
AddLog_P(LOG_LEVEL_DEBUG, PSTR(D_LOG_WIFI D_SCAN_DONE));
|
|
||||||
|
|
||||||
if (0 == n) {
|
if(HTTP_MANAGER_RESET_ONLY != webserver_state){
|
||||||
AddLog_P(LOG_LEVEL_DEBUG, S_LOG_WIFI, S_NO_NETWORKS_FOUND);
|
if (WebServer->hasArg("scan")) {
|
||||||
page += FPSTR(S_NO_NETWORKS_FOUND);
|
#ifdef USE_EMULATION
|
||||||
page += F(". " D_REFRESH_TO_SCAN_AGAIN ".");
|
UdpDisconnect();
|
||||||
} else {
|
#endif // USE_EMULATION
|
||||||
//sort networks
|
int n = WiFi.scanNetworks();
|
||||||
int indices[n];
|
AddLog_P(LOG_LEVEL_DEBUG, PSTR(D_LOG_WIFI D_SCAN_DONE));
|
||||||
for (int i = 0; i < n; i++) {
|
|
||||||
indices[i] = i;
|
|
||||||
}
|
|
||||||
|
|
||||||
// RSSI SORT
|
if (0 == n) {
|
||||||
for (int i = 0; i < n; i++) {
|
AddLog_P(LOG_LEVEL_DEBUG, S_LOG_WIFI, S_NO_NETWORKS_FOUND);
|
||||||
for (int j = i + 1; j < n; j++) {
|
page += FPSTR(S_NO_NETWORKS_FOUND);
|
||||||
if (WiFi.RSSI(indices[j]) > WiFi.RSSI(indices[i])) {
|
page += F(". " D_REFRESH_TO_SCAN_AGAIN ".");
|
||||||
std::swap(indices[i], indices[j]);
|
} else {
|
||||||
}
|
//sort networks
|
||||||
}
|
int indices[n];
|
||||||
}
|
for (int i = 0; i < n; i++) {
|
||||||
|
indices[i] = i;
|
||||||
// remove duplicates ( must be RSSI sorted )
|
}
|
||||||
if (remove_duplicate_access_points) {
|
|
||||||
String cssid;
|
// RSSI SORT
|
||||||
for (int i = 0; i < n; i++) {
|
for (int i = 0; i < n; i++) {
|
||||||
if (-1 == indices[i]) { continue; }
|
|
||||||
cssid = WiFi.SSID(indices[i]);
|
|
||||||
for (int j = i + 1; j < n; j++) {
|
for (int j = i + 1; j < n; j++) {
|
||||||
if (cssid == WiFi.SSID(indices[j])) {
|
if (WiFi.RSSI(indices[j]) > WiFi.RSSI(indices[i])) {
|
||||||
snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_WIFI D_DUPLICATE_ACCESSPOINT " %s"), WiFi.SSID(indices[j]).c_str());
|
std::swap(indices[i], indices[j]);
|
||||||
AddLog(LOG_LEVEL_DEBUG);
|
|
||||||
indices[j] = -1; // set dup aps to index -1
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
//display networks in page
|
// remove duplicates ( must be RSSI sorted )
|
||||||
for (int i = 0; i < n; i++) {
|
if (remove_duplicate_access_points) {
|
||||||
if (-1 == indices[i]) { continue; } // skip dups
|
String cssid;
|
||||||
snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_WIFI D_SSID " %s, " D_BSSID " %s, " D_CHANNEL " %d, " D_RSSI " %d"), WiFi.SSID(indices[i]).c_str(), WiFi.BSSIDstr(indices[i]).c_str(), WiFi.channel(indices[i]), WiFi.RSSI(indices[i]));
|
for (int i = 0; i < n; i++) {
|
||||||
AddLog(LOG_LEVEL_DEBUG);
|
if (-1 == indices[i]) { continue; }
|
||||||
int quality = WifiGetRssiAsQuality(WiFi.RSSI(indices[i]));
|
cssid = WiFi.SSID(indices[i]);
|
||||||
|
for (int j = i + 1; j < n; j++) {
|
||||||
if (minimum_signal_quality == -1 || minimum_signal_quality < quality) {
|
if (cssid == WiFi.SSID(indices[j])) {
|
||||||
String item = FPSTR(HTTP_LNK_ITEM);
|
snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_WIFI D_DUPLICATE_ACCESSPOINT " %s"), WiFi.SSID(indices[j]).c_str());
|
||||||
String rssiQ;
|
AddLog(LOG_LEVEL_DEBUG);
|
||||||
rssiQ += quality;
|
indices[j] = -1; // set dup aps to index -1
|
||||||
item.replace(F("{v}"), htmlEscape(WiFi.SSID(indices[i])));
|
}
|
||||||
item.replace(F("{w}"), String(WiFi.channel(indices[i])));
|
}
|
||||||
item.replace(F("{r}"), rssiQ);
|
}
|
||||||
uint8_t auth = WiFi.encryptionType(indices[i]);
|
|
||||||
item.replace(F("{i}"), (ENC_TYPE_WEP == auth) ? F(D_WEP) : (ENC_TYPE_TKIP == auth) ? F(D_WPA_PSK) : (ENC_TYPE_CCMP == auth) ? F(D_WPA2_PSK) : (ENC_TYPE_AUTO == auth) ? F(D_AUTO) : F(""));
|
|
||||||
page += item;
|
|
||||||
delay(0);
|
|
||||||
} else {
|
|
||||||
AddLog_P(LOG_LEVEL_DEBUG, PSTR(D_LOG_WIFI D_SKIPPING_LOW_QUALITY));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
//display networks in page
|
||||||
page += "<br/>";
|
for (int i = 0; i < n; i++) {
|
||||||
}
|
if (-1 == indices[i]) { continue; } // skip dups
|
||||||
} else {
|
snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_WIFI D_SSID " %s, " D_BSSID " %s, " D_CHANNEL " %d, " D_RSSI " %d"), WiFi.SSID(indices[i]).c_str(), WiFi.BSSIDstr(indices[i]).c_str(), WiFi.channel(indices[i]), WiFi.RSSI(indices[i]));
|
||||||
page += FPSTR(HTTP_LNK_SCAN);
|
AddLog(LOG_LEVEL_DEBUG);
|
||||||
}
|
int quality = WifiGetRssiAsQuality(WiFi.RSSI(indices[i]));
|
||||||
|
|
||||||
page += FPSTR(HTTP_FORM_WIFI);
|
if (minimum_signal_quality == -1 || minimum_signal_quality < quality) {
|
||||||
page.replace(F("{h1"), Settings.hostname);
|
String item = FPSTR(HTTP_LNK_ITEM);
|
||||||
page.replace(F("{s1"), Settings.sta_ssid[0]);
|
String rssiQ;
|
||||||
page.replace(F("{s2"), Settings.sta_ssid[1]);
|
rssiQ += quality;
|
||||||
page += FPSTR(HTTP_FORM_END);
|
item.replace(F("{v}"), htmlEscape(WiFi.SSID(indices[i])));
|
||||||
if (HTTP_MANAGER == webserver_state) {
|
item.replace(F("{w}"), String(WiFi.channel(indices[i])));
|
||||||
|
item.replace(F("{r}"), rssiQ);
|
||||||
|
uint8_t auth = WiFi.encryptionType(indices[i]);
|
||||||
|
item.replace(F("{i}"), (ENC_TYPE_WEP == auth) ? F(D_WEP) : (ENC_TYPE_TKIP == auth) ? F(D_WPA_PSK) : (ENC_TYPE_CCMP == auth) ? F(D_WPA2_PSK) : (ENC_TYPE_AUTO == auth) ? F(D_AUTO) : F(""));
|
||||||
|
page += item;
|
||||||
|
delay(0);
|
||||||
|
} else {
|
||||||
|
AddLog_P(LOG_LEVEL_DEBUG, PSTR(D_LOG_WIFI D_SKIPPING_LOW_QUALITY));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
page += "<br/>";
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
page += FPSTR(HTTP_LNK_SCAN);
|
||||||
|
}
|
||||||
|
|
||||||
|
page += FPSTR(HTTP_FORM_WIFI);
|
||||||
|
page.replace(F("{h1"), Settings.hostname);
|
||||||
|
page.replace(F("{s1"), Settings.sta_ssid[0]);
|
||||||
|
page.replace(F("{s2"), Settings.sta_ssid[1]);
|
||||||
|
page += FPSTR(HTTP_FORM_END);
|
||||||
|
}
|
||||||
|
if (WifiIsInManagerMode()) {
|
||||||
page += FPSTR(HTTP_BTN_RSTRT);
|
page += FPSTR(HTTP_BTN_RSTRT);
|
||||||
|
#ifndef FIRMWARE_MINIMAL
|
||||||
|
page += FPSTR(HTTP_BTN_RESET);
|
||||||
|
#endif // FIRMWARE_MINIMAL
|
||||||
} else {
|
} else {
|
||||||
page += FPSTR(HTTP_BTN_CONF);
|
page += FPSTR(HTTP_BTN_CONF);
|
||||||
}
|
}
|
||||||
// ShowPage(page);
|
// ShowPage(page);
|
||||||
ShowPage(page, !(HTTP_MANAGER == webserver_state));
|
ShowPage(page, !(WifiIsInManagerMode()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void WifiSaveSettings(void)
|
void WifiSaveSettings(void)
|
||||||
@ -1475,7 +1496,7 @@ void HandleResetConfiguration(void)
|
|||||||
page += F("<div style='text-align:center;'>" D_CONFIGURATION_RESET "</div>");
|
page += F("<div style='text-align:center;'>" D_CONFIGURATION_RESET "</div>");
|
||||||
page += FPSTR(HTTP_MSG_RSTRT);
|
page += FPSTR(HTTP_MSG_RSTRT);
|
||||||
page += FPSTR(HTTP_BTN_MAIN);
|
page += FPSTR(HTTP_BTN_MAIN);
|
||||||
ShowPage(page);
|
ShowPage(page, HTTP_MANAGER_RESET_ONLY != webserver_state);
|
||||||
|
|
||||||
snprintf_P(svalue, sizeof(svalue), PSTR(D_CMND_RESET " 1"));
|
snprintf_P(svalue, sizeof(svalue), PSTR(D_CMND_RESET " 1"));
|
||||||
ExecuteWebCommand(svalue, SRC_WEBGUI);
|
ExecuteWebCommand(svalue, SRC_WEBGUI);
|
||||||
@ -2089,7 +2110,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. */
|
/* 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)
|
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));
|
AddLog_P(LOG_LEVEL_DEBUG, PSTR(D_LOG_HTTP D_REDIRECTED));
|
||||||
|
|
||||||
WebServer->sendHeader(F("Location"), String("http://") + WebServer->client().localIP().toString(), true);
|
WebServer->sendHeader(F("Location"), String("http://") + WebServer->client().localIP().toString(), true);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user