Reinitialize ethernet

#1

Hi all,
I’m trying to have a reliable ethernet connection on my esp32 system with LAN8710 phy.
I’m using a custom PCB, but it’s very straightforward. My problem is that we came into the office the other day, saw no ethernet cable plugged into the LAN port, yet the link light was on steady and the traffic light was blinking. Obviously no traffic was moving with no cable plugged in. I consider this an error condition and would like to recover from it.

I would like to detect conditions like this in the future or at the very least, periodically reset the ethernet interface. I’ve been looking through the source code and tried a periodic esp_eth_disable() call, followed by _enable(). That does the job. The interface goes down and comes back, but before it comes back up, it gives ssl errors (see below). I also tried to simply reset the PHY via GPIO. It does the same thing.

How can I gracefully disable and reinitialize the ethernet with no error messages?

Example error msgs:
[Jan 15 15:55:37.509] main.c:560 Performing periodic Ethernet PHY reset
[Jan 15 15:54:37.521] E (841253) emac: tx netif is not ready, emac_status=3
[Jan 15 15:54:38.100] I (841773) emac: emac reset done
[Jan 15 15:54:38.101] mg_ssl_if_mbedtls.c:35 0x3ffca48c mbedtls_ssl_flush_output() returned -78 (-0x004e)
[Jan 15 15:54:38.101] mg_ssl_if_mbedtls.c:35 0x3ffca48c mbedtls_ssl_write_record() returned -78 (-0x004e)
[Jan 15 15:54:38.102] mg_ssl_if_mbedtls.c:35 0x3ffca48c mbedtls_ssl_send_alert_message() returned -78 (-0x004e)
[Jan 15 15:54:38.102] mgos_mqtt.c:167 MQTT Disconnect
[Jan 15 15:54:38.102] main.c:548 Cloud disconnected (0)