Skip to content

eliminates error messages when using Ethernet Static IP #5836

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Nov 9, 2021
13 changes: 11 additions & 2 deletions libraries/WiFi/src/ETH.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -385,8 +385,16 @@ bool ETHClass::config(IPAddress local_ip, IPAddress gateway, IPAddress subnet, I
info.gw.addr = 0;
info.netmask.addr = 0;
}

// avoid error messages or failure while DHCP still did not get stopped
uint8_t tries = 5;
do {
const TickType_t xDelay = 50 / portTICK_PERIOD_MS;
vTaskDelay( xDelay );
err = tcpip_adapter_dhcpc_stop(TCPIP_ADAPTER_IF_ETH);
tries--;
} while (tries && err != ESP_ERR_TCPIP_ADAPTER_DHCP_ALREADY_STOPPED);

err = tcpip_adapter_dhcpc_stop(TCPIP_ADAPTER_IF_ETH);
if(err != ESP_OK && err != ESP_ERR_TCPIP_ADAPTER_DHCP_ALREADY_STOPPED){
log_e("DHCP could not be stopped! Error: %d", err);
return false;
Expand All @@ -396,7 +404,8 @@ bool ETHClass::config(IPAddress local_ip, IPAddress gateway, IPAddress subnet, I
if(err != ERR_OK){
log_e("STA IP could not be configured! Error: %d", err);
return false;
}
}

if(info.ip.addr){
staticIP = true;
} else {
Expand Down