35 explicit ESPETHSPI(eth_phy_type_t type, int32_t phy_addr,
36 int cs,
int irq,
int rst, spi_host_device_t spi_host,
37 int sck = -1,
int miso = -1,
int mosi = -1) {
40 ethspi_phy_addr = phy_addr;
44 ethspi_spi_host = spi_host;
51 if (thisSpiEth ==
this) {
56 static void networkEventHandler(arduino_event_id_t event) {
58 case ARDUINO_EVENT_ETH_GOT_IP: {
59 Serial.print(F(
"[Ethernet] local IP: "));
60 Serial.println(ETH.localIP());
61 Serial.print(F(
"subnetMask: "));
62 Serial.println(ETH.subnetMask());
63 Serial.print(F(
"gatewayIP: "));
64 Serial.println(ETH.gatewayIP());
65 Serial.print(F(
"ETH MAC: "));
66 Serial.println(ETH.macAddress());
67 if (ETH.fullDuplex()) {
68 Serial.print(F(
"FULL_DUPLEX , "));
70 Serial.print(ETH.linkSpeed());
71 Serial.println(F(
"Mbps"));
73 thisSpiEth->setIpv4Addr(ETH.localIP());
77 case ARDUINO_EVENT_ETH_DISCONNECTED: {
78 Serial.println(F(
"[Ethernet] Disconnected"));
80 thisSpiEth->setIpv4Addr(0);
87 void setup()
override {
93 ::Network.onEvent(Supla::ESPETHSPI::networkEventHandler);
95 Serial.println(F(
"[Ethernet] establishing LAN connection"));
96 ETH.begin(ethspi_type,
107 char newHostname[32] = {};
108 generateHostname(hostname, macSizeForHostname, newHostname);
109 strncpy(hostname, newHostname,
sizeof(hostname) - 1);
110 SUPLA_LOG_DEBUG(
"[%s] Network Lan/hostname: %s", getIntfName(), hostname);
111 ETH.setHostname(hostname);
114 void disable()
override {
119 allowDisable =
false;
120 SUPLA_LOG_DEBUG(
"[%s] disabling ETH connection", getIntfName());
121 DisconnectProtocols();
125 bool getMacAddr(uint8_t *mac)
override {
132 void setHostname(
const char *prefix,
int macSize)
override {
133 macSizeForHostname = macSize;
134 strncpy(hostname, prefix,
sizeof(hostname) - 1);
135 SUPLA_LOG_DEBUG(
"[%s] Network Lam/hostname: %s", getIntfName(), hostname);
139 eth_phy_type_t ethspi_type;
140 int32_t ethspi_phy_addr;
144 spi_host_device_t ethspi_spi_host;
148 bool allowDisable =
false;
149 int macSizeForHostname = 0;
150 bool initDone =
false;