2#ifdef USE_CAPTIVE_PORTAL
9namespace captive_portal {
11static const char *
const TAG =
"captive_portal";
14 AsyncResponseStream *stream = request->beginResponseStream(F(
"application/json"));
15 stream->addHeader(F(
"cache-control"), F(
"public, max-age=0, must-revalidate"));
17 stream->print(F(
"{\"mac\":\""));
19 stream->print(F(
"\",\"name\":\""));
21 stream->print(F(
"\",\"aps\":[{}"));
27 if (scan.get_is_hidden())
32 stream->print(F(
",{\"ssid\":\""));
33 stream->print(scan.get_ssid().c_str());
34 stream->print(F(
"\",\"rssi\":"));
35 stream->print(scan.get_rssi());
36 stream->print(F(
",\"lock\":"));
37 stream->print(scan.get_with_auth());
38 stream->print(F(
"}"));
40 stream->printf(R
"(,{"ssid":"%s","rssi":%d,"lock":%d})", scan.get_ssid().c_str(), scan.get_rssi(),
41 scan.get_with_auth());
44 stream->print(F(
"]}"));
45 request->send(stream);
48 std::string ssid = request->arg(
"ssid").c_str();
49 std::string psk = request->arg(
"psk").c_str();
50 ESP_LOGI(TAG,
"Requested WiFi Settings Change:");
51 ESP_LOGI(TAG,
" SSID='%s'", ssid.c_str());
52 ESP_LOGI(TAG,
" Password=" LOG_SECRET(
"'%s'"), psk.c_str());
55 request->redirect(F(
"/?save"));
72 this->
dns_server_->setErrorReplyCode(DNSReplyCode::NoError);
79 this->
base_->
get_server()->onNotFound([
this](AsyncWebServerRequest *req) {
81 req->send(404, F(
"text/html"), F(
"File not found"));
86 String url = F(
"http://");
91 req->redirect(url.c_str());
99 if (req->url() == F(
"/")) {
101 auto *response = req->beginResponse(200, F(
"text/html"), INDEX_GZ,
sizeof(INDEX_GZ));
103 auto *response = req->beginResponse_P(200, F(
"text/html"), INDEX_GZ,
sizeof(INDEX_GZ));
105 response->addHeader(F(
"Content-Encoding"), F(
"gzip"));
108 }
else if (req->url() == F(
"/config.json")) {
111 }
else if (req->url() == F(
"/wifisave")) {
const std::string & get_name() const
Get the name of this Application set by pre_setup().
void enable_loop()
Enable this component's loop.
void disable_loop()
Disable this component's loop.
float get_setup_priority() const override
std::unique_ptr< DNSServer > dns_server_
void dump_config() override
CaptivePortal(web_server_base::WebServerBase *base)
void handle_config(AsyncWebServerRequest *request)
web_server_base::WebServerBase * base_
void handleRequest(AsyncWebServerRequest *req) override
void handle_wifisave(AsyncWebServerRequest *request)
std::shared_ptr< AsyncWebServer > get_server() const
void add_handler(AsyncWebHandler *handler)
void save_wifi_sta(const std::string &ssid, const std::string &password)
network::IPAddress wifi_soft_ap_ip()
CaptivePortal * global_captive_portal
WiFiComponent * global_wifi_component
Providing packet encoding functions for exchanging data with a remote host.
std::string get_mac_address_pretty()
Get the device MAC address as a string, in colon-separated uppercase hex notation.
Application App
Global storage of Application pointer - only one Application can exist.