83 eth_clock_mode_t clkMode)
94 if (thisEth ==
this) {
99 static void networkEventHandler(arduino_event_id_t event) {
101 case ARDUINO_EVENT_ETH_GOT_IP: {
103 thisEth->setIpv4Addr(ETH.localIP());
105 Serial.print(F(
"[Ethernet] local IP: "));
106 Serial.println(ETH.localIP());
107 Serial.print(F(
"subnetMask: "));
108 Serial.println(ETH.subnetMask());
109 Serial.print(F(
"gatewayIP: "));
110 Serial.println(ETH.gatewayIP());
111 Serial.print(F(
"ETH MAC: "));
112 Serial.println(ETH.macAddress());
113 if (ETH.fullDuplex()) {
114 Serial.print(F(
"FULL_DUPLEX , "));
116 Serial.print(ETH.linkSpeed());
117 Serial.println(F(
"Mbps"));
120 case ARDUINO_EVENT_ETH_DISCONNECTED: {
122 SUPLA_LOG_INFO(
"[%s] Disconnected", thisEth->getIntfName());
123 thisEth->setIpv4Addr(0);
131 void setup()
override {
137 ::Network.onEvent(Supla::ESPETH::networkEventHandler);
140 "[%s] setting up ETH (type %d, address %d, mdcPin %d, mdioPin %d, "
141 "powerPin %d, clkMode %d)",
142 thisEth->getIntfName(),
149 ETH.begin(ethType, ethAddress, mdcPin, mdioPin, powerPin, clkMode);
153 char newHostname[32] = {};
154 generateHostname(hostname, macSizeForHostname, newHostname);
155 strncpy(hostname, newHostname,
sizeof(hostname) - 1);
156 SUPLA_LOG_DEBUG(
"[%s] Network LAN/hostname: %s", getIntfName(), hostname);
157 ETH.setHostname(hostname);
160 void disable()
override {
165 allowDisable =
false;
166 SUPLA_LOG_DEBUG(
"[%s] disabling ETH connection", getIntfName());
167 DisconnectProtocols();
170 bool getMacAddr(uint8_t *mac)
override {
178 const char *getIntfName()
const override {
182 void setHostname(
const char *prefix,
int macSize)
override {
183 macSizeForHostname = macSize;
184 strncpy(hostname, prefix,
sizeof(hostname) - 1);
185 SUPLA_LOG_DEBUG(
"[%s] Network LAN/hostname: %s", getIntfName(), hostname);
189 bool allowDisable =
false;
190 int macSizeForHostname = 0;
191 bool initDone =
false;
192 eth_phy_type_t ethType = ETH_PHY_LAN8720;
193 int32_t ethAddress = -1;
197 eth_clock_mode_t clkMode = ETH_CLOCK_GPIO17_OUT;
ESPETH(eth_phy_type_t ethType, int32_t phyAddr, int mdc, int mdio, int power, eth_clock_mode_t clkMode)
Constructor for ETH_PHY configuration.
Definition esp32eth.h:78