ESPHome 2025.9.0-dev
Loading...
Searching...
No Matches
util.cpp
Go to the documentation of this file.
1#include "util.h"
3#ifdef USE_NETWORK
4#ifdef USE_WIFI
6#endif
7
8#ifdef USE_ETHERNET
10#endif
11
12#ifdef USE_OPENTHREAD
14#endif
15
16#ifdef USE_MODEM
17#include "esphome/components/modem/modem_component.h"
18#endif
19
20namespace esphome {
21namespace network {
22
23// The order of the components is important: WiFi should come after any possible main interfaces (it may be used as
24// an AP that use a previous interface for NAT).
25
27#ifdef USE_ETHERNET
29 return true;
30#endif
31
32#ifdef USE_MODEM
33 if (modem::global_modem_component != nullptr)
34 return modem::global_modem_component->is_connected();
35#endif
36
37#ifdef USE_WIFI
38 if (wifi::global_wifi_component != nullptr)
40#endif
41
42#ifdef USE_OPENTHREAD
45#endif
46
47#ifdef USE_HOST
48 return true; // Assume its connected
49#endif
50 return false;
51}
52
54#ifdef USE_MODEM
55 if (modem::global_modem_component != nullptr)
56 return modem::global_modem_component->is_disabled();
57#endif
58
59#ifdef USE_WIFI
60 if (wifi::global_wifi_component != nullptr)
62#endif
63 return false;
64}
65
67#ifdef USE_ETHERNET
68 if (ethernet::global_eth_component != nullptr)
70#endif
71
72#ifdef USE_MODEM
73 if (modem::global_modem_component != nullptr)
74 return modem::global_modem_component->get_ip_addresses();
75#endif
76
77#ifdef USE_WIFI
78 if (wifi::global_wifi_component != nullptr)
80#endif
81#ifdef USE_OPENTHREAD
84#endif
85 return {};
86}
87
88std::string get_use_address() {
89#ifdef USE_ETHERNET
90 if (ethernet::global_eth_component != nullptr)
92#endif
93
94#ifdef USE_MODEM
95 if (modem::global_modem_component != nullptr)
96 return modem::global_modem_component->get_use_address();
97#endif
98
99#ifdef USE_WIFI
100 if (wifi::global_wifi_component != nullptr)
102#endif
103 return "";
104}
105
106} // namespace network
107} // namespace esphome
108#endif
std::string get_use_address() const
network::IPAddresses get_ip_addresses()
EthernetComponent * global_eth_component
std::array< IPAddress, 5 > IPAddresses
Definition ip_address.h:144
std::string get_use_address()
Get the active network hostname.
Definition util.cpp:88
bool is_connected()
Return whether the node is connected to the network (through wifi, eth, ...)
Definition util.cpp:26
network::IPAddresses get_ip_addresses()
Definition util.cpp:66
bool is_disabled()
Return whether the network is disabled (only wifi for now)
Definition util.cpp:53
OpenThreadComponent * global_openthread_component
WiFiComponent * global_wifi_component
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7