Added Custom DNS, fix newlines

This commit is contained in:
Deb
2018-03-15 15:29:34 -05:00
committed by Shawn A
parent 278c320e22
commit 81045e6433
3 changed files with 34 additions and 2 deletions
+29 -2
View File
@@ -586,8 +586,14 @@ uint8_t WiFiManager::connectWifi(String ssid, String pass) {
// Setup static IP config if provided
if (_sta_static_ip) {
WiFi.config(_sta_static_ip, _sta_static_gw, _sta_static_sn);
DEBUG_WM(DEBUG_VERBOSE,F("Custom STA IP/GW/Subnet:"),WiFi.localIP());
if(_sta_static_dns) {
DEBUG_WM(DEBUG_VERBOSE,F("Custom STA IP/GW/Subnet/DNS"));
WiFi.config(_sta_static_ip, _sta_static_gw, _sta_static_sn, _sta_static_dns);
} else {
DEBUG_WM(DEBUG_VERBOSE,F("Custom STA IP/GW/Subnet"));
WiFi.config(_sta_static_ip, _sta_static_gw, _sta_static_sn);
}
DEBUG_WM(WiFi.localIP());
}
// make sure sta is on before `begin` so it does not call enablesta->mode while persistent is ON ( which would save WM AP state to eeprom !)
@@ -952,6 +958,7 @@ String WiFiManager::getStaticOut(){
// WiFi.gatewayIP().toString();
page += getIpForm(FPSTR(S_sn),FPSTR(S_subnet),(_sta_static_sn ? _sta_static_sn.toString() : "")); // @token subnet
// WiFi.subnetMask().toString();
if(_sta_static_dns) page += getIpForm(FPSTR(S_dns),FPSTR(S_staticdns),(_sta_static_dns ? _sta_static_dns.toString() : "")); // @token DNS
page += FPSTR(HTTP_BR); // @todo remove these, use css
}
return page;
@@ -1061,6 +1068,11 @@ void WiFiManager::handleWifiSave() {
optionalIPFromString(&_sta_static_sn, sn.c_str());
DEBUG_WM(DEBUG_DEV,F("static netmask:"),sn);
}
if (server->arg(FPSTR(S_dns)) != "") {
String dns = server->arg(FPSTR(S_dns));
optionalIPFromString(&_sta_static_dns, dns.c_str());
DEBUG_WM(DEBUG_DEV,F("static DNS:"),dns);
}
String page = getHTTPHead(FPSTR(S_titlewifisaved)); // @token titlewifisaved
page += FPSTR(HTTP_SAVED);
@@ -1664,6 +1676,21 @@ void WiFiManager::setSTAStaticIPConfig(IPAddress ip, IPAddress gw, IPAddress sn)
_sta_static_sn = sn;
}
/**
* [setSTAStaticIPConfig description]
* @access public
* @param {[type]} IPAddress ip [description]
* @param {[type]} IPAddress gw [description]
* @param {[type]} IPAddress sn [description]
* @param {[type]} IPAddress dns [description]
*/
void WiFiManager::setSTAStaticIPConfig(IPAddress ip, IPAddress gw, IPAddress sn, IPAddress dns) {
_sta_static_ip = ip;
_sta_static_gw = gw;
_sta_static_sn = sn;
_sta_static_dns = dns;
}
/**
* [setMinimumSignalQuality description]
* @access public
+3
View File
@@ -174,6 +174,8 @@ class WiFiManager
void setAPStaticIPConfig(IPAddress ip, IPAddress gw, IPAddress sn);
//sets config for a static IP
void setSTAStaticIPConfig(IPAddress ip, IPAddress gw, IPAddress sn);
//sets config for a static IP with DNS
void setSTAStaticIPConfig(IPAddress ip, IPAddress gw, IPAddress sn, IPAddress dns);
//called when AP mode and config portal is started
void setAPCallback( void (*func)(WiFiManager*) );
//called when settings have been changed and connection was successful
@@ -246,6 +248,7 @@ class WiFiManager
IPAddress _sta_static_ip;
IPAddress _sta_static_gw;
IPAddress _sta_static_sn;
IPAddress _sta_static_dns;
// defaults
const byte DNS_PORT = 53;
+2
View File
@@ -186,6 +186,7 @@ const char S_options[] PROGMEM = "options";
const char S_nonetworks[] PROGMEM = "No networks found. Refresh to scan again.";
const char S_staticip[] PROGMEM = "Static IP";
const char S_staticgw[] PROGMEM = "Static Gateway";
const char S_staticdns[] PROGMEM = "Static DNS";
const char S_subnet[] PROGMEM = "Subnet";
const char S_exiting[] PROGMEM = "Exiting";
const char S_resetting[] PROGMEM = "Module will reset in a few seconds.";
@@ -223,6 +224,7 @@ const char R_status[] PROGMEM = "/status";
const char S_ip[] PROGMEM = "ip";
const char S_gw[] PROGMEM = "gw";
const char S_sn[] PROGMEM = "sn";
const char S_dns[] PROGMEM = "dns";
// softap ssid default prefix
#ifdef ESP8266