This is out captive portal front page.
"); - response->printf("You were trying to reach: http://%s%s
", request->host().c_str(), request->url().c_str()); - response->printf("Try opening this link instead
", WiFi.softAPIP().toString().c_str()); - response->print(""); - request->send(response); - } + void handleRequest(AsyncWebServerRequest* request) { + AsyncResponseStream* response = request->beginResponseStream("text/html"); + response->print("This is out captive portal front page.
"); + response->printf("You were trying to reach: http://%s%s
", request->host().c_str(), request->url().c_str()); + response->printf("Try opening this link instead
", WiFi.softAPIP().toString().c_str()); + response->print(""); + request->send(response); + } }; - -void setup(){ - //your other setup stuff... +void setup() { + // your other setup stuff... WiFi.softAP("esp-captive"); dnsServer.start(53, "*", WiFi.softAPIP()); - server.addHandler(new CaptiveRequestHandler()).setFilter(ON_AP_FILTER);//only when requested from AP - //more handlers... + server.addHandler(new CaptiveRequestHandler()).setFilter(ON_AP_FILTER); // only when requested from AP + // more handlers... server.begin(); } -void loop(){ +void loop() { dnsServer.processNextRequest(); -} +} \ No newline at end of file diff --git a/examples/ESP_AsyncFSBrowser/ESP_AsyncFSBrowser.ino b/examples/ESP_AsyncFSBrowser/ESP_AsyncFSBrowser.ino deleted file mode 100644 index 3381b9f..0000000 --- a/examples/ESP_AsyncFSBrowser/ESP_AsyncFSBrowser.ino +++ /dev/null @@ -1,257 +0,0 @@ -// Defaulut is SPIFFS, FatFS: only on ESP32, also choose partition scheme w/ ffat. -// Comment 2 lines below or uncomment only one of them - -//#define USE_LittleFS -//#define USE_FatFS // Only ESP32 - -#includeThis is out captive portal front page.
"); + response->printf("You were trying to reach: http://%s%s
", request->host().c_str(), request->url().c_str()); + response->printf("Try opening this link instead
", WiFi.softAPIP().toString().c_str()); + response->print(""); + request->send(response); + } +}; + +void setup() { + // your other setup stuff... + WiFi.softAP("esp-captive"); + dnsServer.start(53, "*", WiFi.softAPIP()); + server.addHandler(new CaptiveRequestHandler()).setFilter(ON_AP_FILTER); // only when requested from AP + // more handlers... + server.begin(); +} + +void loop() { + dnsServer.processNextRequest(); +} \ No newline at end of file diff --git a/examples/SmartSwitch/1.PNG b/examples/SmartSwitch/1.PNG deleted file mode 100644 index 3c95d81..0000000 Binary files a/examples/SmartSwitch/1.PNG and /dev/null differ diff --git a/examples/SmartSwitch/2.PNG b/examples/SmartSwitch/2.PNG deleted file mode 100644 index 6c02cab..0000000 Binary files a/examples/SmartSwitch/2.PNG and /dev/null differ diff --git a/examples/SmartSwitch/3.PNG b/examples/SmartSwitch/3.PNG deleted file mode 100644 index 258c51c..0000000 Binary files a/examples/SmartSwitch/3.PNG and /dev/null differ diff --git a/examples/SmartSwitch/4.PNG b/examples/SmartSwitch/4.PNG deleted file mode 100644 index 56947d5..0000000 Binary files a/examples/SmartSwitch/4.PNG and /dev/null differ diff --git a/examples/SmartSwitch/ESPAsyncWiFiManager.cpp b/examples/SmartSwitch/ESPAsyncWiFiManager.cpp deleted file mode 100644 index 4455258..0000000 --- a/examples/SmartSwitch/ESPAsyncWiFiManager.cpp +++ /dev/null @@ -1,1177 +0,0 @@ -/************************************************************** - AsyncWiFiManager is a library for the ESP8266/Arduino platform - (https://github.com/esp8266/Arduino) to enable easy - configuration and reconfiguration of WiFi credentials using a Captive Portal - inspired by: - http://www.esp8266.com/viewtopic.php?f=29&t=2520 - https://github.com/chriscook8/esp-arduino-apboot - https://github.com/esp8266/Arduino/tree/esp8266/hardware/esp8266com/esp8266/libraries/DNSServer/examples/CaptivePortalAdvanced - Built by AlexT https://github.com/tzapu - Ported to Async Web Server by https://github.com/alanswx - Licensed under MIT license - **************************************************************/ - -#include "ESPAsyncWiFiManager.h" - -AsyncWiFiManagerParameter::AsyncWiFiManagerParameter(const char *custom) { - _id = NULL; - _placeholder = NULL; - _length = 0; - _value = NULL; - - _customHTML = custom; -} - -AsyncWiFiManagerParameter::AsyncWiFiManagerParameter(const char *id, const char *placeholder, const char *defaultValue, int length) { - init(id, placeholder, defaultValue, length, ""); -} - -AsyncWiFiManagerParameter::AsyncWiFiManagerParameter(const char *id, const char *placeholder, const char *defaultValue, int length, const char *custom) { - init(id, placeholder, defaultValue, length, custom); -} - -void AsyncWiFiManagerParameter::init(const char *id, const char *placeholder, const char *defaultValue, int length, const char *custom) { - _id = id; - _placeholder = placeholder; - _length = length; - _value = new char[length + 1]; - for (int i = 0; i < length; i++) { - _value[i] = 0; - } - if (defaultValue != NULL) { - strncpy(_value, defaultValue, length); - } - - _customHTML = custom; -} - -const char* AsyncWiFiManagerParameter::getValue() { - return _value; -} -const char* AsyncWiFiManagerParameter::getID() { - return _id; -} -const char* AsyncWiFiManagerParameter::getPlaceholder() { - return _placeholder; -} -int AsyncWiFiManagerParameter::getValueLength() { - return _length; -} -const char* AsyncWiFiManagerParameter::getCustomHTML() { - return _customHTML; -} - -#ifdef USE_EADNS -AsyncWiFiManager::AsyncWiFiManager(AsyncWebServer *server, AsyncDNSServer *dns) :server(server), dnsServer(dns) { -#else -AsyncWiFiManager::AsyncWiFiManager(AsyncWebServer *server, DNSServer *dns) :server(server), dnsServer(dns) { -#endif - wifiSSIDs = NULL; - wifiSSIDscan=true; - _modeless=false; - shouldscan=true; -} - -void AsyncWiFiManager::addParameter(AsyncWiFiManagerParameter *p) { - _params[_paramsCount] = p; - _paramsCount++; - DEBUG_WM("Adding parameter"); - DEBUG_WM(p->getID()); -} - -void AsyncWiFiManager::setupConfigPortal() { - // dnsServer.reset(new DNSServer()); - // server.reset(new ESP8266WebServer(80)); - server->reset(); - - DEBUG_WM(F("")); - _configPortalStart = millis(); - - DEBUG_WM(F("Configuring access point... ")); - DEBUG_WM(_apName); - if (_apPassword != NULL) { - if (strlen(_apPassword) < 8 || strlen(_apPassword) > 63) { - // fail passphrase to short or long! - DEBUG_WM(F("Invalid AccessPoint password. Ignoring")); - _apPassword = NULL; - } - DEBUG_WM(_apPassword); - } - - //optional soft ip config - if (_ap_static_ip) { - DEBUG_WM(F("Custom AP IP/GW/Subnet")); - WiFi.softAPConfig(_ap_static_ip, _ap_static_gw, _ap_static_sn); - } - - if (_apPassword != NULL) { - WiFi.softAP(_apName, _apPassword);//password option - } else { - WiFi.softAP(_apName); - } - - delay(500); // Without delay I've seen the IP address blank - DEBUG_WM(F("AP IP address: ")); - DEBUG_WM(WiFi.softAPIP()); - - /* Setup the DNS server redirecting all the domains to the apIP */ - #ifdef USE_EADNS - dnsServer->setErrorReplyCode(AsyncDNSReplyCode::NoError); - #else - dnsServer->setErrorReplyCode(DNSReplyCode::NoError); - #endif - dnsServer->start(DNS_PORT, "*", WiFi.softAPIP()); - - setInfo(); - - /* Setup web pages: root, wifi config pages, SO captive portal detectors and not found. */ - server->on("/", std::bind(&AsyncWiFiManager::handleRoot, this,std::placeholders::_1)).setFilter(ON_AP_FILTER); - server->on("/wifi", std::bind(&AsyncWiFiManager::handleWifi, this, std::placeholders::_1,true)).setFilter(ON_AP_FILTER); - server->on("/0wifi", std::bind(&AsyncWiFiManager::handleWifi, this,std::placeholders::_1, false)).setFilter(ON_AP_FILTER); - server->on("/wifisave", std::bind(&AsyncWiFiManager::handleWifiSave,this,std::placeholders::_1)).setFilter(ON_AP_FILTER); - server->on("/i", std::bind(&AsyncWiFiManager::handleInfo,this, std::placeholders::_1)).setFilter(ON_AP_FILTER); - server->on("/r", std::bind(&AsyncWiFiManager::handleReset, this,std::placeholders::_1)).setFilter(ON_AP_FILTER); - //server->on("/generate_204", std::bind(&AsyncWiFiManager::handle204, this)); //Android/Chrome OS captive portal check. - server->on("/fwlink", std::bind(&AsyncWiFiManager::handleRoot, this,std::placeholders::_1)).setFilter(ON_AP_FILTER); //Microsoft captive portal. Maybe not needed. Might be handled by notFound handler. - server->onNotFound (std::bind(&AsyncWiFiManager::handleNotFound,this,std::placeholders::_1)); - server->begin(); // Web server start - DEBUG_WM(F("HTTP server started")); - -} - -static const char HEX_CHAR_ARRAY[17] = "0123456789ABCDEF"; -/** -* convert char array (hex values) to readable string by seperator -* buf: buffer to convert -* length: data length -* strSeperator seperator between each hex value -* return: formated value as String -*/ -static String byteToHexString(uint8_t* buf, uint8_t length, String strSeperator="-") { - String dataString = ""; - for (uint8_t i = 0; i < length; i++) { - byte v = buf[i] / 16; - byte w = buf[i] % 16; - if (i>0) { - dataString += strSeperator; - } - dataString += String(HEX_CHAR_ARRAY[v]); - dataString += String(HEX_CHAR_ARRAY[w]); - } - dataString.toUpperCase(); - return dataString; -} // byteToHexString - -#if !defined(ESP8266) -String getESP32ChipID() { - uint64_t chipid; - chipid=ESP.getEfuseMac();//The chip ID is essentially its MAC address(length: 6 bytes). - int chipid_size = 6; - uint8_t chipid_arr[chipid_size]; - for (uint8_t i=0; i < chipid_size; i++) { - chipid_arr[i] = (chipid >> (8 * i)) & 0xff; - } - return byteToHexString(chipid_arr, chipid_size, ""); -} -#endif - -boolean AsyncWiFiManager::autoConnect(unsigned long maxConnectRetries, unsigned long retryDelayMs) { - String ssid = "ESP"; - #if defined(ESP8266) - ssid += String(ESP.getChipId()); - #else - ssid += getESP32ChipID(); - #endif - return autoConnect(ssid.c_str(), NULL); -} - -boolean AsyncWiFiManager::autoConnect(char const *apName, char const *apPassword, unsigned long maxConnectRetries, unsigned long retryDelayMs) { - DEBUG_WM(F("")); - - // read eeprom for ssid and pass - //String ssid = getSSID(); - //String pass = getPassword(); - - // attempt to connect; should it fail, fall back to AP - WiFi.mode(WIFI_STA); - - for(unsigned long tryNumber = 0; tryNumber < maxConnectRetries; tryNumber++) { - DEBUG_WM(F("AutoConnect Try No.:")); - DEBUG_WM(tryNumber); - - if (connectWifi("", "") == WL_CONNECTED) { - DEBUG_WM(F("IP Address:")); - DEBUG_WM(WiFi.localIP()); - //connected - return true; - } - - if(tryNumber + 1 < maxConnectRetries) { - - // we might connect during the delay - unsigned long restDelayMs = retryDelayMs; - while(restDelayMs != 0) { - if(WiFi.status() == WL_CONNECTED) { - DEBUG_WM(F("IP Address (connected during delay):")); - DEBUG_WM(WiFi.localIP()); - return true; - } - unsigned long thisDelay = std::min(restDelayMs, 100ul); - delay(thisDelay); - restDelayMs -= thisDelay; - } - - } - } - - - return startConfigPortal(apName, apPassword); -} - - -String AsyncWiFiManager::networkListAsString() -{ - String pager ; - //display networks in page - for (int i = 0; i < wifiSSIDCount; i++) { - if (wifiSSIDs[i].duplicate == true) continue; // skip dups - int quality = getRSSIasQuality(wifiSSIDs[i].RSSI); - - if (_minimumQuality == -1 || _minimumQuality < quality) { - String item = FPSTR(HTTP_ITEM); - String rssiQ; - rssiQ += quality; - item.replace("{v}", wifiSSIDs[i].SSID); - item.replace("{r}", rssiQ); -#if defined(ESP8266) - if (wifiSSIDs[i].encryptionType != ENC_TYPE_NONE) { -#else - if (wifiSSIDs[i].encryptionType != WIFI_AUTH_OPEN) { -#endif - item.replace("{i}", "l"); - } else { - item.replace("{i}", ""); - } - pager += item; - - } else { - DEBUG_WM(F("Skipping due to quality")); - } - - } - return pager; -} - -String AsyncWiFiManager::scanModal() -{ - shouldscan=true; - scan(); - String pager=networkListAsString(); - return pager; -} - -void AsyncWiFiManager::scan() -{ - if (!shouldscan) return; - DEBUG_WM(F("About to scan()")); - if (wifiSSIDscan) - { - delay(100); - } - - if (wifiSSIDscan) - { - wifi_ssid_count_t n = WiFi.scanNetworks(); - DEBUG_WM(F("Scan done")); - if(n == WIFI_SCAN_FAILED) { - DEBUG_WM(F("scanNetworks returned: WIFI_SCAN_FAILED!")); - } else if(n == WIFI_SCAN_RUNNING) { - DEBUG_WM(F("scanNetworks returned: WIFI_SCAN_RUNNING!")); - } else if(n < 0) { - DEBUG_WM(F("scanNetworks failed with unknown error code!")); - } else if (n == 0) { - DEBUG_WM(F("No networks found")); - // page += F("No networks found. Refresh to scan again."); - } else { - - - if (wifiSSIDscan) - { - /* WE SHOULD MOVE THIS IN PLACE ATOMICALLY */ - if (wifiSSIDs) delete [] wifiSSIDs; - wifiSSIDs = new WiFiResult[n]; - wifiSSIDCount = n; - - if (n>0) - shouldscan=false; - - for (wifi_ssid_count_t i=0;i- - | -||
- - - | -- - - | -- - - | -
- - | -- - | -- - | -
-
-
-
- |
- - |
-
-
-
- |
-
- - | -- - | -- - | -
- |