71 eth_clock_mode_t clkMode)
82 if (thisEth ==
this) {
87 static void networkEventHandler(arduino_event_id_t event) {
89 case ARDUINO_EVENT_ETH_GOT_IP: {
91 thisEth->setIpv4Addr(ETH.localIP());
94 IPAddress subnetMaskIP = ETH.subnetMask();
98 SUPLA_LOG_INFO(
"localIP: %d.%d.%d.%d",
103 SUPLA_LOG_INFO(
"subnetMaskIP: %d.%d.%d.%d",
108 SUPLA_LOG_INFO(
"gatewayIP: %d.%d.%d.%d",
113 SUPLA_LOG_INFO(
"ETH MAC: %02X:%02X:%02X:%02X:%02X:%02X",
120 SUPLA_LOG_INFO(
"speed: %d Mbps", ETH.linkSpeed());
121 if (ETH.fullDuplex()) {
122 SUPLA_LOG_INFO(
"FULL_DUPLEX");
126 case ARDUINO_EVENT_ETH_DISCONNECTED: {
128 SUPLA_LOG_INFO(
"[%s] Disconnected", thisEth->getIntfName());
129 thisEth->setIpv4Addr(0);
137 void setup()
override {
143 ::Network.onEvent(Supla::ESPETH::networkEventHandler);
146 "[%s] setting up ETH (type %d, address %d, mdcPin %d, mdioPin %d, "
147 "powerPin %d, clkMode %d)",
148 thisEth->getIntfName(),
155 ETH.begin(ethType, ethAddress, mdcPin, mdioPin, powerPin, clkMode);
156 if (hasStaticIpConfig()) {
157 const auto &cfg = getNetifConfig();
158 IPAddress localIp = toArduinoIpAddress(cfg.ip);
159 IPAddress gateway = toArduinoIpAddress(cfg.gateway);
160 IPAddress subnet = toArduinoIpAddress(cfg.netmask);
161 IPAddress dns1 = toArduinoIpAddress(cfg.dns1);
162 IPAddress dns2 = toArduinoIpAddress(cfg.dns2);
163 if (!ETH.config(localIp, gateway, subnet, dns1, dns2)) {
164 SUPLA_LOG_WARNING(
"ETH static IP config failed, continuing");
170 char newHostname[32] = {};
171 generateHostname(hostname, macSizeForHostname, newHostname);
172 strncpy(hostname, newHostname,
sizeof(hostname) - 1);
173 SUPLA_LOG_DEBUG(
"[%s] Network LAN/hostname: %s", getIntfName(), hostname);
174 ETH.setHostname(hostname);
177 void disable()
override {
182 allowDisable =
false;
183 SUPLA_LOG_DEBUG(
"[%s] disabling ETH connection", getIntfName());
184 DisconnectProtocols();
187 bool getMacAddr(uint8_t *mac)
override {
195 const char *getIntfName()
const override {
199 void setHostname(
const char *prefix,
int macSize)
override {
200 macSizeForHostname = macSize;
201 strncpy(hostname, prefix,
sizeof(hostname) - 1);
202 SUPLA_LOG_DEBUG(
"[%s] Network LAN/hostname: %s", getIntfName(), hostname);
206 bool allowDisable =
false;
207 int macSizeForHostname = 0;
208 bool initDone =
false;
209 eth_phy_type_t ethType = ETH_PHY_LAN8720;
210 int32_t ethAddress = -1;
214 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:66