chore: clean up W5500 debug logs

- Reduce verbose logs in main loop
- Remove detailed HTTP traces on shade commands
- Keep useful messages for W5500 initialization and IP status
This commit is contained in:
Anthony Marchand 2026-01-29 00:18:09 +01:00
parent 0e0a482afb
commit 4df4fc87d2
3 changed files with 94 additions and 78 deletions

View file

@ -86,7 +86,10 @@ conn_types_t Network::preferredConnType() {
} }
void Network::loop() { void Network::loop() {
// Check W5500 link status manually (polling mode) // Check W5500 link status manually (polling mode)
// Only check if we don't have IP yet - once we have IP, stop checking to avoid SPI errors
if(settings.Ethernet.isSPIController() && !this->w5500GotIP) {
this->checkW5500Link(); this->checkW5500Link();
}
// ORDER OF OPERATIONS: // ORDER OF OPERATIONS:
// ---------------------------------------------- // ----------------------------------------------
@ -499,9 +502,11 @@ bool Network::connectWired() {
buscfg.sclk_io_num = settings.Ethernet.SCLKPin; buscfg.sclk_io_num = settings.Ethernet.SCLKPin;
buscfg.quadwp_io_num = -1; buscfg.quadwp_io_num = -1;
buscfg.quadhd_io_num = -1; buscfg.quadhd_io_num = -1;
buscfg.max_transfer_sz = 0; buscfg.max_transfer_sz = 4096;
esp_err_t ret = spi_bus_initialize(SPI2_HOST, &buscfg, SPI_DMA_CH_AUTO); // Use SPI3_HOST instead of SPI2_HOST to avoid conflicts with CC1101
// CC1101 typically uses SPI1/VSPI, so SPI3 should be safe
esp_err_t ret = spi_bus_initialize(SPI3_HOST, &buscfg, SPI_DMA_CH_AUTO);
if(ret != ESP_OK && ret != ESP_ERR_INVALID_STATE) { if(ret != ESP_OK && ret != ESP_ERR_INVALID_STATE) {
Serial.printf("Failed to initialize SPI bus: %s\n", esp_err_to_name(ret)); Serial.printf("Failed to initialize SPI bus: %s\n", esp_err_to_name(ret));
ethBeginSuccess = false; ethBeginSuccess = false;
@ -516,7 +521,7 @@ bool Network::connectWired() {
devcfg.queue_size = 20; devcfg.queue_size = 20;
spi_device_handle_t spi_handle = NULL; spi_device_handle_t spi_handle = NULL;
ret = spi_bus_add_device(SPI2_HOST, &devcfg, &spi_handle); ret = spi_bus_add_device(SPI3_HOST, &devcfg, &spi_handle);
if(ret != ESP_OK) { if(ret != ESP_OK) {
Serial.printf("Failed to add SPI device: %s\n", esp_err_to_name(ret)); Serial.printf("Failed to add SPI device: %s\n", esp_err_to_name(ret));
ethBeginSuccess = false; ethBeginSuccess = false;
@ -967,50 +972,54 @@ void Network::emitHeap(uint8_t num) {
} }
// Check W5500 link status manually // Check W5500 link status manually
// IMPORTANT: Do NOT call esp_eth_ioctl() - it causes SPI errors and blocks the system!
void Network::checkW5500Link() { void Network::checkW5500Link() {
if(!this->ethStarted || !settings.Ethernet.isSPIController() || this->w5500_eth_handle == nullptr) { if(!this->ethStarted || !settings.Ethernet.isSPIController() || this->w5500_eth_handle == nullptr) {
return; return;
} }
static unsigned long lastCheck = 0; static unsigned long lastIPCheck = 0;
static bool lastLinkState = false; static bool dhcpStarted = false;
// Only check every 2 seconds to avoid spam // Once we have IP, just verify it's still valid periodically (every 30 seconds)
if(millis() - lastCheck < 2000) return; if(this->w5500GotIP) {
lastCheck = millis(); if(millis() - lastIPCheck >= 30000) {
lastIPCheck = millis();
// Check link status via speed (if we can get speed, link is up)
esp_eth_handle_t eth_handle = (esp_eth_handle_t)this->w5500_eth_handle;
eth_speed_t speed;
esp_err_t ret = esp_eth_ioctl(eth_handle, ETH_CMD_G_SPEED, &speed);
if(ret == ESP_OK) {
// If we can get speed, link is up
bool currentLink = true;
if(currentLink != lastLinkState) {
lastLinkState = currentLink;
if(currentLink) {
Serial.println("W5500: Link UP");
this->w5500LinkUp = true;
// Start DHCP client now that link is up
if(this->w5500_netif) { if(this->w5500_netif) {
esp_netif_dhcpc_start(this->w5500_netif);
}
} else {
Serial.println("W5500: Link DOWN");
this->w5500LinkUp = false;
this->w5500GotIP = false;
this->connType = conn_types_t::unset;
}
}
// If link is up but no IP yet, check for IP
if(currentLink && !this->w5500GotIP && this->w5500_netif) {
esp_netif_ip_info_t ip_info; esp_netif_ip_info_t ip_info;
if(esp_netif_get_ip_info(this->w5500_netif, &ip_info) == ESP_OK) { if(esp_netif_get_ip_info(this->w5500_netif, &ip_info) == ESP_OK) {
if(ip_info.ip.addr != 0) { if(ip_info.ip.addr == 0) {
// IP lost, reset state
Serial.println("W5500: IP lost!");
this->w5500GotIP = false;
this->w5500LinkUp = false;
this->connType = conn_types_t::unset;
dhcpStarted = false;
}
}
}
}
return; // Don't do anything else once we have IP
}
// If we don't have IP yet, check for it every 2 seconds
if(millis() - lastIPCheck < 2000) return;
lastIPCheck = millis();
// Start DHCP if not already started
if(!dhcpStarted && this->w5500_netif) {
Serial.println("W5500: Starting DHCP client...");
esp_netif_dhcpc_start(this->w5500_netif);
dhcpStarted = true;
this->w5500LinkUp = true; // Assume link is up if we're trying DHCP
}
// Check for IP
if(this->w5500_netif) {
esp_netif_ip_info_t ip_info;
if(esp_netif_get_ip_info(this->w5500_netif, &ip_info) == ESP_OK && ip_info.ip.addr != 0) {
this->w5500GotIP = true; this->w5500GotIP = true;
this->w5500LinkUp = true;
this->w5500IP = IPAddress( this->w5500IP = IPAddress(
esp_ip4_addr_get_byte(&ip_info.ip, 0), esp_ip4_addr_get_byte(&ip_info.ip, 0),
esp_ip4_addr_get_byte(&ip_info.ip, 1), esp_ip4_addr_get_byte(&ip_info.ip, 1),
@ -1038,8 +1047,6 @@ void Network::checkW5500Link() {
} }
} }
} }
}
}
// W5500 Event Handler for ESP-IDF events // W5500 Event Handler for ESP-IDF events
void Network::w5500EventHandler(void *arg, esp_event_base_t event_base, int32_t event_id, void *event_data) { void Network::w5500EventHandler(void *arg, esp_event_base_t event_base, int32_t event_id, void *event_data) {

View file

@ -37,7 +37,7 @@ void setup() {
net.setup(); net.setup();
somfy.begin(); somfy.begin();
//git.checkForUpdate(); //git.checkForUpdate();
esp_task_wdt_init(15, true); //enable panic so ESP32 restarts (increased from 7 to 15 seconds) esp_task_wdt_init(30, true); //enable panic so ESP32 restarts (increased to 30 seconds for W5500)
esp_task_wdt_add(NULL); //add current thread to WDT watch esp_task_wdt_add(NULL); //add current thread to WDT watch
} }
@ -54,15 +54,20 @@ void loop() {
ESP.restart(); ESP.restart();
return; return;
} }
uint32_t timing = millis(); uint32_t timing = millis();
net.loop(); net.loop();
if(millis() - timing > 100) Serial.printf("Timing Net: %ldms\n", millis() - timing); if(millis() - timing > 100) {
Serial.printf("Timing Net: %ldms\n", millis() - timing);
}
esp_task_wdt_reset(); esp_task_wdt_reset();
timing = millis(); timing = millis();
somfy.loop(); somfy.loop();
if(millis() - timing > 100) Serial.printf("Timing Somfy: %ldms\n", millis() - timing); if(millis() - timing > 100) {
Serial.printf("Timing Somfy: %ldms\n", millis() - timing);
}
esp_task_wdt_reset(); esp_task_wdt_reset();
timing = millis(); timing = millis();
@ -71,19 +76,25 @@ void loop() {
git.loop(); git.loop();
esp_task_wdt_reset(); esp_task_wdt_reset();
} }
webServer.loop(); webServer.loop();
if(millis() - timing > 100) Serial.printf("Timing WebServer: %ldms\n", millis() - timing); if(millis() - timing > 100) {
Serial.printf("Timing WebServer: %ldms\n", millis() - timing);
}
esp_task_wdt_reset(); esp_task_wdt_reset();
timing = millis(); timing = millis();
sockEmit.loop(); sockEmit.loop();
if(millis() - timing > 100) Serial.printf("Timing Socket: %ldms\n", millis() - timing); if(millis() - timing > 100) {
Serial.printf("Timing Socket: %ldms\n", millis() - timing);
}
esp_task_wdt_reset(); esp_task_wdt_reset();
} }
if(rebootDelay.reboot && millis() > rebootDelay.rebootTime) { if(rebootDelay.reboot && millis() > rebootDelay.rebootTime) {
net.end(); net.end();
ESP.restart(); ESP.restart();
return;
} }
// Final watchdog reset before end of loop // Final watchdog reset before end of loop

View file

@ -383,8 +383,6 @@ void Web::handleShadeCommand(WebServer& server) {
else server.send(500, _encoding_json, F("{\"status\":\"ERROR\",\"desc\":\"No shade object supplied.\"}")); else server.send(500, _encoding_json, F("{\"status\":\"ERROR\",\"desc\":\"No shade object supplied.\"}"));
SomfyShade* shade = somfy.getShadeById(shadeId); SomfyShade* shade = somfy.getShadeById(shadeId);
if (shade) { if (shade) {
Serial.print("Received:");
Serial.println(server.arg("plain"));
// Send the command to the shade. // Send the command to the shade.
if (target <= 100) if (target <= 100)
shade->moveToTarget(shade->transformPosition(target)); shade->moveToTarget(shade->transformPosition(target));