75 explicit ESPETH(uint8_t ethmode) {
85 if (thisEth ==
this) {
90 static void networkEventHandler(arduino_event_id_t event) {
92 case ARDUINO_EVENT_ETH_GOT_IP: {
93 Serial.print(F(
"[Ethernet] local IP: "));
94 Serial.println(ETH.localIP());
95 Serial.print(F(
"subnetMask: "));
96 Serial.println(ETH.subnetMask());
97 Serial.print(F(
"gatewayIP: "));
98 Serial.println(ETH.gatewayIP());
99 Serial.print(F(
"ETH MAC: "));
100 Serial.println(ETH.macAddress());
101 if (ETH.fullDuplex()) {
102 Serial.print(F(
"FULL_DUPLEX , "));
104 Serial.print(ETH.linkSpeed());
105 Serial.println(F(
"Mbps"));
107 thisEth->setIpv4Addr(ETH.localIP());
111 case ARDUINO_EVENT_ETH_DISCONNECTED: {
112 Serial.println(F(
"[Ethernet] Disconnected"));
114 thisEth->setIpv4Addr(0);
122 void setup()
override {
128 ::Network.onEvent(Supla::ESPETH::networkEventHandler);
130 Serial.println(F(
"[Ethernet] establishing LAN connection"));
139 char newHostname[32] = {};
140 generateHostname(hostname, macSizeForHostname, newHostname);
141 strncpy(hostname, newHostname,
sizeof(hostname) - 1);
142 SUPLA_LOG_DEBUG(
"[%s] Network AP/hostname: %s", getIntfName(), hostname);
143 ETH.setHostname(hostname);
146 void disable()
override {
151 allowDisable =
false;
152 SUPLA_LOG_DEBUG(
"[%s] disabling ETH connection", getIntfName());
153 DisconnectProtocols();
157 bool getMacAddr(uint8_t *mac)
override {
164 void setHostname(
const char *prefix,
int macSize)
override {
165 macSizeForHostname = macSize;
166 strncpy(hostname, prefix,
sizeof(hostname) - 1);
167 SUPLA_LOG_DEBUG(
"[%s] Network AP/hostname: %s", getIntfName(), hostname);
171 uint8_t ETH_ADDRESS = {};
172 bool allowDisable =
false;
173 int macSizeForHostname = 0;
174 bool initDone =
false;