84 eth_clock_mode_t clkMode)
95 if (thisEth ==
this) {
100 static void networkEventHandler(arduino_event_id_t event) {
102 case ARDUINO_EVENT_ETH_GOT_IP: {
104 thisEth->setIpv4Addr(ETH.localIP());
106 Serial.print(F(
"[Ethernet] local IP: "));
107 Serial.println(ETH.localIP());
108 Serial.print(F(
"subnetMask: "));
109 Serial.println(ETH.subnetMask());
110 Serial.print(F(
"gatewayIP: "));
111 Serial.println(ETH.gatewayIP());
112 Serial.print(F(
"ETH MAC: "));
113 Serial.println(ETH.macAddress());
114 if (ETH.fullDuplex()) {
115 Serial.print(F(
"FULL_DUPLEX , "));
117 Serial.print(ETH.linkSpeed());
118 Serial.println(F(
"Mbps"));
121 case ARDUINO_EVENT_ETH_DISCONNECTED: {
123 SUPLA_LOG_INFO(
"[%s] Disconnected", thisEth->getIntfName());
124 thisEth->setIpv4Addr(0);
132 void setup()
override {
138 ::Network.onEvent(Supla::ESPETH::networkEventHandler);
141 "[%s] setting up ETH (type %d, address %d, mdcPin %d, mdioPin %d, "
142 "powerPin %d, clkMode %d)",
143 thisEth->getIntfName(),
150 ETH.begin(ethType, ethAddress, mdcPin, mdioPin, powerPin, clkMode);
151 if (hasStaticIpConfig()) {
152 const auto &cfg = getNetifConfig();
153 IPAddress localIp = toArduinoIpAddress(cfg.ip);
154 IPAddress gateway = toArduinoIpAddress(cfg.gateway);
155 IPAddress subnet = toArduinoIpAddress(cfg.netmask);
156 IPAddress dns1 = toArduinoIpAddress(cfg.dns1);
157 IPAddress dns2 = toArduinoIpAddress(cfg.dns2);
158 if (!ETH.config(localIp, gateway, subnet, dns1, dns2)) {
159 SUPLA_LOG_WARNING(
"ETH static IP config failed, continuing");
165 char newHostname[32] = {};
166 generateHostname(hostname, macSizeForHostname, newHostname);
167 strncpy(hostname, newHostname,
sizeof(hostname) - 1);
168 SUPLA_LOG_DEBUG(
"[%s] Network LAN/hostname: %s", getIntfName(), hostname);
169 ETH.setHostname(hostname);
172 void disable()
override {
177 allowDisable =
false;
178 SUPLA_LOG_DEBUG(
"[%s] disabling ETH connection", getIntfName());
179 DisconnectProtocols();
182 bool getMacAddr(uint8_t *mac)
override {
190 const char *getIntfName()
const override {
194 void setHostname(
const char *prefix,
int macSize)
override {
195 macSizeForHostname = macSize;
196 strncpy(hostname, prefix,
sizeof(hostname) - 1);
197 SUPLA_LOG_DEBUG(
"[%s] Network LAN/hostname: %s", getIntfName(), hostname);
201 bool allowDisable =
false;
202 int macSizeForHostname = 0;
203 bool initDone =
false;
204 eth_phy_type_t ethType = ETH_PHY_LAN8720;
205 int32_t ethAddress = -1;
209 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:79