mirror of
https://github.com/esphome/esphome.git
synced 2026-02-08 00:31:58 +00:00
wip
This commit is contained in:
@@ -75,8 +75,7 @@ void CaptivePortal::setup() {
|
||||
void CaptivePortal::start() {
|
||||
this->base_->init();
|
||||
if (!this->initialized_) {
|
||||
// Use fallback position so web_server handlers are checked first
|
||||
this->base_->add_handler(this, web_server_base::HandlerPosition::FALLBACK);
|
||||
this->base_->add_handler(this);
|
||||
}
|
||||
|
||||
network::IPAddress ip = wifi::global_wifi_component->wifi_soft_ap_ip();
|
||||
|
||||
@@ -49,14 +49,9 @@ class CaptivePortal : public AsyncWebHandler, public Component {
|
||||
// Handle all GET requests when captive portal is active.
|
||||
// This allows us to respond with the portal page for any URL,
|
||||
// triggering OS captive portal detection.
|
||||
if (!this->active_ || request->method() != HTTP_GET)
|
||||
return false;
|
||||
#ifdef USE_WEBSERVER
|
||||
// Let web_server handle root URL when ?web_server param is present
|
||||
if (request->url() == "/" && request->hasParam("web_server"))
|
||||
return false;
|
||||
#endif
|
||||
return true;
|
||||
// Note: web_server registers its handlers first, so it will handle
|
||||
// /?web_server before captive_portal sees the request.
|
||||
return this->active_ && request->method() == HTTP_GET;
|
||||
}
|
||||
|
||||
void handle_config(AsyncWebServerRequest *request);
|
||||
|
||||
@@ -149,12 +149,6 @@ bool ESPNowComponent::is_wifi_enabled() {
|
||||
}
|
||||
|
||||
void ESPNowComponent::setup() {
|
||||
#ifndef USE_WIFI
|
||||
// Initialize LwIP stack for wake_loop_threadsafe() socket support
|
||||
// When WiFi component is present, it handles esp_netif_init()
|
||||
ESP_ERROR_CHECK(esp_netif_init());
|
||||
#endif
|
||||
|
||||
if (this->enable_on_boot_) {
|
||||
this->enable_();
|
||||
} else {
|
||||
@@ -174,8 +168,6 @@ void ESPNowComponent::enable() {
|
||||
|
||||
void ESPNowComponent::enable_() {
|
||||
if (!this->is_wifi_enabled()) {
|
||||
esp_event_loop_create_default();
|
||||
|
||||
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
|
||||
|
||||
ESP_ERROR_CHECK(esp_wifi_init(&cfg));
|
||||
|
||||
@@ -102,11 +102,6 @@ void EthernetComponent::setup() {
|
||||
ESPHL_ERROR_CHECK(err, "SPI bus initialize error");
|
||||
#endif
|
||||
|
||||
err = esp_netif_init();
|
||||
ESPHL_ERROR_CHECK(err, "ETH netif init error");
|
||||
err = esp_event_loop_create_default();
|
||||
ESPHL_ERROR_CHECK(err, "ETH event loop error");
|
||||
|
||||
esp_netif_config_t cfg = ESP_NETIF_DEFAULT_ETH();
|
||||
this->eth_netif_ = esp_netif_new(&cfg);
|
||||
|
||||
|
||||
@@ -1,19 +1,14 @@
|
||||
#include "network_component.h"
|
||||
#ifdef USE_NETWORK
|
||||
#include "esphome/core/log.h"
|
||||
|
||||
#ifdef USE_ESP32
|
||||
#include "esphome/core/log.h"
|
||||
#include "esp_event.h"
|
||||
#include "esp_netif.h"
|
||||
#endif
|
||||
|
||||
namespace esphome {
|
||||
namespace network {
|
||||
namespace esphome::network {
|
||||
|
||||
static const char *const TAG = "network";
|
||||
|
||||
void NetworkComponent::setup() {
|
||||
#ifdef USE_ESP32
|
||||
// Initialize network stack early - required before web_server can bind.
|
||||
// This must run before WiFi/Ethernet setup so web_server can register
|
||||
// its handlers before captive_portal.
|
||||
@@ -26,7 +21,6 @@ void NetworkComponent::setup() {
|
||||
// ESP_ERR_INVALID_STATE means it was already created
|
||||
ESP_LOGE(TAG, "esp_event_loop_create_default failed: %s", esp_err_to_name(err));
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
float NetworkComponent::get_setup_priority() const {
|
||||
@@ -34,6 +28,5 @@ float NetworkComponent::get_setup_priority() const {
|
||||
return setup_priority::WIFI + 2.0f;
|
||||
}
|
||||
|
||||
} // namespace network
|
||||
} // namespace esphome
|
||||
} // namespace esphome::network
|
||||
#endif
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
#pragma once
|
||||
#include "esphome/core/defines.h"
|
||||
#ifdef USE_NETWORK
|
||||
#ifdef USE_ESP32
|
||||
#include "esphome/core/component.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace network {
|
||||
namespace esphome::network {
|
||||
|
||||
/// Component that initializes the network stack early.
|
||||
/// This allows web_server to bind before WiFi/Ethernet setup.
|
||||
@@ -14,6 +13,5 @@ class NetworkComponent : public Component {
|
||||
float get_setup_priority() const override;
|
||||
};
|
||||
|
||||
} // namespace network
|
||||
} // namespace esphome
|
||||
} // namespace esphome::network
|
||||
#endif
|
||||
|
||||
@@ -35,8 +35,6 @@ void OpenThreadComponent::setup() {
|
||||
.max_fds = 3,
|
||||
};
|
||||
ESP_ERROR_CHECK(nvs_flash_init());
|
||||
ESP_ERROR_CHECK(esp_event_loop_create_default());
|
||||
ESP_ERROR_CHECK(esp_netif_init());
|
||||
ESP_ERROR_CHECK(esp_vfs_eventfd_register(&eventfd_config));
|
||||
|
||||
xTaskCreate(
|
||||
|
||||
@@ -24,6 +24,10 @@
|
||||
#include "esphome/components/logger/logger.h"
|
||||
#endif
|
||||
|
||||
#ifdef USE_CAPTIVE_PORTAL
|
||||
#include "esphome/components/captive_portal/captive_portal.h"
|
||||
#endif
|
||||
|
||||
#ifdef USE_CLIMATE
|
||||
#include "esphome/components/climate/climate.h"
|
||||
#endif
|
||||
@@ -1966,6 +1970,7 @@ bool WebServer::canHandle(AsyncWebServerRequest *request) const {
|
||||
if (url == ESPHOME_F("/")) {
|
||||
#ifdef USE_CAPTIVE_PORTAL
|
||||
// When captive portal is active, only handle "/" if ?web_server param is present
|
||||
// This lets captive_portal show its page at "/" while web_server handles /?web_server
|
||||
if (captive_portal::global_captive_portal != nullptr && captive_portal::global_captive_portal->is_active()) {
|
||||
return request->hasParam(ESPHOME_F("web_server"));
|
||||
}
|
||||
|
||||
@@ -414,9 +414,6 @@ void WiFiComponent::setup() {
|
||||
if (this->enable_on_boot_) {
|
||||
this->start();
|
||||
} else {
|
||||
#ifdef USE_ESP32
|
||||
esp_netif_init();
|
||||
#endif
|
||||
this->state_ = WIFI_COMPONENT_STATE_DISABLED;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -137,11 +137,6 @@ void WiFiComponent::wifi_pre_setup_() {
|
||||
get_mac_address_raw(mac);
|
||||
set_mac_address(mac);
|
||||
}
|
||||
esp_err_t err = esp_netif_init();
|
||||
if (err != ERR_OK) {
|
||||
ESP_LOGE(TAG, "esp_netif_init failed: %s", esp_err_to_name(err));
|
||||
return;
|
||||
}
|
||||
s_wifi_event_group = xEventGroupCreate();
|
||||
if (s_wifi_event_group == nullptr) {
|
||||
ESP_LOGE(TAG, "xEventGroupCreate failed");
|
||||
@@ -153,11 +148,7 @@ void WiFiComponent::wifi_pre_setup_() {
|
||||
ESP_LOGE(TAG, "xQueueCreate failed");
|
||||
return;
|
||||
}
|
||||
err = esp_event_loop_create_default();
|
||||
if (err != ERR_OK) {
|
||||
ESP_LOGE(TAG, "esp_event_loop_create_default failed: %s", esp_err_to_name(err));
|
||||
return;
|
||||
}
|
||||
esp_err_t err;
|
||||
esp_event_handler_instance_t instance_wifi_id, instance_ip_id;
|
||||
err = esp_event_handler_instance_register(WIFI_EVENT, ESP_EVENT_ANY_ID, &event_handler, nullptr, &instance_wifi_id);
|
||||
if (err != ERR_OK) {
|
||||
|
||||
Reference in New Issue
Block a user