ESPHome 2026.11.0-dev
Loading...
Searching...
No Matches
network_component.h
Go to the documentation of this file.
1#pragma once
3#if defined(USE_NETWORK) && defined(USE_ESP32)
5
6#ifdef USE_NETWORK_DEFAULT_ROUTE
8// Forward declaration matching esp_netif's own typedef; avoids pulling esp_netif.h
9// into this header.
10using esp_netif_t = struct esp_netif_obj;
11#endif
12
13namespace esphome::network {
14
15#ifdef USE_NETWORK_DEFAULT_ROUTE
23
24#ifdef NETWORK_ACTIVE_INTERFACE_LISTENER_COUNT
27 public:
28 virtual void on_active_interface(NetworkInterface interface) = 0;
29};
30#endif
31#endif
32
33class NetworkComponent final : public Component {
34 public:
35 void setup() override;
36 void dump_config() override;
37 // AFTER_BLUETOOTH: BLE controller must initialize before esp_netif_init per IDF guidance.
38 float get_setup_priority() const override { return setup_priority::AFTER_BLUETOOTH; }
39
40#ifdef USE_NETWORK_DEFAULT_ROUTE
41 void loop() override;
42
45#ifdef NETWORK_ACTIVE_INTERFACE_LISTENER_COUNT
47 this->active_interface_listeners_.push_back(listener);
48 }
49#endif
50
51 protected:
52 // Verify-lwIP-route interval for the settled state; keeps the global lwIP core
53 // mutex off the hot loop path.
54 static constexpr uint32_t ROUTE_CHECK_INTERVAL_MS = 1000;
55 // Last netif this component made the default; avoids redundant esp_netif calls.
58#ifdef NETWORK_ACTIVE_INTERFACE_LISTENER_COUNT
60#endif
62#endif
63};
64} // namespace esphome::network
65#endif
Minimal static vector - saves memory by avoiding std::vector overhead.
Definition helpers.h:286
Notified from the main loop when the interface holding the default route changes.
virtual void on_active_interface(NetworkInterface interface)=0
StaticVector< ActiveInterfaceListener *, NETWORK_ACTIVE_INTERFACE_LISTENER_COUNT > active_interface_listeners_
float get_setup_priority() const override
void add_active_interface_listener(ActiveInterfaceListener *listener)
static constexpr uint32_t ROUTE_CHECK_INTERVAL_MS
NetworkInterface get_active_interface() const
The first connected interface in network: priority order; NONE while none is connected.
NetworkInterface
The interface holding the default route.
constexpr float AFTER_BLUETOOTH
Definition component.h:49
struct esp_netif_obj esp_netif_t
static void uint32_t