from static address to dhcp
Posted: Fri Mar 10, 2023 6:17 pm
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
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