mirror of
https://github.com/esphome/esphome.git
synced 2025-10-22 03:33:52 +01:00
Reduce CPU overhead by allowing components to disable their loop() (#9089)
This commit is contained in:
@@ -37,7 +37,12 @@ void CaptivePortal::handle_wifisave(AsyncWebServerRequest *request) {
|
||||
request->redirect("/?save");
|
||||
}
|
||||
|
||||
void CaptivePortal::setup() {}
|
||||
void CaptivePortal::setup() {
|
||||
#ifndef USE_ARDUINO
|
||||
// No DNS server needed for non-Arduino frameworks
|
||||
this->disable_loop();
|
||||
#endif
|
||||
}
|
||||
void CaptivePortal::start() {
|
||||
this->base_->init();
|
||||
if (!this->initialized_) {
|
||||
@@ -50,6 +55,8 @@ void CaptivePortal::start() {
|
||||
this->dns_server_->setErrorReplyCode(DNSReplyCode::NoError);
|
||||
network::IPAddress ip = wifi::global_wifi_component->wifi_soft_ap_ip();
|
||||
this->dns_server_->start(53, "*", ip);
|
||||
// Re-enable loop() when DNS server is started
|
||||
this->enable_loop();
|
||||
#endif
|
||||
|
||||
this->base_->get_server()->onNotFound([this](AsyncWebServerRequest *req) {
|
||||
|
@@ -21,8 +21,11 @@ class CaptivePortal : public AsyncWebHandler, public Component {
|
||||
void dump_config() override;
|
||||
#ifdef USE_ARDUINO
|
||||
void loop() override {
|
||||
if (this->dns_server_ != nullptr)
|
||||
if (this->dns_server_ != nullptr) {
|
||||
this->dns_server_->processNextRequest();
|
||||
} else {
|
||||
this->disable_loop();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
float get_setup_priority() const override;
|
||||
|
Reference in New Issue
Block a user