Commit 4a1775c2 authored by dnc40085's avatar dnc40085 Committed by Marcel Stör
Browse files

Fixed bug where default hostname is not set on boot when in SoftAP mode (#1341)

parent 9cedfd47
...@@ -1311,6 +1311,8 @@ static const LUA_REG_TYPE wifi_map[] = { ...@@ -1311,6 +1311,8 @@ static const LUA_REG_TYPE wifi_map[] = {
void wifi_change_default_host_name(void) void wifi_change_default_host_name(void)
{ {
uint8 opmode_temp=wifi_get_opmode();
wifi_set_opmode_current(STATION_MODE);
#ifndef WIFI_STA_HOSTNAME #ifndef WIFI_STA_HOSTNAME
char temp[32]; char temp[32];
uint8_t mac[6]; uint8_t mac[6];
...@@ -1318,7 +1320,7 @@ void wifi_change_default_host_name(void) ...@@ -1318,7 +1320,7 @@ void wifi_change_default_host_name(void)
c_sprintf(temp, "NODE-%X%X%X", (mac)[3], (mac)[4], (mac)[5]); c_sprintf(temp, "NODE-%X%X%X", (mac)[3], (mac)[4], (mac)[5]);
wifi_sta_sethostname((const char*)temp, strlen(temp)); wifi_sta_sethostname((const char*)temp, strlen(temp));
#elif defined(WIFI_STA_HOSTNAME) && !defined(WIFI_STA_HOSTNAME_APPEND_MAC) #elif defined(WIFI_STA_HOSTNAME) && !defined(WIFI_STA_HOSTNAME_APPEND_MAC)
if(!wifi_sta_sethostname(WIFI_STA_HOSTNAME, strlen(WIFI_STA_HOSTNAME))) if(!wifi_sta_sethostname(WIFI_STA_HOSTNAME, strlen(WIFI_STA_HOSTNAME)))
{ {
char temp[32]; char temp[32];
...@@ -1339,7 +1341,10 @@ void wifi_change_default_host_name(void) ...@@ -1339,7 +1341,10 @@ void wifi_change_default_host_name(void)
wifi_sta_sethostname((const char*)temp, strlen(temp)); wifi_sta_sethostname((const char*)temp, strlen(temp));
} }
#endif #endif
if(opmode_temp!=wifi_get_opmode())
{
wifi_set_opmode_current(opmode_temp);
}
} }
int luaopen_wifi( lua_State *L ) int luaopen_wifi( lua_State *L )
......
...@@ -122,7 +122,7 @@ void nodemcu_init(void) ...@@ -122,7 +122,7 @@ void nodemcu_init(void)
void user_rf_pre_init(void) void user_rf_pre_init(void)
{ {
//set WiFi hostname before RF initialization (adds ~440 us to boot time) //set WiFi hostname before RF initialization (adds ~479 us to boot time)
wifi_change_default_host_name(); wifi_change_default_host_name();
} }
#endif #endif
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment