ESPHome  2023.5.5
util.cpp
Go to the documentation of this file.
1 #include "util.h"
2 #include "esphome/core/defines.h"
3 
4 #ifdef USE_WIFI
6 #endif
7 
8 #ifdef USE_ETHERNET
10 #endif
11 
12 namespace esphome {
13 namespace network {
14 
15 bool is_connected() {
16 #ifdef USE_ETHERNET
18  return true;
19 #endif
20 
21 #ifdef USE_WIFI
22  if (wifi::global_wifi_component != nullptr)
24 #endif
25 
26 #ifdef USE_HOST
27  return true; // Assume its connected
28 #endif
29  return false;
30 }
31 
33 #ifdef USE_ETHERNET
34  if (ethernet::global_eth_component != nullptr)
36 #endif
37 #ifdef USE_WIFI
38  if (wifi::global_wifi_component != nullptr)
40 #endif
41  return {};
42 }
43 
44 std::string get_use_address() {
45 #ifdef USE_ETHERNET
46  if (ethernet::global_eth_component != nullptr)
48 #endif
49 #ifdef USE_WIFI
50  if (wifi::global_wifi_component != nullptr)
52 #endif
53  return "";
54 }
55 
56 } // namespace network
57 } // namespace esphome
std::string get_use_address()
Get the active network hostname.
Definition: util.cpp:44
network::IPAddress get_ip_address()
bool is_connected()
Return whether the node is connected to the network (through wifi, eth, ...)
Definition: util.cpp:15
EthernetComponent * global_eth_component
WiFiComponent * global_wifi_component
Definition: a4988.cpp:4
std::string get_use_address() const
network::IPAddress get_ip_address()
Definition: util.cpp:32