mirror of
https://github.com/tzapu/WiFiManager.git
synced 2026-05-01 11:05:58 +03:00
[GH-ISSUE #235] Switch between DHCP and static IP configuration #194
Labels
No labels
📶 WiFi
🕸️ HTTP
Branch
DEV Help Wanted
Discussion
Documentation
ESP32
Example
Good First Issue
Hotfix
In Progress
Incomplete
Needs Feeback
Priority
QA
Question
Task
Upstream/Dependancy
bug
duplicate
enhancement
invalid
pull-request
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/WiFiManager#194
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @alexkirill on GitHub (Oct 10, 2016).
Original GitHub issue: https://github.com/tzapu/WiFiManager/issues/235
I try to provide user ability to switch between DHCP and static IP configuration .
How to do it?
I try to use setSTAStaticIPConfig in sketch with default values, but when, during the configuration on Captive Portal leave it blank ( or enter wrong value) ESP successfully connects to WIFI as client but with wrong IP, DNS, etc. Hence device connected to wifi but not accessible from network due to wrong submask or gateway, ect. And it seems no way to go back to change them, or start device in AP mode again. Lot of words, hope I was plain))
@kentaylor commented on GitHub (Oct 10, 2016):
Not really but if I understand correctly you want the user to decide when the device is to be configured rather than autoconnect which throws up a config portal whenever it can not connect to WiFi.
Assuming that is correct you want to initiate a configuration portal on a button press rather than autoconnect.
@alexkirill commented on GitHub (Oct 10, 2016):
Not exactly, when user set up wifi parameters of his network via Captive Portal, he must have ability to choose use DHCP or set up IP/DNS/gate manually.
@kentaylor commented on GitHub (Oct 11, 2016):
Then perhaps this example is what you should copy. But when you don't want to set an IP make sure it doesn't call this line. I don't use static IP but according to this I think it will work.
@alexkirill commented on GitHub (Oct 11, 2016):
I using AutoConnectWithStaticIP.ino example, but it almost the same. But if I remove setSTAStaticIPConfig declaration it will be no possible to set static IP in Portal. I need the way to switch between DHCP and static assign in captive portal.
@kentaylor commented on GitHub (Oct 11, 2016):
Good point.
You need to not make this call when you do not want a static IP. So you will need some logic change to achieve that.
@alexkirill commented on GitHub (Oct 11, 2016):
This logic must be implemented in captive portal and based on this library should to set wifi in dhcp or static mode. Library is pretty good but it weird that anyone haven't asked about it before.
@alexkirill commented on GitHub (Oct 11, 2016):
Ken, I test your version of WFmanager and it works like a charm. I customized template and library a bit as I want, but in general it better than this. & thanks for your fast replies
@kentaylor commented on GitHub (Oct 12, 2016):
@alexkirill I'm glad you liked it.
I'd be curious to see your modifications as I expect it would not have done exactly what you want as is and others may want the same functionality. The easiest for me would be fork my repository to your Github then commit your changes.
@jindrichsirucek commented on GitHub (Jul 12, 2018):
I was solving the same.. If you call
WiFi.config(...)and than you call
WiFi.begin(...);- it useses always provided static conf.So when you want to force ESP to use DHCP (after calling Wifi.config(...)) you have to call this inner function:
wifi_station_dhcpc_start();prior to
WiFi.begin(...);@tablatronix commented on GitHub (Jul 12, 2018):
Yeah I think begin only resets dhcp if the config changes, I noted this elsewhere and kind of consider it a bug.
@sajibkarmaker commented on GitHub (Nov 4, 2018):
you don't need any kind off esp.reset or restart you just need to write a function where you should re define IP,gateway as below to switch from fixed ip to dhcp(for esp8266 it will work definitely):
function_name(){
IPAddress ip(0, 0, 0, 0);
IPAddress subnet(0, 0, 0, 0);
IPAddress gateway(0, 0, 0, 0);
IPAddress dns(8, 8, 8, 8);
IPAddress dn1(9, 9, 9, 9);
WiFi.config(ip, gateway, subnet, dns, dn1);
WiFi.begin(SSID,PSK); //give your desired ssid
}
according to the library if ip configured as 0.0.0.0 it switch from static ip to dhcp, and set fixed ip to do the reverse from dhcp to fixed ip.
@Eusebio100 commented on GitHub (Jun 21, 2019):
I have the same problem, I can not get it to work in dhcp or static mode.
Can someone publish a code that works?
Thank.