Allow showing static IP config without predefined value

Previously a valid predefined static IP had to be passed before the
config page would show the IP, gateway and subnet fields. This did not
allow the config page to show 'optional' static IP fields.
Now a boolean can be passed to the autoConnect() function which will
specify whether the static IP fields should be shown or not.
When this boolean is true but no predefined values are passed and fields
are left blank in config page, wifiManager will revert to DHCP. This
allows user to choose between static IP or DHCP without changing code
This commit is contained in:
Alex Goris
2017-05-04 21:59:17 +02:00
parent 1f500fddd1
commit 486ea7db2c
2 changed files with 13 additions and 10 deletions
+9 -7
View File
@@ -131,15 +131,17 @@ void WiFiManager::setupConfigPortal() {
}
boolean WiFiManager::autoConnect() {
boolean WiFiManager::autoConnect(boolean showStaticIPFields) {
String ssid = "ESP" + String(ESP.getChipId());
return autoConnect(ssid.c_str(), NULL);
return autoConnect(ssid.c_str(), NULL, showStaticIPFields);
}
boolean WiFiManager::autoConnect(char const *apName, char const *apPassword) {
boolean WiFiManager::autoConnect(char const *apName, char const *apPassword, boolean showStaticIPFields) {
DEBUG_WM(F(""));
DEBUG_WM(F("AutoConnect"));
_sta_show_static_fields = showStaticIPFields;
// read eeprom for ssid and pass
//String ssid = getSSID();
//String pass = getPassword();
@@ -498,14 +500,14 @@ void WiFiManager::handleWifi(boolean scan) {
page += "<br/>";
}
if (_sta_static_ip) {
if (_sta_show_static_fields) {
String item = FPSTR(HTTP_FORM_PARAM);
item.replace("{i}", "ip");
item.replace("{n}", "ip");
item.replace("{p}", "Static IP");
item.replace("{l}", "15");
item.replace("{v}", _sta_static_ip.toString());
item.replace("{v}", (_sta_static_ip ? _sta_static_ip.toString() : ""));
page += item;
@@ -514,7 +516,7 @@ void WiFiManager::handleWifi(boolean scan) {
item.replace("{n}", "gw");
item.replace("{p}", "Static Gateway");
item.replace("{l}", "15");
item.replace("{v}", _sta_static_gw.toString());
item.replace("{v}", (_sta_static_gw ? _sta_static_gw.toString() : ""));
page += item;
@@ -523,7 +525,7 @@ void WiFiManager::handleWifi(boolean scan) {
item.replace("{n}", "sn");
item.replace("{p}", "Subnet");
item.replace("{l}", "15");
item.replace("{v}", _sta_static_sn.toString());
item.replace("{v}", (_sta_static_sn ? _sta_static_sn.toString() : ""));
page += item;