@@ -85,7 +85,10 @@ void NetWizard::autoConnect(const char* ssid, const char* password) {
8585 NETWIZARD_DEBUG_MSG (" Connecting to saved credentials\n " );
8686 NETWIZARD_DEBUG_MSG (" SSID: " + _nw.sta .ssid + " \n " );
8787 Serial.printf (" Connecting to %s, %s\n " , _nw.sta .ssid .c_str (), _nw.sta .password .c_str ());
88- // Credentials loaded successfully
88+ // Set hostname
89+ if (_nw.hostname != " " ) {
90+ WiFi.setHostname (_nw.hostname .c_str ());
91+ }
8992 WiFi.mode (WIFI_STA);
9093 WiFi.persistent (false );
9194 _connect (_nw.sta .ssid .c_str (), _nw.sta .password .c_str (), true );
@@ -111,6 +114,10 @@ void NetWizard::autoConnect(const char* ssid, const char* password) {
111114 || _nw.status == NetWizardConnectionStatus::CONNECTION_FAILED
112115 ) {
113116 NETWIZARD_DEBUG_MSG (" Trying to connect again...\n " );
117+ // Set hostname
118+ if (_nw.hostname != " " ) {
119+ WiFi.setHostname (_nw.hostname .c_str ());
120+ }
114121 WiFi.mode (WIFI_STA);
115122 WiFi.persistent (false );
116123 _connect (_nw.sta .ssid .c_str (), _nw.sta .password .c_str (), true );
@@ -417,8 +424,6 @@ void NetWizard::_connect(const char* ssid, const char* password, bool autoreconn
417424 WiFi.setAutoReconnect (true );
418425 }
419426 #endif
420- // Set hostname
421- WiFi.setHostname (_nw.hostname .c_str ());
422427 // Connect to WiFi
423428 WiFi.begin (ssid, password);
424429 _nw.status = NetWizardConnectionStatus::CONNECTING;
@@ -1092,6 +1097,10 @@ void NetWizard::_stopHTTP() {
10921097}
10931098
10941099void NetWizard::_startPortal () {
1100+ // Set hostname
1101+ if (_nw.hostname != " " ) {
1102+ WiFi.setHostname (_nw.hostname .c_str ());
1103+ }
10951104 WiFi.mode (WIFI_AP_STA);
10961105 WiFi.persistent (false );
10971106 if (this ->isConfigured ()) {
@@ -1156,6 +1165,10 @@ void NetWizard::_stopPortal() {
11561165 WiFi.softAPdisconnect (true );
11571166 if (this ->isConfigured ()) {
11581167 NETWIZARD_DEBUG_MSG (" Connecting to configured connection\n " );
1168+ // Set hostname
1169+ if (_nw.hostname != " " ) {
1170+ WiFi.setHostname (_nw.hostname .c_str ());
1171+ }
11591172 WiFi.mode (WIFI_STA);
11601173 WiFi.persistent (false );
11611174 _connect (_nw.sta .ssid .c_str (), _nw.sta .password .c_str (), true );
0 commit comments