[GH-ISSUE #152] Checkbox to select DHCP or static #118

Closed
opened 2026-02-28 01:23:32 +03:00 by kerem · 9 comments
Owner

Originally created by @Jobenas on GitHub (Apr 12, 2016).
Original GitHub issue: https://github.com/tzapu/WiFiManager/issues/152

Is there any way to include a checkbox in the manager so it is easy to select wether the station connection will be done with dhcp or static ip? I've been reading the documentation but haven't found an easy way of accomplishing this (actually haven't found any way of doing it). Thanks a lot!

Best regards,

Jorge.

Originally created by @Jobenas on GitHub (Apr 12, 2016). Original GitHub issue: https://github.com/tzapu/WiFiManager/issues/152 Is there any way to include a checkbox in the manager so it is easy to select wether the station connection will be done with dhcp or static ip? I've been reading the documentation but haven't found an easy way of accomplishing this (actually haven't found any way of doing it). Thanks a lot! Best regards, Jorge.
kerem closed this issue 2026-02-28 01:23:32 +03:00
Author
Owner

@Jobenas commented on GitHub (May 5, 2016):

Hi Tzapu,

I'm posting this on the same thread, hope you can reply :). I managed to place a checkbox on the config portal injecting html code as is shown in the documentation. My first question is how to get the value from the checkbox when I click on save, I tried using the getValue() method but can't get any actual value out of it. The second question is how to make the device connect with DHCP or static? because if I use setSTAStaticIPConfig that automatically forces a static IP to connect, but what if I need to give the choice to the user between the two? I've tried putting that last method in an if, but if the conditional is false, I don't get shown the parameters for IP and connects directly via DHCP. Thanks in advance for any hint you can provide me, and sorry if the post is a bit long.

Jorge.

<!-- gh-comment-id:217312500 --> @Jobenas commented on GitHub (May 5, 2016): Hi Tzapu, I'm posting this on the same thread, hope you can reply :). I managed to place a checkbox on the config portal injecting html code as is shown in the documentation. My first question is how to get the value from the checkbox when I click on save, I tried using the getValue() method but can't get any actual value out of it. The second question is how to make the device connect with DHCP or static? because if I use setSTAStaticIPConfig that automatically forces a static IP to connect, but what if I need to give the choice to the user between the two? I've tried putting that last method in an if, but if the conditional is false, I don't get shown the parameters for IP and connects directly via DHCP. Thanks in advance for any hint you can provide me, and sorry if the post is a bit long. Jorge.
Author
Owner

@tzapu commented on GitHub (May 6, 2016):

jorge, there s no way yet to get a value if you use completly custom html

somewhere on the todo list...

<!-- gh-comment-id:217418650 --> @tzapu commented on GitHub (May 6, 2016): jorge, there s no way yet to get a value if you use completly custom html somewhere on the todo list...
Author
Owner

@kentaylor commented on GitHub (May 8, 2016):

There is an example with a check box in the config portal at https://github.com/kentaylor/WiFiManager/blob/master/examples/ConfigOnSwitchFS/ConfigOnSwitchFS.ino . This shows how to get the check box value but doesn't answer your second question.

<!-- gh-comment-id:217710000 --> @kentaylor commented on GitHub (May 8, 2016): There is an example with a check box in the config portal at https://github.com/kentaylor/WiFiManager/blob/master/examples/ConfigOnSwitchFS/ConfigOnSwitchFS.ino . This shows how to get the check box value but doesn't answer your second question.
Author
Owner

@josep112 commented on GitHub (Jul 25, 2017):

Has anyone made any progress on this?

<!-- gh-comment-id:317736570 --> @josep112 commented on GitHub (Jul 25, 2017): Has anyone made any progress on this?
Author
Owner

@kgreene1983 commented on GitHub (Feb 5, 2018):

This a very useful thread. Ken... Will your code for checkbox work the tzapu version of wifi manager

<!-- gh-comment-id:362972012 --> @kgreene1983 commented on GitHub (Feb 5, 2018): This a very useful thread. Ken... Will your code for checkbox work the tzapu version of wifi manager
Author
Owner

@Humancell commented on GitHub (Sep 15, 2018):

I saw in the version 0.14 there is a commit that says "adds checkboxes", but I am unable to locate the documentation on this feature. Where is this documented? Just in issues ... and what specifically was added?

<!-- gh-comment-id:421591260 --> @Humancell commented on GitHub (Sep 15, 2018): I saw in the version 0.14 there is a commit that says "adds checkboxes", but I am unable to locate the documentation on this feature. Where is this documented? Just in issues ... and what specifically was added?
Author
Owner

@tablatronix commented on GitHub (Sep 16, 2018):

adds checkboxes to the issue template not wm

<!-- gh-comment-id:421658287 --> @tablatronix commented on GitHub (Sep 16, 2018): adds checkboxes to the issue template not wm
Author
Owner

@ThatchSS commented on GitHub (Dec 19, 2018):

HI All,
thought I'd jump in because I also needed this and found nothing but this thread on the topic.

I think I have a quick fix.??.
I modified the .cpp file to include this but eliminated the no scan as I don't think I'll need it.
I recycled the WiFi (no scan) button to be a WiFi (Static IP) button.

maybe not the most elegant (sorry Tzapu) but definitely the easiest way for me.
then I added this to the following method (just as you see right at the top)

void WiFiManager::handleWifi(boolean statIPAddr) {

bool scan = true;

if (statIPAddr == true) {
IPAddress _ip = IPAddress(10, 0, 1, 50);
IPAddress _gw = IPAddress(10, 0, 1, 1);
IPAddress _sn = IPAddress(255, 255, 255, 0);
setSTAStaticIPConfig(_ip, _gw, _sn);
}

then I switched the true/false values in the web page handlers

server->on(String(F("/wifi")), std::bind(&WiFiManager::handleWifi, this, false));
// switched this and the following T/F values
server->on(String(F("/0wifi")), std::bind(&WiFiManager::handleWifi, this, true));

don't forget to change the button name in the .h file.

I just have to modify the FS Parameters sketch in the examples to save the values into a SPIFFS/Json file.
so it will reboot correctly after a power cycle.

I hope it is also just as trivial.

I haven't 100% tested it, as its not complete, but just wanted to get it out to you guys, hope it helps.

I'll post the main sketch(.ino) adjustments once I have them, or let me know if you guys figure it out first.
Thanks.

Thatch

<!-- gh-comment-id:448484204 --> @ThatchSS commented on GitHub (Dec 19, 2018): HI All, thought I'd jump in because I also needed this and found nothing but this thread on the topic. I think I have a quick fix.??. I modified the .cpp file to include this but eliminated the no scan as I don't think I'll need it. I recycled the WiFi (no scan) button to be a WiFi (Static IP) button. maybe not the most elegant (sorry Tzapu) but definitely the easiest way for me. then I added this to the following method (just as you see right at the top) `void WiFiManager::handleWifi(boolean statIPAddr) {` `bool scan = true;` `if (statIPAddr == true) {` `IPAddress _ip = IPAddress(10, 0, 1, 50);` `IPAddress _gw = IPAddress(10, 0, 1, 1);` `IPAddress _sn = IPAddress(255, 255, 255, 0);` `setSTAStaticIPConfig(_ip, _gw, _sn);` `}` then I switched the true/false values in the web page handlers `server->on(String(F("/wifi")), std::bind(&WiFiManager::handleWifi, this, false));` `// switched this and the following T/F values` `server->on(String(F("/0wifi")), std::bind(&WiFiManager::handleWifi, this, true));` don't forget to change the button name in the .h file. I just have to modify the FS Parameters sketch in the examples to save the values into a SPIFFS/Json file. so it will reboot correctly after a power cycle. I hope it is also just as trivial. I haven't 100% tested it, as its not complete, but just wanted to get it out to you guys, hope it helps. I'll post the main sketch(.ino) adjustments once I have them, or let me know if you guys figure it out first. Thanks. Thatch
Author
Owner

@tablatronix commented on GitHub (Dec 19, 2018):

you can add subclasses to parameters in development branch now, there is even an example

<!-- gh-comment-id:448655760 --> @tablatronix commented on GitHub (Dec 19, 2018): you can add subclasses to parameters in development branch now, there is even an example
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/WiFiManager#118
No description provided.