Page 1 of 1

from static address to dhcp

Posted: Fri Mar 10, 2023 6:17 pm
by VormsThierry
Hello,
I have a software that store different wifi conifguration.
Some are with dhcp other not.
The software try all configs with criterias.
When the esp try a config with fixed address and the next is with dhcp, the esp try to connect with the precedent ip.
How to forget the precedent ip ?

Basicaly, my code:
if (!currentWifi.dhcp){
if (!WiFi.config(currentWifi.ip, currentWifi.gateway, currentWifi.mask, currentWifi.dns, currentWifi.dns)) {
Serial.println("STA Failed to configure");
return false;
} else {
printIPAddress(", ip", currentWifi.ip);
printIPAddress(", dns", currentWifi.dns);
printIPAddress(", gateway", currentWifi.gateway);
printIPAddress(", mask", currentWifi.mask, true);
}
}
Serial.println("Wifi begin..");
WiFi.begin(currentWifi.SSID, currentWifi.PWD);

return true;

The Wifi.config remains. How to erase it ?

Many thanks

Thierry

Re: from static address to dhcp

Posted: Wed Mar 22, 2023 4:33 pm
by VormsThierry
no response.... not good..
I try to solve the issue by starting the dhcp with:
uint32_t error = tcpip_adapter_dhcpc_start(TCPIP_ADAPTER_IF_STA);

the result error is: E (9907) event: invalid static ip

any suggestions ?