ESPHome 2026.3.3
Loading...
Searching...
No Matches
util.h
Go to the documentation of this file.
1#pragma once
3#ifdef USE_NETWORK
4#include <string>
6#include "ip_address.h"
7
8#ifdef USE_ETHERNET
10#endif
11#ifdef USE_MODEM
12#include "esphome/components/modem/modem_component.h"
13#endif
14#ifdef USE_WIFI
16#endif
17#ifdef USE_OPENTHREAD
19#endif
20
21namespace esphome::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 uses a previous interface for NAT).
25
27ESPHOME_ALWAYS_INLINE inline bool is_connected() {
28#ifdef USE_ETHERNET
30 return true;
31#endif
32
33#ifdef USE_MODEM
34 if (modem::global_modem_component != nullptr)
35 return modem::global_modem_component->is_connected();
36#endif
37
38#ifdef USE_WIFI
39 if (wifi::global_wifi_component != nullptr)
41#endif
42
43#ifdef USE_OPENTHREAD
46#endif
47
48#ifdef USE_HOST
49 return true; // Assume it's connected
50#endif
51 return false;
52}
53
55bool is_disabled();
57const char *get_use_address();
59
60} // namespace esphome::network
61#endif
EthernetComponent * global_eth_component
std::array< IPAddress, 5 > IPAddresses
Definition ip_address.h:187
const char * get_use_address()
Get the active network hostname.
Definition util.cpp:45
ESPHOME_ALWAYS_INLINE bool is_connected()
Return whether the node is connected to the network (through wifi, eth, ...)
Definition util.h:27
network::IPAddresses get_ip_addresses()
Definition util.cpp:23
bool is_disabled()
Return whether the network is disabled (only wifi for now)
Definition util.cpp:10
OpenThreadComponent * global_openthread_component
WiFiComponent * global_wifi_component