diff --git a/examples/CaptivePortal/CaptivePortal.ino b/examples/CaptivePortal/CaptivePortal.ino index 2d0de89..2cc5851 100644 --- a/examples/CaptivePortal/CaptivePortal.ino +++ b/examples/CaptivePortal/CaptivePortal.ino @@ -29,7 +29,9 @@ class CaptiveRequestHandler : public AsyncWebHandler { response->print("Captive Portal"); 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()); +#ifndef CONFIG_IDF_TARGET_ESP32H2 response->printf("

Try opening this link instead

", WiFi.softAPIP().toString().c_str()); +#endif response->print(""); request->send(response); } @@ -40,6 +42,7 @@ void setup() { Serial.println(); Serial.println("Configuring access point..."); +#ifndef CONFIG_IDF_TARGET_ESP32H2 if (!WiFi.softAP("esp-captive")) { Serial.println("Soft AP creation failed."); while (1) @@ -47,6 +50,8 @@ void setup() { } dnsServer.start(53, "*", WiFi.softAPIP()); +#endif + server.addHandler(new CaptiveRequestHandler()).setFilter(ON_AP_FILTER); // only when requested from AP // more handlers... server.begin(); diff --git a/examples/Filters/Filters.ino b/examples/Filters/Filters.ino index f031a1f..b7bbcff 100644 --- a/examples/Filters/Filters.ino +++ b/examples/Filters/Filters.ino @@ -31,7 +31,9 @@ class CaptiveRequestHandler : public AsyncWebHandler { response->print("Captive Portal"); 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()); +#ifndef CONFIG_IDF_TARGET_ESP32H2 response->printf("

Try opening this link instead

", WiFi.softAPIP().toString().c_str()); +#endif response->print(""); request->send(response); } @@ -46,15 +48,21 @@ void setup() { server .on("/", HTTP_GET, [](AsyncWebServerRequest* request) { Serial.println("Captive portal request..."); +#ifndef CONFIG_IDF_TARGET_ESP32H2 Serial.println("WiFi.localIP(): " + WiFi.localIP().toString()); +#endif 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())); #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()); +#endif request->send(200, "text/plain", "This is the captive portal"); hit1 = true; }) @@ -63,15 +71,21 @@ void setup() { server .on("/", HTTP_GET, [](AsyncWebServerRequest* request) { Serial.println("Website request..."); +#ifndef CONFIG_IDF_TARGET_ESP32H2 Serial.println("WiFi.localIP(): " + WiFi.localIP().toString()); +#endif 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())); #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()); +#endif request->send(200, "text/plain", "This is the website"); hit2 = true; }) @@ -92,12 +106,15 @@ void setup() { // dnsServer.stop(); // WiFi.softAPdisconnect(); +#ifndef CONFIG_IDF_TARGET_ESP32H2 WiFi.persistent(false); WiFi.begin("IoT"); while (WiFi.status() != WL_CONNECTED) { delay(500); } Serial.println("Connected to WiFi with IP address: " + WiFi.localIP().toString()); +#endif + server.begin(); // while (!hit2) { diff --git a/examples/SimpleServer/SimpleServer.ino b/examples/SimpleServer/SimpleServer.ino index f3a1605..081541c 100644 --- a/examples/SimpleServer/SimpleServer.ino +++ b/examples/SimpleServer/SimpleServer.ino @@ -38,6 +38,7 @@ void setup() { Serial.begin(115200); +#ifndef CONFIG_IDF_TARGET_ESP32H2 // WiFi.mode(WIFI_STA); // WiFi.begin("YOUR_SSID", "YOUR_PASSWORD"); // if (WiFi.waitForConnectResult() != WL_CONNECTED) { @@ -49,6 +50,7 @@ void setup() { WiFi.mode(WIFI_AP); WiFi.softAP("esp-captive"); +#endif server.on("/", HTTP_GET, [](AsyncWebServerRequest* request) { request->send(200, "text/plain", "Hello, world"); diff --git a/examples/StreamFiles/StreamFiles.ino b/examples/StreamFiles/StreamFiles.ino index 2a2c1b6..508298d 100644 --- a/examples/StreamFiles/StreamFiles.ino +++ b/examples/StreamFiles/StreamFiles.ino @@ -23,9 +23,12 @@ void setup() { LittleFS.begin(); +#ifndef CONFIG_IDF_TARGET_ESP32H2 WiFi.mode(WIFI_AP); WiFi.softAP("esp-captive"); + dnsServer.start(53, "*", WiFi.softAPIP()); +#endif File file1 = LittleFS.open("/header.html", "w"); file1.print("ESP Captive Portal"); diff --git a/platformio.ini b/platformio.ini index 6f68d0d..397539b 100644 --- a/platformio.ini +++ b/platformio.ini @@ -15,8 +15,8 @@ monitor_filters = esp32_exception_decoder, log2file [platformio] lib_dir = . -; src_dir = examples/CaptivePortal -src_dir = examples/SimpleServer +src_dir = examples/CaptivePortal +; src_dir = examples/SimpleServer ; src_dir = examples/StreamFiles ; src_dir = examples/Filters ; src_dir = examples/Draft @@ -78,3 +78,10 @@ board = esp32-c6-devkitc-1 lib_deps = bblanchon/ArduinoJson @ 7.1.0 mathieucarbou/AsyncTCP @ 3.2.4 + +[env:pioarduino-h2] +platform = https://github.com/pioarduino/platform-espressif32/releases/download/51.03.04/platform-espressif32.zip +board = esp32-h2-devkitm-1 +lib_deps = + bblanchon/ArduinoJson @ 7.1.0 + mathieucarbou/AsyncTCP @ 3.2.4