2 #ifdef USE_CAPTIVE_PORTAL 9 namespace captive_portal {
11 static const char *
const TAG =
"captive_portal";
14 AsyncResponseStream *stream = request->beginResponseStream(
"application/json");
15 stream->addHeader(
"cache-control",
"public, max-age=0, must-revalidate");
19 if (scan.get_is_hidden())
23 stream->printf(R
"(,{"ssid":"%s","rssi":%d,"lock":%d})", scan.get_ssid().c_str(), scan.get_rssi(), 24 scan.get_with_auth()); 26 stream->print(F("]}"));
27 request->send(stream);
30 std::string ssid = request->arg(
"ssid").c_str();
31 std::string psk = request->arg(
"psk").c_str();
32 ESP_LOGI(TAG,
"Captive Portal Requested WiFi Settings Change:");
33 ESP_LOGI(TAG,
" SSID='%s'", ssid.c_str());
34 ESP_LOGI(TAG,
" Password=" LOG_SECRET(
"'%s'"), psk.c_str());
37 request->redirect(
"/?save");
50 this->
dns_server_->setErrorReplyCode(DNSReplyCode::NoError);
55 this->
base_->
get_server()->onNotFound([
this](AsyncWebServerRequest *req) {
57 req->send(404,
"text/html",
"File not found");
62 req->redirect(url.c_str());
70 if (req->url() ==
"/") {
71 auto *response = req->beginResponse_P(200,
"text/html", INDEX_GZ,
sizeof(INDEX_GZ));
72 response->addHeader(
"Content-Encoding",
"gzip");
75 }
else if (req->url() ==
"/config.json") {
78 }
else if (req->url() ==
"/wifisave") {
CaptivePortal(web_server_base::WebServerBase *base)
std::unique_ptr< DNSServer > dns_server_
void handleRequest(AsyncWebServerRequest *req) override
void save_wifi_sta(const std::string &ssid, const std::string &password)
web_server_base::WebServerBase * base_
CaptivePortal * global_captive_portal
void add_handler(AsyncWebHandler *handler)
void handle_config(AsyncWebServerRequest *request)
void dump_config() override
Application App
Global storage of Application pointer - only one Application can exist.
WiFiComponent * global_wifi_component
const std::string & get_name() const
Get the name of this Application set by pre_setup().
network::IPAddress wifi_soft_ap_ip()
Implementation of SPI Controller mode.
std::shared_ptr< AsyncWebServer > get_server() const
std::string get_mac_address_pretty()
Get the device MAC address as a string, in colon-separated uppercase hex notation.
float get_setup_priority() const override
void handle_wifisave(AsyncWebServerRequest *request)