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