1
0
mirror of https://github.com/esphome/esphome.git synced 2025-10-03 18:42:23 +01:00

[captive_portal] Add DHCP Option 114 support for ESP32

This commit is contained in:
J. Nick Koston
2025-09-30 11:53:15 +02:00
parent 96868aa754
commit d30a3f0d83

View File

@@ -27,6 +27,10 @@
#include "dhcpserver/dhcpserver.h"
#endif // USE_WIFI_AP
#ifdef USE_CAPTIVE_PORTAL
#include "esphome/components/captive_portal/captive_portal.h"
#endif
#include "lwip/apps/sntp.h"
#include "lwip/dns.h"
#include "lwip/err.h"
@@ -918,6 +922,22 @@ bool WiFiComponent::wifi_ap_ip_config_(optional<ManualIP> manual_ip) {
return false;
}
#if defined(USE_CAPTIVE_PORTAL) && ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 4, 0)
// Configure DHCP Option 114 (Captive Portal URI) if captive portal is enabled
// This provides a standards-compliant way for clients to discover the captive portal
if (captive_portal::global_captive_portal != nullptr) {
static char captive_portal_uri[32];
snprintf(captive_portal_uri, sizeof(captive_portal_uri), "http://%s", network::IPAddress(&info.ip).str().c_str());
err = esp_netif_dhcps_option(s_ap_netif, ESP_NETIF_OP_SET, ESP_NETIF_CAPTIVEPORTAL_URI, captive_portal_uri,
strlen(captive_portal_uri));
if (err != ESP_OK) {
ESP_LOGV(TAG, "Failed to set DHCP captive portal URI: %s", esp_err_to_name(err));
} else {
ESP_LOGV(TAG, "DHCP Captive Portal URI set to: %s", captive_portal_uri);
}
}
#endif
err = esp_netif_dhcps_start(s_ap_netif);
if (err != ESP_OK) {