Skip to content

Commit

Permalink
add result checking #527
Browse files Browse the repository at this point in the history
  • Loading branch information
tablatronix committed Feb 19, 2018
1 parent 7a5a72e commit aaad9ca
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
23 changes: 18 additions & 5 deletions WiFiManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,14 +181,17 @@ boolean WiFiManager::autoConnect(char const *apName, char const *apPassword) {

// set hostname before stating
if(_hostname != ""){
bool res = true;
#ifdef ESP8266
WiFi.hostname(_hostname);
res = WiFi.hostname(_hostname);
#elif defined(ESP32)
// @note hostname must be set after STA_START
delay(200); // do not remove, give time for STA_START
WiFi.setHostname(_hostname);
res = WiFi.setHostname(_hostname);
#endif

if(!res)DEBUG_WM(F("hostname: set failed!"));

if(WiFi.status() == WL_CONNECTED){
DEBUG_WM(F("reconnecting to set new hostname"));
// WiFi.reconnect(); // This does not reset dhcp
Expand All @@ -203,8 +206,17 @@ boolean WiFiManager::autoConnect(char const *apName, char const *apPassword) {
//connected
DEBUG_WM(F("IP Address:"),WiFi.localIP());
_lastconxresult = WL_CONNECTED;

if(_hostname != ""){
#ifdef ESP8266
DEBUG_WM("hostname: STA",WiFi.hostname());
#elif defined(ESP32)
DEBUG_WM("hostname: STA",WiFi.getHostname());
#endif
}
return true;
}

// not connected start configportal
return startConfigPortal(apName, apPassword);
}
Expand Down Expand Up @@ -238,16 +250,17 @@ bool WiFiManager::startAP(){
// set ap hostname
#ifdef ESP32
if(ret && _hostname != ""){
WiFi.softAPsetHostname(_hostname);
DEBUG_WM(F("aphostname: "),WiFi.softAPgetHostname());
bool res = WiFi.softAPsetHostname(_hostname);
if(!res)DEBUG_WM(F("hostname: AP set failed!"));
DEBUG_WM(F("hostname: AP"),WiFi.softAPgetHostname());
}
#endif

// do AP callback if set
if ( _apcallback != NULL) {
_apcallback(this);
}

return ret;
}

Expand Down
2 changes: 1 addition & 1 deletion WiFiManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,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 * _hostname = "wmtest";

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

Expand Down

0 comments on commit aaad9ca

Please sign in to comment.