ESPHome  2022.11.3
ethernet_component.h
Go to the documentation of this file.
1 #pragma once
2 
3 #ifdef USE_ESP32_FRAMEWORK_ARDUINO
4 
6 #include "esphome/core/hal.h"
8 
9 #include "esp_eth.h"
10 #include <esp_wifi.h>
11 #include <WiFiType.h>
12 #include <WiFi.h>
13 
14 namespace esphome {
15 namespace ethernet {
16 
21 };
22 
23 struct ManualIP {
29 };
30 
32  STOPPED,
33  CONNECTING,
34  CONNECTED,
35 };
36 
37 class EthernetComponent : public Component {
38  public:
40  void setup() override;
41  void loop() override;
42  void dump_config() override;
43  float get_setup_priority() const override;
44  bool can_proceed() override;
45  bool is_connected();
46 
47  void set_phy_addr(uint8_t phy_addr);
48  void set_power_pin(GPIOPin *power_pin);
49  void set_mdc_pin(uint8_t mdc_pin);
50  void set_mdio_pin(uint8_t mdio_pin);
51  void set_type(EthernetType type);
52  void set_clk_mode(eth_clock_mode_t clk_mode);
53  void set_manual_ip(const ManualIP &manual_ip);
54 
56  std::string get_use_address() const;
57  void set_use_address(const std::string &use_address);
58 
59  protected:
60  void on_wifi_event_(system_event_id_t event, system_event_info_t info);
61  void start_connect_();
62  void dump_connect_params_();
63 
64  static void eth_phy_config_gpio();
65  static void eth_phy_power_enable(bool enable);
66 
67  std::string use_address_;
68  uint8_t phy_addr_{0};
69  GPIOPin *power_pin_{nullptr};
70  uint8_t mdc_pin_{23};
71  uint8_t mdio_pin_{18};
73  eth_clock_mode_t clk_mode_{ETH_CLOCK_GPIO0_IN};
74  optional<ManualIP> manual_ip_{};
75 
76  bool started_{false};
77  bool connected_{false};
79  uint32_t connect_begin_;
80  eth_config_t eth_config_;
81  eth_phy_power_enable_func orig_power_enable_fun_;
82 };
83 
84 // NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
86 
87 } // namespace ethernet
88 } // namespace esphome
89 
90 #endif // USE_ESP32_FRAMEWORK_ARDUINO
void setup()
void loop()
network::IPAddress dns1
The first DNS server. 0.0.0.0 for default.
std::string get_use_address()
Get the active network hostname.
Definition: util.cpp:41
bool is_connected()
Return whether the node is connected to the network (through wifi, eth, ...)
Definition: util.cpp:15
EthernetComponent * global_eth_component
network::IPAddress dns2
The second DNS server. 0.0.0.0 for default.
uint8_t type
Definition: a4988.cpp:4
eth_phy_power_enable_func orig_power_enable_fun_
network::IPAddress get_ip_address()
Definition: util.cpp:29