Skip to content

Commit

Permalink
testing #527
Browse files Browse the repository at this point in the history
  • Loading branch information
tablatronix committed Feb 18, 2018
1 parent f3db838 commit cb7cbec
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 3 deletions.
39 changes: 36 additions & 3 deletions WiFiManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,14 @@ boolean WiFiManager::autoConnect(char const *apName, char const *apPassword) {
// so we must force it on else, if not connectimeout then waitforconnectionresult gets stuck endless loop
WiFi_autoReconnect();

if(_hostname != ""){
#ifdef ESP8266
WiFi.hostname(_hostname);
#elif defined(ESP32)
WiFi.setHostname(_hostname);
#endif
}

// if already connected, or try stored connect
if (WiFi.status() == WL_CONNECTED || connectWifi("", "") == WL_CONNECTED) {
//connected
Expand Down Expand Up @@ -208,7 +216,13 @@ bool WiFiManager::startAP(){
if ( _apcallback != NULL) {
_apcallback(this);
}


#ifdef ESP32
if(ret && _hostname != ""){
WiFi.softAPsetHostname(_hostname);
}
#endif

return ret;
}

Expand Down Expand Up @@ -279,6 +293,7 @@ void WiFiManager::setupConfigPortal() {
server->on((String)F("/i"), std::bind(&WiFiManager::handleInfo, this));
server->on((String)F("/r"), std::bind(&WiFiManager::handleReset, this));
server->on((String)F("/exit"), std::bind(&WiFiManager::handleExit, this));
// server->on((String)F("/exit"), std::bind(&WiFiManager::stopCaptivePortal, this));
server->on((String)F("/erase"), std::bind(&WiFiManager::handleErase, this));
server->on((String)F("/status"), std::bind(&WiFiManager::handleWiFiStatus, this));
//server->on("/fwlink", std::bind(&WiFiManager::handleRoot, this)); //Microsoft captive portal. Maybe not needed. Might be handled by notFound handler.
Expand Down Expand Up @@ -439,8 +454,8 @@ boolean WiFiManager::stopConfigPortal(){
DEBUG_WM(F("disconnect configportal"));
bool ret = WiFi.softAPdisconnect(false);
if(!ret)DEBUG_WM(F("disconnect configportal - softAPdisconnect failed"));
// WiFi_Mode(_usermode); // restore users wifi mode
DEBUG_WM("uswermode",_usermode);
// WiFi_Mode(_usermode); // restore users wifi mode, BUG https://github.com/esp8266/Arduino/issues/4372
// DEBUG_WM("usermode",_usermode);
configPortalActive = false;
return ret;
}
Expand Down Expand Up @@ -494,6 +509,15 @@ int WiFiManager::connectWifi(String ssid, String pass) {
}

_lastconxresult = connRes;

if(connRes == WL_CONNECTED && _hostname != ""){
#ifdef ESP8266
WiFi.hostname(_hostname);
#elif defined(ESP32)
WiFi.setHostname(_hostname);
#endif
}

return connRes;
}

Expand Down Expand Up @@ -1295,6 +1319,10 @@ boolean WiFiManager::captivePortal() {
return false;
}

void WiFiManager::stopCaptivePortal(){
_enableCaptivePortal= false;
}

void WiFiManager::reportStatus(String &page){
String str;
if (WiFi_SSID() != ""){
Expand Down Expand Up @@ -1442,6 +1470,11 @@ uint8_t WiFiManager::getLastConxResult(){
return _lastconxresult;
}

bool WiFiManager::setHostname(const char * hostname){
//@todo max length 32
_hostname = hostname;
}

// HELPERS

template <typename Generic>
Expand Down
4 changes: 4 additions & 0 deletions WiFiManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ class WiFiManager
uint8_t getLastConxResult();
// get a status as string
String getWLStatusString(uint8_t status);
bool setHostname(const char * hostname);

private:
std::unique_ptr<DNSServer> dnsServer;
Expand Down Expand Up @@ -211,6 +212,7 @@ class WiFiManager
String _wifissidprefix = FPSTR(S_ssidpre); // auto apname prefix prefix+chipid
uint8_t _lastconxresult = WL_IDLE_STATUS;


// option parameters
int _minimumQuality = -1; // filter wifiscan ap by this rssi
boolean _removeDuplicateAPs = true; // remove dup aps from wifiscan
Expand All @@ -224,6 +226,7 @@ class WiFiManager
boolean _cpClientCheck = false; // keep cp alive if cp have station
boolean _webClientCheck = true; // keep cp alive if web have client
boolean _scanDispOptions = false; // show percentage in scans not icons
const char * _hostname = "";

const char* _customHeadElement = ""; // store custom head element html from user

Expand Down Expand Up @@ -252,6 +255,7 @@ class WiFiManager
boolean configPortalHasTimeout();
boolean stopConfigPortal();
uint8_t handleConfigPortal();
void stopCaptivePortal();

// wifi platform abstractions
bool WiFi_Mode(WiFiMode_t m);
Expand Down

0 comments on commit cb7cbec

Please sign in to comment.