ESPHome 2026.8.0-dev
Loading...
Searching...
No Matches
util.h
Go to the documentation of this file.
1#pragma once
3#ifdef USE_NETWORK
4#include <span>
5#include <string>
7#include "ip_address.h"
8
9#ifdef USE_ETHERNET
11#endif
12#ifdef USE_MODEM
13#include "esphome/components/modem/modem_component.h"
14#endif
15#ifdef USE_WIFI
17#endif
18#ifdef USE_OPENTHREAD
20#endif
21
22namespace esphome::network {
23
24// The order of the components is important: WiFi should come after any possible main interfaces (it may be used as
25// an AP that uses a previous interface for NAT).
26
28ESPHOME_ALWAYS_INLINE inline bool is_connected() {
29#ifdef USE_ETHERNET
31 return true;
32#endif
33
34#ifdef USE_MODEM
35 if (modem::global_modem_component != nullptr)
36 return modem::global_modem_component->is_connected();
37#endif
38
39#ifdef USE_WIFI
40 if (wifi::global_wifi_component != nullptr)
42#endif
43
44#ifdef USE_OPENTHREAD
47#endif
48
49#ifdef USE_HOST
50 return true; // Assume it's connected
51#endif
52 return false;
53}
54
56bool is_disabled();
58static constexpr size_t USE_ADDRESS_BUFFER_SIZE = 70;
63const char *get_use_address_to(std::span<char, USE_ADDRESS_BUFFER_SIZE> buf);
65
66} // namespace esphome::network
67#endif
EthernetComponent * global_eth_component
std::array< IPAddress, 5 > IPAddresses
Definition ip_address.h:299
ESPHOME_ALWAYS_INLINE bool is_connected()
Return whether the node is connected to the network (through wifi, eth, ...)
Definition util.h:28
const char * get_use_address_to(std::span< char, USE_ADDRESS_BUFFER_SIZE > buf)
Get the active network address for logging.
Definition util.cpp:25
network::IPAddresses get_ip_addresses()
Definition util.cpp:51
bool is_disabled()
Return whether the network is disabled (only wifi for now)
Definition util.cpp:12
OpenThreadComponent * global_openthread_component
WiFiComponent * global_wifi_component