Skip to content

Commit f89ba44

Browse files
authored
Merge pull request #646 from ourairquality/wificfg-hostname
wificfg: default the hostname in all modes.
2 parents 88ff263 + 024fbd0 commit f89ba44

File tree

1 file changed

+20
-17
lines changed

1 file changed

+20
-17
lines changed

extras/wificfg/wificfg.c

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1884,8 +1884,11 @@ static void server_task(void *pvParameters)
18841884
value = skip_whitespace(value);
18851885
switch (header) {
18861886
case HTTP_HEADER_HOST:
1887-
if (hostname_local && host_is_name(value) &&
1888-
strcmp(value, hostname_local)) {
1887+
if (!host_is_name(value)) {
1888+
break;
1889+
}
1890+
if (!hostname_local ||
1891+
(hostname_local && strcmp(value, hostname_local))) {
18891892
host_redirect = true;
18901893
}
18911894
break;
@@ -2049,6 +2052,21 @@ void wificfg_init(uint32_t port, const wificfg_dispatch *dispatch)
20492052
return;
20502053
}
20512054

2055+
/* Default a hostname. */
2056+
char *hostname = NULL;
2057+
sysparam_get_string("hostname", &hostname);
2058+
if (!hostname && wificfg_default_hostname) {
2059+
uint8_t macaddr[6];
2060+
char name[32];
2061+
sdk_wifi_get_macaddr(1, macaddr);
2062+
snprintf(name, sizeof(name), wificfg_default_hostname, macaddr[3],
2063+
macaddr[4], macaddr[5]);
2064+
sysparam_set_string("hostname", name);
2065+
}
2066+
if (hostname) {
2067+
free(hostname);
2068+
}
2069+
20522070
sysparam_get_string("wifi_ap_ssid", &wifi_ap_ssid);
20532071
sysparam_get_string("wifi_ap_password", &wifi_ap_password);
20542072
sysparam_get_string("wifi_sta_ssid", &wifi_sta_ssid);
@@ -2120,21 +2138,6 @@ void wificfg_init(uint32_t port, const wificfg_dispatch *dispatch)
21202138
sdk_wifi_set_opmode(wifi_mode);
21212139

21222140
if (wifi_sta_enable) {
2123-
/* Default a hostname. */
2124-
char *hostname = NULL;
2125-
sysparam_get_string("hostname", &hostname);
2126-
if (!hostname && wificfg_default_hostname) {
2127-
uint8_t macaddr[6];
2128-
char name[32];
2129-
sdk_wifi_get_macaddr(1, macaddr);
2130-
snprintf(name, sizeof(name), wificfg_default_hostname, macaddr[3],
2131-
macaddr[4], macaddr[5]);
2132-
sysparam_set_string("hostname", name);
2133-
}
2134-
if (hostname) {
2135-
free(hostname);
2136-
}
2137-
21382141
struct sdk_station_config config;
21392142
strcpy((char *)config.ssid, wifi_sta_ssid);
21402143
strcpy((char *)config.password, wifi_sta_password);

0 commit comments

Comments
 (0)