Update na verzi 3.7.2. POZOR: vyzaduje do platformio.ini doplnit lib_compat_mode = strict

This commit is contained in:
2025-03-06 07:56:54 +01:00
parent d55bb23fef
commit b12c714d5e
92 changed files with 7585 additions and 6187 deletions

View File

@ -1,38 +1,43 @@
// Reproduced issue https://github.com/ESP32Async/ESPAsyncWebServer/issues/26
// SPDX-License-Identifier: LGPL-3.0-or-later
// Copyright 2016-2025 Hristo Gochkov, Mathieu Carbou, Emil Muratov
//
// Shows how to use setFilter to route requests to different handlers based on WiFi mode
//
#include <DNSServer.h>
#ifdef ESP32
#include <AsyncTCP.h>
#include <WiFi.h>
#include <AsyncTCP.h>
#include <WiFi.h>
#elif defined(ESP8266)
#include <ESP8266WiFi.h>
#include <ESPAsyncTCP.h>
#elif defined(TARGET_RP2040)
#include <WebServer.h>
#include <WiFi.h>
#include <ESP8266WiFi.h>
#include <ESPAsyncTCP.h>
#elif defined(TARGET_RP2040) || defined(TARGET_RP2350) || defined(PICO_RP2040) || defined(PICO_RP2350)
#include <RPAsyncTCP.h>
#include <WiFi.h>
#endif
#include "ESPAsyncWebServer.h"
DNSServer dnsServer;
AsyncWebServer server(80);
static DNSServer dnsServer;
static AsyncWebServer server(80);
class CaptiveRequestHandler : public AsyncWebHandler {
public:
bool canHandle(__unused AsyncWebServerRequest* request) const override {
return true;
}
public:
bool canHandle(__unused AsyncWebServerRequest *request) const override {
return true;
}
void handleRequest(AsyncWebServerRequest* request) override {
AsyncResponseStream* response = request->beginResponseStream("text/html");
response->print("<!DOCTYPE html><html><head><title>Captive Portal</title></head><body>");
response->print("<p>This is out captive portal front page.</p>");
response->printf("<p>You were trying to reach: http://%s%s</p>", request->host().c_str(), request->url().c_str());
void handleRequest(AsyncWebServerRequest *request) override {
AsyncResponseStream *response = request->beginResponseStream("text/html");
response->print("<!DOCTYPE html><html><head><title>Captive Portal</title></head><body>");
response->print("<p>This is out captive portal front page.</p>");
response->printf("<p>You were trying to reach: http://%s%s</p>", request->host().c_str(), request->url().c_str());
#ifndef CONFIG_IDF_TARGET_ESP32H2
response->printf("<p>Try opening <a href='http://%s'>this link</a> instead</p>", WiFi.softAPIP().toString().c_str());
response->printf("<p>Try opening <a href='http://%s'>this link</a> instead</p>", WiFi.softAPIP().toString().c_str());
#endif
response->print("</body></html>");
request->send(response);
}
response->print("</body></html>");
request->send(response);
}
};
bool hit1 = false;
@ -42,49 +47,55 @@ void setup() {
Serial.begin(115200);
server
.on("/", HTTP_GET, [](AsyncWebServerRequest* request) {
Serial.println("Captive portal request...");
.on(
"/", HTTP_GET,
[](AsyncWebServerRequest *request) {
Serial.println("Captive portal request...");
#ifndef CONFIG_IDF_TARGET_ESP32H2
Serial.println("WiFi.localIP(): " + WiFi.localIP().toString());
Serial.println("WiFi.localIP(): " + WiFi.localIP().toString());
#endif
Serial.println("request->client()->localIP(): " + request->client()->localIP().toString());
Serial.println("request->client()->localIP(): " + request->client()->localIP().toString());
#if ESP_IDF_VERSION_MAJOR >= 5
#ifndef CONFIG_IDF_TARGET_ESP32H2
Serial.println("WiFi.type(): " + String((int)WiFi.localIP().type()));
#endif
Serial.println("request->client()->type(): " + String((int)request->client()->localIP().type()));
#ifndef CONFIG_IDF_TARGET_ESP32H2
Serial.println("WiFi.type(): " + String((int)WiFi.localIP().type()));
#endif
Serial.println("request->client()->type(): " + String((int)request->client()->localIP().type()));
#endif
#ifndef CONFIG_IDF_TARGET_ESP32H2
Serial.println(WiFi.localIP() == request->client()->localIP() ? "should be: ON_STA_FILTER" : "should be: ON_AP_FILTER");
Serial.println(WiFi.localIP() == request->client()->localIP());
Serial.println(WiFi.localIP().toString() == request->client()->localIP().toString());
Serial.println(WiFi.localIP() == request->client()->localIP() ? "should be: ON_STA_FILTER" : "should be: ON_AP_FILTER");
Serial.println(WiFi.localIP() == request->client()->localIP());
Serial.println(WiFi.localIP().toString() == request->client()->localIP().toString());
#endif
request->send(200, "text/plain", "This is the captive portal");
hit1 = true;
})
request->send(200, "text/plain", "This is the captive portal");
hit1 = true;
}
)
.setFilter(ON_AP_FILTER);
server
.on("/", HTTP_GET, [](AsyncWebServerRequest* request) {
Serial.println("Website request...");
.on(
"/", HTTP_GET,
[](AsyncWebServerRequest *request) {
Serial.println("Website request...");
#ifndef CONFIG_IDF_TARGET_ESP32H2
Serial.println("WiFi.localIP(): " + WiFi.localIP().toString());
Serial.println("WiFi.localIP(): " + WiFi.localIP().toString());
#endif
Serial.println("request->client()->localIP(): " + request->client()->localIP().toString());
Serial.println("request->client()->localIP(): " + request->client()->localIP().toString());
#if ESP_IDF_VERSION_MAJOR >= 5
#ifndef CONFIG_IDF_TARGET_ESP32H2
Serial.println("WiFi.type(): " + String((int)WiFi.localIP().type()));
#endif
Serial.println("request->client()->type(): " + String((int)request->client()->localIP().type()));
#ifndef CONFIG_IDF_TARGET_ESP32H2
Serial.println("WiFi.type(): " + String((int)WiFi.localIP().type()));
#endif
Serial.println("request->client()->type(): " + String((int)request->client()->localIP().type()));
#endif
#ifndef CONFIG_IDF_TARGET_ESP32H2
Serial.println(WiFi.localIP() == request->client()->localIP() ? "should be: ON_STA_FILTER" : "should be: ON_AP_FILTER");
Serial.println(WiFi.localIP() == request->client()->localIP());
Serial.println(WiFi.localIP().toString() == request->client()->localIP().toString());
Serial.println(WiFi.localIP() == request->client()->localIP() ? "should be: ON_STA_FILTER" : "should be: ON_AP_FILTER");
Serial.println(WiFi.localIP() == request->client()->localIP());
Serial.println(WiFi.localIP().toString() == request->client()->localIP().toString());
#endif
request->send(200, "text/plain", "This is the website");
hit2 = true;
})
request->send(200, "text/plain", "This is the website");
hit2 = true;
}
)
.setFilter(ON_STA_FILTER);
// assert(WiFi.softAP("esp-captive-portal"));
@ -121,4 +132,5 @@ void setup() {
}
void loop() {
delay(100);
}