From 8f38a0fbaf2ff42461dde8f57399871497561e26 Mon Sep 17 00:00:00 2001 From: Alex Tudorache Date: Tue, 10 Nov 2015 08:20:53 +0200 Subject: [PATCH] added no scan option --- WiFiManager.cpp | 42 ++++++++++++++++++++++++------------------ WiFiManager.h | 2 +- 2 files changed, 25 insertions(+), 19 deletions(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index 89edd56..8225cb5 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -45,7 +45,8 @@ void WiFiManager::begin(char const *apName) { /* Setup web pages: root, wifi config pages, SO captive portal detectors and not found. */ server.on("/", std::bind(&WiFiManager::handleRoot, this)); - server.on("/wifi", std::bind(&WiFiManager::handleWifi, this)); + server.on("/wifi", std::bind(&WiFiManager::handleWifi, this, true)); + server.on("/0wifi", std::bind(&WiFiManager::handleWifi, this, false)); server.on("/wifisave", std::bind(&WiFiManager::handleWifiSave, this)); server.on("/generate_204", std::bind(&WiFiManager::handle204, this)); //Android/Chrome OS captive portal check. server.on("/fwlink", std::bind(&WiFiManager::handleRoot, this)); //Microsoft captive portal. Maybe not needed. Might be handled by notFound handler. @@ -272,6 +273,9 @@ void WiFiManager::handleRoot() { server.sendContent( "
" ); + server.sendContent( + "
" + ); server.sendContent(HTTP_END); @@ -279,7 +283,7 @@ void WiFiManager::handleRoot() { } /** Wifi config page handler */ -void WiFiManager::handleWifi() { +void WiFiManager::handleWifi(bool scan) { server.sendHeader("Cache-Control", "no-cache, no-store, must-revalidate"); server.sendHeader("Pragma", "no-cache"); server.sendHeader("Expires", "-1"); @@ -293,24 +297,26 @@ void WiFiManager::handleWifi() { server.sendContent(HTTP_STYLE); server.sendContent(HTTP_HEAD_END); - int n = WiFi.scanNetworks(); - DEBUG_PRINT("Scan done"); - if (n == 0) { - DEBUG_PRINT("No networks found"); - server.sendContent("
No networks found. Refresh to scan again.
"); - } - else { - for (int i = 0; i < n; ++i) - { - DEBUG_PRINT(WiFi.SSID(i)); - DEBUG_PRINT(WiFi.RSSI(i)); - String item = HTTP_ITEM; - item.replace("{v}", WiFi.SSID(i)); - server.sendContent(item); - yield(); + if (scan) { + int n = WiFi.scanNetworks(); + DEBUG_PRINT("Scan done"); + if (n == 0) { + DEBUG_PRINT("No networks found"); + server.sendContent("
No networks found. Refresh to scan again.
"); + } + else { + for (int i = 0; i < n; ++i) + { + DEBUG_PRINT(WiFi.SSID(i)); + DEBUG_PRINT(WiFi.RSSI(i)); + String item = HTTP_ITEM; + item.replace("{v}", WiFi.SSID(i)); + server.sendContent(item); + yield(); + } } } - + server.sendContent(HTTP_FORM); server.sendContent(HTTP_END); server.client().stop(); diff --git a/WiFiManager.h b/WiFiManager.h index e2dbb0d..57028d3 100644 --- a/WiFiManager.h +++ b/WiFiManager.h @@ -89,7 +89,7 @@ private: void connectWifi(String ssid, String pass); void handleRoot(); - void handleWifi(); + void handleWifi(bool scan); void handleWifiSave(); void handleNotFound(); void handle204();