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

This commit is contained in:
dnc40085 2016-06-05 04:38:12 -07:00 committed by Marcel Stör
parent 9cedfd4767
commit 4a1775c2e8
2 changed files with 9 additions and 4 deletions

View File

@ -1311,6 +1311,8 @@ static const LUA_REG_TYPE wifi_map[] = {
void wifi_change_default_host_name(void)
{
uint8 opmode_temp=wifi_get_opmode();
wifi_set_opmode_current(STATION_MODE);
#ifndef WIFI_STA_HOSTNAME
char temp[32];
uint8_t mac[6];
@ -1318,7 +1320,7 @@ void wifi_change_default_host_name(void)
c_sprintf(temp, "NODE-%X%X%X", (mac)[3], (mac)[4], (mac)[5]);
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)))
{
char temp[32];
@ -1335,11 +1337,14 @@ void wifi_change_default_host_name(void)
c_sprintf(temp, "%s%X%X%X", WIFI_STA_HOSTNAME, (mac)[3], (mac)[4], (mac)[5]);
if(!wifi_sta_sethostname(temp, strlen(temp)))
{
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));
}
#endif
if(opmode_temp!=wifi_get_opmode())
{
wifi_set_opmode_current(opmode_temp);
}
}
int luaopen_wifi( lua_State *L )

View File

@ -122,7 +122,7 @@ void nodemcu_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();
}
#endif