#include #include "ProjGlobals.h" #include "Web_APConfig.h" static String EncType_str(uint8_t encType) { switch (encType) { case ENC_TYPE_NONE: return "open"; break; case ENC_TYPE_WEP: return "wep"; break; case ENC_TYPE_TKIP: return "wpa psk"; break; case ENC_TYPE_CCMP: return "wpa2 psk"; break; case ENC_TYPE_AUTO: return "wpa wpa2 psk"; break; default: return "unknown"; break; } } void HandleAPScan() { // WiFi.scanNetworks will return the number of networks found Serial.println("Scan ..."); int n = WiFi.scanNetworks(false, true); // blocking call and show hidden. Serial.println("scan done."); if (n == 0) { Serial.println("no networks found"); } else { Serial.print(n); Serial.println(" networks found"); server.sendContent_P("HTTP/1.1 200 OK\r\n"); server.sendContent_P("Content-Type: text/html\r\n"); server.sendContent_P("\r\n"); server.sendContent_P( "\n" "\n" "Grow Controller - Scan\n" "\n" "

Grow Controller - Scan

" ); server.sendContent_P( "
\n" "
\n" " \n" " \n" ); for (int i = 0; i < n; ++i) { // Select, Network #, RSSI, SSID, BSSID, Channel, Hidden String bgcolor = (i & 1) ? "#E0E0E0" : "#FFFFFF"; String record = " \n" + " \n" + " \n" + " \n" + " \n"; record += " \n"; record += " \n"; record += WiFi.isHidden(i) ? " \n" : " \n"; record += " \n"; server.sendContent(record); // Serial.print(i + 1); Serial.print(": "); Serial.print(WiFi.SSID(i)); Serial.print(" ("); Serial.print(WiFi.RSSI(i)); Serial.print(")"); Serial.println((WiFi.encryptionType(i) == ENC_TYPE_NONE) ? " " : "*"); } server.sendContent_P( " \n" " \n" " \n" "
NetRSSISSIDBSSIDEncryptionChannelHidden
" + (i + 1) + "" + WiFi.RSSI(i) + "" + WiFi.SSID(i) + "
" + "
" + WiFi.BSSIDstr(i) + "" + EncType_str(WiFi.encryptionType(i)) + "" + String(WiFi.channel(i)); record += "YesNo
 \n" " \n" " \n" "
\n" "
\n" "
\n" "NAV:  " " Home | " " Config | " " Scan | " " RSSI | " " Current | " " Factory Reset | " " About\n" "
\n" "\n" "\n" ); } } void FactoryReset(bool forceRestart) { Serial.println("Factory Reset Configuration...\n"); wifiConfig.factoryReset(); wifiConfig.save(); if (forceRestart) { Serial.println("Restart in 3 sec ..."); delay(3000); ESP.restart(); } } void HandleAPConfigPage() { String name = wifiConfig.getName(); String ssid = wifiConfig.getSSID(); String pass = wifiConfig.getPassword(); String url = wifiConfig.getURL(); //String ntp = wifiConfig.getNTPServerName(); char _onref[6], _offref[6], _autoOff[6]; snprintf(_onref, sizeof(_onref), "%d", wifiConfig.getOnRef()); snprintf(_offref, sizeof(_offref), "%d", wifiConfig.getOffRef()); snprintf(_autoOff, sizeof(_autoOff), "%d", wifiConfig.getAutoOff()); String onref = String(_onref); String offref = String(_offref); String autooff = String(_autoOff); if (server.hasArg("ssid") && server.hasArg("pass")) { String _ssid = server.hasArg("_ssid") ? server.arg("_ssid") : ""; String _pass = server.hasArg("_pass") ? server.arg("_pass") : ""; name = server.arg("name"); ssid = server.arg("ssid"); pass = server.arg("pass"); url = server.hasArg("url") ? server.arg("url") : ""; onref = server.hasArg("onref") ? server.arg("onref") : ""; offref = server.hasArg("offref") ? server.arg("offref") : ""; autooff = server.hasArg("autooff") ? server.arg("autooff") : ""; //ntp = server.hasArg("ntp") ? server.arg("ntp") : ""; if (ssid == "reset" && pass == "reset") { FactoryReset(true); } wifiConfig.setName(name); wifiConfig.setSSID(ssid); wifiConfig.setPassword(pass); wifiConfig.setURL(url); wifiConfig.setOnRef(onref.toInt()); wifiConfig.setOffRef(offref.toInt()); wifiConfig.setAutoOff(autooff.toInt()); //wifiConfig.setNTPServerName(ntp); wifiConfig.save(); Serial.println("Settings saved."); if (ssid != _ssid || pass != _pass) { // They changed stuff that requires a restart. server.send(200, "text/html", "Configuration Saved! Restarting in 3 sec..."); Serial.printf("Config saved. Restarting in 3 sec . . ."); delay(3000); ESP.restart(); return; } } String modeText = (isStationMode) ? "Station mode
" : "Access Point mode
"; if (server.hasArg("ssid") && !server.hasArg("pass")) { ssid = server.arg("ssid"); pass = ""; Serial.println("ssid: " + ssid + ", pass: " + pass); } if (server.hasArg("url")) url = server.arg("url"); //if (server.hasArg("ntp")) // ntp = server.arg("ntp"); server.send(200, "text/html", "\n" "\n" "Grow Controller - Config\n" "\n" "

Grow Controller - Configuration

" "
\n" "
\n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" // " \n" // " \n" // " \n" // " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" "
Node Name
SSID **\n" "
Password **\n" "
Update URL
NTP Server
Auto-Off (time in seconds when non-zero)
On Reference (sense above this indicates power is on)
Off Reference (sense below this indicates power is off)
 \n" " \n" " ** Changes to these will trigger a module restart.\n" "

 Check for SW update (module will restart if updated)
\n" "
\n" "
\n" "NAV:  " " Home | " " Config | " " Scan | " " RSSI | " " Current | " " Factory Reset | " " About\n" "
\n" "\n" "\n" ); }