Merge pull request #1 from lutzky/master

Add customizable DHCP hostname
This commit is contained in:
Nordstrand 2021-08-28 16:07:23 +02:00 committed by GitHub
commit 9c5804dc9f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 0 deletions

View File

@ -22,6 +22,8 @@
#define WIFI_SSID ""
// Wi-Fi password (required)
#define WIFI_PASSWORD ""
// Wi-Fi hostname (for DHCP, uncomment if non-default desired)
// #define WIFI_HOSTNAME "my_host_name"
// Wi-Fi static IPv4 address enabled or disabled (disable for DHCPv4)
#define WIFI_IPV4_STATIC false
// Wi-Fi static IPv4 address

View File

@ -44,6 +44,7 @@ void setup_dht_sensor() {
}
void setup_wifi() {
WiFi.mode(WIFI_STA);
char message[128];
snprintf(message, 128, "Wi-Fi SSID: %s", WIFI_SSID);
log(message);
@ -70,6 +71,18 @@ void setup_wifi() {
}
log("Wi-Fi connecting ...");
#ifdef WIFI_HOSTNAME
snprintf(message, 128, "Initial hostname: %s", WiFi.hostname().c_str());
log(message);
log("Requesting hostname " WIFI_HOSTNAME);
if (!WiFi.hostname(WIFI_HOSTNAME)) {
log("Hostname request failed");
} else {
log("Hostname request succeeded");
}
snprintf(message, 128, "New hostname: %s", WiFi.hostname().c_str());
log(message);
#endif
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
while (WiFi.status() != WL_CONNECTED) {
log("Wi-Fi waiting ...", LogLevel::DEBUG);